diff --git a/core/cat/looking_glass/agent_manager.py b/core/cat/looking_glass/agent_manager.py index dc61395d..2d2acc33 100644 --- a/core/cat/looking_glass/agent_manager.py +++ b/core/cat/looking_glass/agent_manager.py @@ -6,24 +6,15 @@ from langchain.docstore.document import Document from langchain.prompts import PromptTemplate from langchain.chains import LLMChain -from langchain.callbacks.base import BaseCallbackHandler from langchain.agents import AgentExecutor, LLMSingleActionAgent from cat.looking_glass import prompts +from cat.looking_glass.callbacks import NewTokenHandler from cat.looking_glass.output_parser import ToolOutputParser from cat.utils import verbal_timedelta from cat.log import log -class NewTokenHandler(BaseCallbackHandler): - - def __init__(self, cat): - self.cat = cat - def on_llm_new_token(self, token: str, **kwargs) -> None: - self.cat.send_ws_message(token, "chat_token") - - - class AgentManager: """Manager of Langchain Agent. @@ -54,7 +45,11 @@ def execute_tool_agent(self, agent_input, allowed_tools): ) # main chain - agent_chain = LLMChain(prompt=prompt, llm=self.cat._llm, verbose=True) + agent_chain = LLMChain( + prompt=prompt, + llm=self.cat._llm, + verbose=True + ) # init agent agent = LLMSingleActionAgent( diff --git a/core/cat/looking_glass/callbacks.py b/core/cat/looking_glass/callbacks.py new file mode 100644 index 00000000..b224c9e5 --- /dev/null +++ b/core/cat/looking_glass/callbacks.py @@ -0,0 +1,11 @@ + +from langchain.callbacks.base import BaseCallbackHandler + + +class NewTokenHandler(BaseCallbackHandler): + + def __init__(self, cat): + self.cat = cat + + def on_llm_new_token(self, token: str, **kwargs) -> None: + self.cat.send_ws_message(token, "chat_token")