diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 21347f4c..e927b39e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,4 @@ +repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. rev: v0.4.4 diff --git a/examples/frontend/app.py b/examples/frontend/app.py index a94ae4c5..3b3f4929 100644 --- a/examples/frontend/app.py +++ b/examples/frontend/app.py @@ -2,9 +2,9 @@ import sys import streamlit as st +from utils import get_images from codeinterpreterapi import File -from codeinterpreterapi.config import settings # Page configuration st.set_page_config(layout="wide") diff --git a/server.py b/server.py index 27b0ed31..0ea1ab0e 100644 --- a/server.py +++ b/server.py @@ -2,15 +2,8 @@ ConnectorImplCodeinterpreterApi, ) from gui_agent_loop_core.gui_agent_loop_core import GuiAgentLoopCore -from gui_agent_loop_core.schema.schema import ( - GuiAgentInterpreterChatMessage, - GuiAgentInterpreterChatMessages, - GuiAgentInterpreterChatResponse, - GuiAgentInterpreterChatResponseAny, -) -from langchain_core.messages import SystemMessage -from codeinterpreterapi import CodeInterpreterSession, settings +from codeinterpreterapi import CodeInterpreterSession class CodeInterpreter(ConnectorImplCodeinterpreterApi): diff --git a/src/codeinterpreterapi/agents/plan_and_execute/agent_executor.py b/src/codeinterpreterapi/agents/plan_and_execute/agent_executor.py index 6439d4cf..efde9478 100644 --- a/src/codeinterpreterapi/agents/plan_and_execute/agent_executor.py +++ b/src/codeinterpreterapi/agents/plan_and_execute/agent_executor.py @@ -1,7 +1,7 @@ from typing import List, Optional from langchain.agents.agent import AgentExecutor, AgentOutputParser -from langchain.agents.structured_chat.base import StructuredChatAgent, create_structured_chat_agent +from langchain.agents.structured_chat.base import create_structured_chat_agent from langchain.tools import BaseTool from langchain_core.callbacks import BaseCallbackManager from langchain_core.language_models import BaseLanguageModel diff --git a/src/codeinterpreterapi/agents/plan_and_execute/prompts.py b/src/codeinterpreterapi/agents/plan_and_execute/prompts.py index e624d4ff..ff5a33c7 100644 --- a/src/codeinterpreterapi/agents/plan_and_execute/prompts.py +++ b/src/codeinterpreterapi/agents/plan_and_execute/prompts.py @@ -1,7 +1,4 @@ -from textwrap import dedent - -from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder, PromptTemplate -from langchain_experimental.tot.prompts import JSONListOutputParser +from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder SYSTEM_MESSAGE_TEMPLATE = '''Respond to the human as helpfully and accurately as possible. You have access to the following tools: diff --git a/src/codeinterpreterapi/planners/planners.py b/src/codeinterpreterapi/planners/planners.py index 6b34e7da..666c9bc8 100644 --- a/src/codeinterpreterapi/planners/planners.py +++ b/src/codeinterpreterapi/planners/planners.py @@ -1,9 +1,7 @@ from langchain import hub -from langchain.agents import AgentExecutor, create_react_agent +from langchain.agents import create_react_agent from langchain.base_language import BaseLanguageModel -from langchain_core.runnables import Runnable, RunnablePassthrough -from langchain_experimental.plan_and_execute import load_chat_planner -from langchain_experimental.plan_and_execute.planners.base import LLMPlanner +from langchain_core.runnables import Runnable SYSTEM_PROMPT_PLANNER = """ Let's first understand the problem and devise a plan to solve the problem. diff --git a/src/codeinterpreterapi/supervisors/supervisors.py b/src/codeinterpreterapi/supervisors/supervisors.py index 9b76fe93..fa54f492 100644 --- a/src/codeinterpreterapi/supervisors/supervisors.py +++ b/src/codeinterpreterapi/supervisors/supervisors.py @@ -1,7 +1,10 @@ -from langchain import hub +import getpass +import os +import platform + from langchain.agents import AgentExecutor from langchain.chains.base import Chain -from langchain_core.runnables import RunnablePassthrough +from langchain_core.runnables import RunnableAssign, RunnablePassthrough from langchain_experimental.plan_and_execute.agent_executor import PlanAndExecute from langchain_experimental.plan_and_execute.planners.base import LLMPlanner @@ -13,11 +16,21 @@ class MySupervisorChain(Chain): class CodeInterpreterSupervisor: @staticmethod def choose_supervisor(planner: LLMPlanner, executor: AgentExecutor, verbose: bool = False) -> MySupervisorChain: + # prompt + username = getpass.getuser() + current_working_directory = os.getcwd() + operating_system = platform.system() + info = f"[User Info]\nName: {username}\nCWD: {current_working_directory}\nOS: {operating_system}" + print("choose_supervisor info=", info) + supervisor = PlanAndExecute(planner=planner, executor=executor, verbose=verbose) - prompt = hub.pull("nobu/chat_planner") - agent = create_react_agent(llm, [], prompt) - return agent + # prompt = hub.pull("nobu/chat_planner") + # agent = create_react_agent(llm, [], prompt) + # return agent # prompt = hub.pull("nobu/code_writer:0c56967d") supervisor_chain = RunnablePassthrough() | supervisor return supervisor_chain + + supervisor_chain = RunnableAssign() | supervisor + return supervisor_chain diff --git a/src/codeinterpreterapi/thoughts/thoughts.py b/src/codeinterpreterapi/thoughts/thoughts.py index 9f4622d7..40e1dd8d 100644 --- a/src/codeinterpreterapi/thoughts/thoughts.py +++ b/src/codeinterpreterapi/thoughts/thoughts.py @@ -1,13 +1,9 @@ from gui_agent_loop_core.thoughts.prompts import get_propose_prompt, get_propose_prompt_ja -from langchain.agents import AgentExecutor -from langchain.chains.base import Chain from langchain.prompts.base import BasePromptTemplate -from langchain_experimental.plan_and_execute.agent_executor import PlanAndExecute -from langchain_experimental.plan_and_execute.planners.base import LLMPlanner from langchain_experimental.pydantic_v1 import Field # from langchain_experimental.tot.prompts import get_cot_prompt, get_propose_prompt -from langchain_experimental.tot.thought_generation import BaseThoughtGenerationStrategy, ProposePromptStrategy +from langchain_experimental.tot.thought_generation import ProposePromptStrategy class MyProposePromptStrategy(ProposePromptStrategy): diff --git a/src/codeinterpreterapi/tools/tools.py b/src/codeinterpreterapi/tools/tools.py index c23449bc..bf29bc1f 100644 --- a/src/codeinterpreterapi/tools/tools.py +++ b/src/codeinterpreterapi/tools/tools.py @@ -1,8 +1,7 @@ from langchain_community.tools.shell.tool import BaseTool, ShellTool from langchain_community.tools.tavily_search import TavilySearchResults -from langchain_core.language_models import LLM, BaseLanguageModel, BaseLLM +from langchain_core.language_models import BaseLanguageModel from langchain_core.tools import StructuredTool, Tool -from langchain_experimental.chat_models.llm_wrapper import ChatWrapper from langchain_experimental.llm_bash.base import LLMBashChain from codeinterpreterapi.config import settings @@ -65,7 +64,6 @@ def get_shell_v2(additional_tools: list[BaseTool], llm: BaseLanguageModel) -> li commands field required (type=value_error.missing) """ - llm_runnable = ChatWrapper(llm=llm) bash_chain = LLMBashChain.from_llm(llm=llm) bash_tool = Tool( name="Bash", func=bash_chain.invoke, description="Executes bash commands in a terminal environment."