Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply formatter #155

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/frontend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import sys

import streamlit as st
from codeinterpreterapi import File
from utils import get_images # type: ignore

from codeinterpreterapi import File

# Page configuration
st.set_page_config(layout="wide")

Expand Down
1 change: 1 addition & 0 deletions examples/frontend/chainlitui.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import chainlit as cl # type: ignore

from codeinterpreterapi import CodeInterpreterSession
from codeinterpreterapi import File as CIFile

Expand Down
1 change: 1 addition & 0 deletions examples/frontend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Optional

import streamlit as st

from codeinterpreterapi import CodeInterpreterSession


Expand Down
4 changes: 3 additions & 1 deletion examples/use_additional_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
so it can download the bitcoin chart from yahoo finance
and plot it for you
"""

import csv
import io
from typing import Any

from codeinterpreterapi import CodeInterpreterSession
from langchain_core.tools import BaseTool

from codeinterpreterapi import CodeInterpreterSession


class ExampleKnowledgeBaseTool(BaseTool):
name: str = "salary_database"
Expand Down
3 changes: 1 addition & 2 deletions src/codeinterpreterapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from . import _patch_parser # noqa

from codeinterpreterapi.config import settings
from codeinterpreterapi.schema import File
from codeinterpreterapi.session import CodeInterpreterSession

from . import _patch_parser # noqa

__all__ = [
"CodeInterpreterSession",
Expand Down
46 changes: 26 additions & 20 deletions src/codeinterpreterapi/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,34 +177,40 @@ def _choose_agent(self) -> BaseSingleActionAgent:
],
)
if isinstance(self.llm, ChatOpenAI) or isinstance(self.llm, AzureChatOpenAI)
else ConversationalChatAgent.from_llm_and_tools(
llm=self.llm,
tools=self.tools,
system_message=settings.SYSTEM_MESSAGE.content.__str__(),
)
if isinstance(self.llm, BaseChatModel)
else ConversationalAgent.from_llm_and_tools(
llm=self.llm,
tools=self.tools,
prefix=settings.SYSTEM_MESSAGE.content.__str__(),
else (
ConversationalChatAgent.from_llm_and_tools(
llm=self.llm,
tools=self.tools,
system_message=settings.SYSTEM_MESSAGE.content.__str__(),
)
if isinstance(self.llm, BaseChatModel)
else ConversationalAgent.from_llm_and_tools(
llm=self.llm,
tools=self.tools,
prefix=settings.SYSTEM_MESSAGE.content.__str__(),
)
)
)

def _history_backend(self) -> BaseChatMessageHistory:
return (
CodeBoxChatMessageHistory(codebox=self.codebox)
if settings.HISTORY_BACKEND == "codebox"
else RedisChatMessageHistory(
session_id=str(self.session_id),
url=settings.REDIS_URL,
)
if settings.HISTORY_BACKEND == "redis"
else PostgresChatMessageHistory(
session_id=str(self.session_id),
connection_string=settings.POSTGRES_URL,
else (
RedisChatMessageHistory(
session_id=str(self.session_id),
url=settings.REDIS_URL,
)
if settings.HISTORY_BACKEND == "redis"
else (
PostgresChatMessageHistory(
session_id=str(self.session_id),
connection_string=settings.POSTGRES_URL,
)
if settings.HISTORY_BACKEND == "postgres"
else ChatMessageHistory()
)
)
if settings.HISTORY_BACKEND == "postgres"
else ChatMessageHistory()
)

def _agent_executor(self) -> AgentExecutor:
Expand Down
3 changes: 2 additions & 1 deletion tests/chain_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from asyncio import run as _await

from langchain_openai import ChatOpenAI

from codeinterpreterapi.chains import (
aget_file_modifications,
aremove_download_link,
get_file_modifications,
remove_download_link,
)
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-3.5-turbo")

Expand Down