Replies: 2 comments
-
Thanks for the suggestion! Session clearing does not belong in
I would recommend one of the following two options, depending on the goal:
Could you say a bit more about this issue? This feels like an unrelated issue, but something we'd want to fix. |
Beta Was this translation helpful? Give feedback.
-
Regarding item 1: of course, the server controls the session, and what I'm trying to do is: My agent: _llm = ChatOpenAI(temperature=0,
model='gpt-4-1106-preview',
streaming=True,
verbose=verbose,
callback_manager=BaseCallbackManager(
handlers=[Fb()]),
# callbacks=[Fb()]
)
print(u'\rLLM launched.')
prompt = hub.pull("hwchase17/openai-functions-agent")
tools.append(PythonREPLTool())
_agent = create_openai_functions_agent(_llm, tools, prompt)
_agent_executor = AgentExecutor(agent=_agent,
tools=tools,
verbose=verbose,
callbacks=[Fb()]
)
# return _agent_executor
_message_history = ChatMessageHistory()
agent = RunnableWithMessageHistory(
_agent_executor,
lambda session_id: _message_history,
input_messages_key="input",
history_messages_key="chat_history",
) Then, when the server sees the user leave: def on_user_left_chat(session_id):
"""Called when user exits the chatroom"""
db.save_thread(agent.get_session_history(session_id=session_id)) # works
agent.forget_conversation(session_id) # <--- the missing method This way I can have several users having concurrent conversations and an easy way to manage the session histories. Regarding item 2, If you run the agent code above, with the class Fb(BaseCallbackHandler):
_instance = None
def __new__(cls, *args, **kwargs):
if not isinstance(cls._instance, cls):
print('Creating new Firebase interface object')
cls._instance = super(Fb, cls).__new__(cls)
# Put any initialization here.
return cls._instance
def on_llm_end(self, response: LLMResult, **kwargs: Any) -> Any:
"""Run when LLM ends running."""
print(response.llm_output)
print(response.run)
print(response.generations) The Even if I do this: with get_openai_callback() as cb:
result = agent.invoke(
{ "input": query },
config={"configurable": {"session_id": session_id}},
)["output"]
print(cb) I get nothing in I would appreciate an advice on the latter, as I've tried several variants and the only thing that returns token count is if you call Thanks! |
Beta Was this translation helpful? Give feedback.
-
Checked
Feature request
Thanks for adding the
RunnableWithMessageHistory
class. It really helps to keep the ducks in a row. However, it appears that there's no way to delete the history by session ID, e.g. after user has exited the chat. So it just grows and grows until the agent is restarted. Also, would be nice to fix the token tracking for the agents. It seems to only work on simple LLMrun
calls.Motivation
This, hopefully, solves two problems:
Thanks!
Proposal (If applicable)
No response
Beta Was this translation helpful? Give feedback.
All reactions