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

Add notebook with workaround for lengthy tool descriptions #13701

Merged
merged 3 commits into from
May 24, 2024

Conversation

joelrorseth
Copy link
Collaborator

Description

OpenAI tools have a limit on the length of the description provided, which is currently 1024 characters. In QueryPlanTool, we ultimately concatenate a number of constituent QueryEngineTools into a single OpenAI tool. Obviously this character limit will be hit after adding enough engine tools, and probably pretty quickly. I've made some small changes and added a notebook to demonstrate an alternative solution: moving the engine tools to the prompt.

I made a small opinionated change to allow manual overriding of the QueryPlanTool metadata, which will enable the separation of these tool components. Feel free to suggest another approach if it aligns better (e.g., we could have added an optional parameter to QueryToolPlan that allows users to omit the tool descriptions in the metadata getter).

Fixes #13159

New Package?

Did I fill in the tool.llamahub section in the pyproject.toml and provide a detailed README.md for my new integration or package?

  • Yes
  • No

Version Bump?

Did I bump the version in the pyproject.toml file of the package I am updating? (Except for the llama-index-core package)

  • Yes
  • No

Type of Change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Added new unit/integration tests
  • Added new notebook (that tests end-to-end)
  • I stared at the code and made sure it makes sense

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks.
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I ran make format; make lint to appease the lint gods

@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label May 23, 2024
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@@ -70,6 +70,11 @@ def to_openai_function(self) -> Dict[str, Any]:

def to_openai_tool(self) -> Dict[str, Any]:
"""To OpenAI tool."""
if len(self.description) > 1024:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my one comment is that (sadly) this function is used in a few things outside the scope of openai (namely, inside the huggingface llm integration, and the mistral llm integration.

Should we have an optional flag to disable this check for these cases?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh interesting, I was wondering why it appears in core. I can definitely add a flag, should we default to skipping the check?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since its specific to openai (or supposed to be lol), we should probably default to checking, and use the flag to disable

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay cool, should I update any of these other calls to set this flag? Will any break if we don't?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea lets update them to set the flag. They won't break per-say without it, but I'm not 100% sure if they have this limit

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the flag, let me know if I missed anything!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great write-up! And a decent workaround.

Do you think its worthing doing this automatically in the query plan tool constructor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Yep we could easily modify the tool definition automatically, but if the user isn't aware that we've omitted the engine tool definitions, I suppose they won't know to include them in their agent query call. We could add an optional constructor param to omit the engine tool definitions, but this would be less automatic. Let me know what you think, I'm indifferent

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right right -- the tool itself is still disconnected from the overall prompt

Ok, this is fine for now 👍🏻

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label May 24, 2024
@logan-markewich logan-markewich enabled auto-merge (squash) May 24, 2024 17:26
@logan-markewich logan-markewich merged commit 45b9c94 into main May 24, 2024
8 checks passed
@logan-markewich logan-markewich deleted the joel/long-tool-descriptions branch May 24, 2024 17:56
Mateusz-Switala pushed a commit to Mateusz-Switala/llama_index that referenced this pull request Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: QueryPlanTool --> function description too long
2 participants