Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assistant's LLM tools list contains duplicates causing tools list limit OpenAI error #254

Closed
nate-mar opened this issue May 16, 2024 · 9 comments
Assignees

Comments

@nate-mar
Copy link

nate-mar commented May 16, 2024

Assistant tools are updated after every run. When they are updated, tools are appended to the llm's list of tools, but it doesn't appear that the tools are deduplicated before they are appended to the list. The result is that if there are enough runs performed, then the list of tools will exceed the allowed number of tools in an LLM request. Specifically for OpenAI GPT-4 that limit is 128.

When I ran the LLM OS and had a chat with around 8 interactions, I received this OpenAI error:

openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid 'tools': array too long. Expected an array with maximum length 128, but got an array with length 135 instead.", 'type': 'invalid_request_error', 'param': 'tools', 'code': 'array_above_max_length'}}

I manually logged the tools argument and could see in the console that the list simply grows longer after every exchange, and that the list contains duplicate tools. To reproduce, you can load up the LLM OS cookbook, and have a conversation with the LLM with roughly 8 exchanges.

Happy to take a pass at addressing this (once someone confirms)! Looks like it will have to involve doing a full list check, unless the tools attribute is replaced with a Dict perhaps (the llm functions attribute look like a Dict though).

@nexxeln
Copy link

nexxeln commented May 16, 2024

i also faced this issue

@nexxeln
Copy link

nexxeln commented May 16, 2024

i think a simple deduplication of the list should work.

self.llm.tools = list({tool.name: tool for tool in self.llm.tools}.values())

but using a dict might be better

@chivalry1314
Copy link

i also faced this issue

@jacobweiss2305 jacobweiss2305 self-assigned this May 16, 2024
@jacobweiss2305
Copy link
Contributor

@ysolanky and I are working on a fix.

@nate-mar
Copy link
Author

@jacobweiss2305 awesome -- happy to help out in any way

@anhuibl
Copy link

anhuibl commented May 19, 2024

i also faced this issue, please fix it. Thanks so much!

@sigren
Copy link

sigren commented May 20, 2024

please!

@ysolanky
Copy link
Contributor

PR is already out for this issue. It will be fixed in the next release 🙂

@nate-mar
Copy link
Author

Fixed via #973

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants