I'm getting an IndexError: list index out of range from AsyncLangchainCallbackHandler when the agent calls a tool; I'm using chainlit 0.6.3.
import chainlit as cl
from langchain.agents import Tool, AgentExecutor, OpenAIFunctionsAgent
from langchain.schema import SystemMessage
from langchain.chat_models import ChatOpenAI
from pydantic.v1 import BaseModel, Field
class GetWordLength(BaseModel):
word: str = Field(description="word to calculate length for")
async def get_word_length(word: str) -> int:
"""Returns the length of a word."""
print('calculating length')
return len(word)
@cl.on_chat_start
def main():
tools = [Tool.from_function(
func=get_word_length,
name="GetWordLength",
description="calculates the length of a word",
args_schema=GetWordLength,
coroutine=get_word_length
)]
llm = ChatOpenAI(temperature=0)
prompt = OpenAIFunctionsAgent.create_prompt(
system_message=SystemMessage(content="be useful")
)
agent = OpenAIFunctionsAgent(llm=llm, tools=tools, prompt=prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
cl.user_session.set("executor", executor)
@cl.on_message
async def main(message: str):
llm_chain = cl.user_session.get("executor")
res = await llm_chain.arun(message, callbacks=[cl.AsyncLangchainCallbackHandler()])
await cl.Message(content=res).send()
Question: how long is foobar
> Entering new AgentExecutor chain...
2023-08-26 08:09:58 - message='OpenAI API response' path=https://api.openai.com/v1/chat/completions processing_ms=550 request_id=6a13b82df2d603709a3bf3c087f27a6f response_code=200
Invoking: `GetWordLength` with `{'word': 'foobar'}`
calculating length
62023-08-26 08:09:58 - Error in AsyncLangchainCallbackHandler.on_chat_model_start callback: list index out of range
2023-08-26 08:09:58 - list index out of range
Traceback (most recent call last):
File "/Users/p8a/data/research/botpoc/venv/lib/python3.11/site-packages/chainlit/utils.py", line 36, in wrapper
return await user_function(**params_values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/p8a/data/research/botpoc/litpoc.py", line 44, in main
res = await llm_chain.arun(message, callbacks=[cl.AsyncLangchainCallbackHandler()])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/p8a/data/research/botpoc/venv/lib/python3.11/site-packages/langchain/chains/base.py", line 549, in arun
await self.acall(
File "/Users/p8a/data/research/botpoc/venv/lib/python3.11/site-packages/langchain/chains/base.py", line 349, in acall
raise e
File "/Users/p8a/data/research/botpoc/venv/lib/python3.11/site-packages/langchain/chains/base.py", line 343, in acall
await self._acall(inputs, run_manager=run_manager)
File "/Users/p8a/data/research/botpoc/venv/lib/python3.11/site-packages/langchain/agents/agent.py", line 1085, in _acall
next_step_output = await self._atake_next_step(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/p8a/data/research/botpoc/venv/lib/python3.11/site-packages/langchain/agents/agent.py", line 929, in _atake_next_step
output = await self.agent.aplan(
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/p8a/data/research/botpoc/venv/lib/python3.11/site-packages/langchain/agents/openai_functions_agent/base.py", line 247, in aplan
predicted_message = await self.llm.apredict_messages(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/p8a/data/research/botpoc/venv/lib/python3.11/site-packages/langchain/chat_models/base.py", line 626, in apredict_messages
return await self._call_async(messages, stop=_stop, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/p8a/data/research/botpoc/venv/lib/python3.11/site-packages/langchain/chat_models/base.py", line 566, in _call_async
result = await self.agenerate(
^^^^^^^^^^^^^^^^^^^^^
File "/Users/p8a/data/research/botpoc/venv/lib/python3.11/site-packages/langchain/chat_models/base.py", line 349, in agenerate
run_managers = await callback_manager.on_chat_model_start(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/p8a/data/research/botpoc/venv/lib/python3.11/site-packages/langchain/callbacks/manager.py", line 1432, in on_chat_model_start
await asyncio.gather(*tasks)
File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/tasks.py", line 339, in __wakeup
future.result()
File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/tasks.py", line 269, in __step
result = coro.throw(exc)
^^^^^^^^^^^^^^^
File "/Users/p8a/data/research/botpoc/venv/lib/python3.11/site-packages/langchain/callbacks/manager.py", line 387, in _ahandle_event
await asyncio.gather(
File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/tasks.py", line 339, in __wakeup
future.result()
File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/tasks.py", line 267, in __step
result = coro.send(None)
^^^^^^^^^^^^^^^
File "/Users/p8a/data/research/botpoc/venv/lib/python3.11/site-packages/langchain/callbacks/manager.py", line 372, in _ahandle_event_for_handler
raise e
File "/Users/p8a/data/research/botpoc/venv/lib/python3.11/site-packages/langchain/callbacks/manager.py", line 342, in _ahandle_event_for_handler
await event(*args, **kwargs)
File "/Users/p8a/data/research/botpoc/venv/lib/python3.11/site-packages/chainlit/langchain/callbacks.py", line 468, in on_chat_model_start
_on_chat_model_start(self, serialized, messages, **kwargs)
File "/Users/p8a/data/research/botpoc/venv/lib/python3.11/site-packages/chainlit/langchain/callbacks.py", line 254, in _on_chat_model_start
self.current_prompt.messages[idx].formatted = m.content
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
IndexError: list index out of range
I'm getting an
IndexError: list index out of range
fromAsyncLangchainCallbackHandler
when the agent calls a tool; I'm using chainlit 0.6.3.Question:
how long is foobar