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
[FunctionTool] Use docstring_parser to infer description for FunctionTool #12864
base: main
Are you sure you want to change the base?
Conversation
It was already openai format wasn't it? I see your diff has changed more than just the docstring. What is the issue with the original code? It works fine for me from llama_index.core.tools import FunctionTool
from llama_index.agent.openai import OpenAIAgent
from typing import Literal
def get_current_weather(
location: str, unit: Literal["celsius", "fahrenheit"] = "celcius"
) -> str:
"""Get the current weather in a given location
Args:
location (str): The city and state, e.g. San Francisco, CA
"""
return "-10C"
tool = FunctionTool.from_defaults(fn=get_current_weather)
agent = OpenAIAgent.from_tools([tool], verbose=True)
response = agent.chat("What is the current weather in Toronto, Canada?")
print(str(response)) |
Calling with current code
Calling with this PR
|
@logan-markewich The change is focused on the descriptions. The original code just wrote the function description with docstring + function signature, and no description inside the params. While the OpenAI example in their document wrote the function description and params description (which is the JSON schema way). I believe the change can make the LLM perform better in complex tasks because of fewer ambiguous and the same format as their training data (although no difference in the simple get_weather task) |
replying to @logan-markewich Seems legit(better now?) as |
Description
In this PR, I updated the
llama_index.core.tools
package to use docstring_parser to parse afunction.__doc__
, so that to make theFunctionTool
to comply with the general format (openai format).Originally, the
description
provided byFunctionTool
is simply__doc__
andsignature()
. Using the docstring_parser, we can parse the__doc__
to get the function description and per param's description, so that to make theFunctionTool.metadata
passed to the LLM API the same as the OpenAI's example.For the OpenAI's example,
diff between old and new:
Type of Change
Please delete options that are not relevant.
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
Suggested Checklist:
make format; make lint
to appease the lint gods