Open berrazuriz1 opened 1 month ago
It seems that the await on the _aparse_intermidiate_steps is causing the error
def _wait_for_run(self, run_id: str, thread_id: str) -> Any:
in_progress = True
while in_progress:
run = self.client.beta.threads.runs.retrieve(run_id, thread_id=thread_id)
in_progress = run.status in ("in_progress", "queued")
if in_progress:
sleep(self.check_every_ms / 1000)
return run
async def _aparse_intermediate_steps(
self, intermediate_steps: List[Tuple[OpenAIAssistantAction, str]]
) -> dict:
last_action, last_output = intermediate_steps[-1]
run = await self._wait_for_run(last_action.run_id, last_action.thread_id)
required_tool_call_ids = set()
if run.required_action:
required_tool_call_ids = {
tc.id for tc in run.required_action.submit_tool_outputs.tool_calls
}
tool_outputs = [
{"output": str(output), "tool_call_id": action.tool_call_id}
for action, output in intermediate_steps
if action.tool_call_id in required_tool_call_ids
]
submit_tool_outputs = {
"tool_outputs": tool_outputs,
"run_id": last_action.run_id,
"thread_id": last_action.thread_id,
}
return submit_tool_outputs
I erase the await and runs well now
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 244, in run_asgi result = await self.app(self.scope, self.asgi_receive, self.asgi_send) # type: ignore[func-returns-value] File "/usr/local/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in call return await self.app(scope, receive, send) File "/usr/local/lib/python3.10/site-packages/channels/routing.py", line 62, in call return await application(scope, receive, send) File "/app/blar/authentication/websocket/WebSocketAuthMiddleware.py", line 50, in call return await self.app(scope, receive, send) File "/usr/local/lib/python3.10/site-packages/channels/routing.py", line 132, in call return await application( File "/usr/local/lib/python3.10/site-packages/channels/consumer.py", line 94, in app return await consumer(scope, receive, send) File "/usr/local/lib/python3.10/site-packages/channels/consumer.py", line 58, in call await await_many_dispatch( File "/usr/local/lib/python3.10/site-packages/channels/utils.py", line 50, in await_many_dispatch await dispatch(result) File "/usr/local/lib/python3.10/site-packages/channels/consumer.py", line 73, in dispatch await handler(message) File "/usr/local/lib/python3.10/site-packages/channels/generic/websocket.py", line 203, in websocket_receive await self.receive(text_data=message["text"]) File "/app/blar/agents/consumers.py", line 103, in receive await self.blar_agent_message(text_data_json) File "/app/blar/agents/consumers.py", line 219, in blar_agent_message raise e File "/usr/local/lib/python3.10/site-packages/asgiref/sync.py", line 518, in thread_handler raise exc_info[1] File "/app/blar/agents/consumers.py", line 173, in blar_agent_message async for event in custom_agent.stream_agent_response( File "/app/blar/agents/custom_agents/agent.py", line 232, in stream_agent_response async for chunk in self.agent_executor.astream({"content": input}): File "/usr/local/lib/python3.10/site-packages/langchain/agents/agent.py", line 1810, in astream async for step in iterator: File "/usr/local/lib/python3.10/site-packages/langchain/agents/agent_iterator.py", line 266, in aiter async for chunk in self.agent_executor._aiter_next_step( File "/usr/local/lib/python3.10/site-packages/langchain/agents/agent.py", line 1500, in _aiter_next_step output = await self._action_agent.aplan( File "/usr/local/lib/python3.10/site-packages/langchain/agents/agent.py", line 503, in aplan async for chunk in self.runnable.astream( File "/usr/local/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 1018, in astream yield await self.ainvoke(input, config, **kwargs) File "/usr/local/lib/python3.10/site-packages/langchain/agents/openai_assistant/base.py", line 474, in ainvoke raise e File "/usr/local/lib/python3.10/site-packages/langchain/agents/openai_assistant/base.py", line 437, in ainvoke tool_outputs = await self._aparse_intermediate_steps( File "/usr/local/lib/python3.10/site-packages/langchain/agents/openai_assistant/base.py", line 618, in _aparse_intermediate_steps run = await self._wait_for_run(last_action.run_id, last_action.thread_id) TypeError: object Run can't be used in 'await' expression
Description
It runs function calling well, but when it gets to a AI message chunk it throws this
System Info