Facing complexities with OpenAI’s APIs? I made a small project called LLM FOO to help with tool / function calling. The project aims to reduce verbosity and ease documentation efforts with the @tool decorator. It’s a work in progress, and I’m eager for your insights and contributions. I would love to get some feedback to make it really useful for everybody.
Basic idea is to automatically generate Function json schema with GPT-4-turbo and have convenience methods for function calling.
Seems I can’t make links but pip install llmfoo and you can find the project from github robocorp llmfoo.
That sounds really interesting, but you kind of lost me with the description. Why not just describe functions in structured prompts and let ChatGPT (likely using gpt-4-turbo or similar itself) crank out the functions?
Thanks for the interest!
The tool does the following (assume you want to expose adder as a tool / function calling):
from llmfoo.functions import tool
@tool
def adder(x: int, y: int) -> int:
return x + y
This will call on the first time gpt-4-turbo to crank out the function definition JSON. This is stored to a file in the same directory as the original function is ($FILE.tool.json).
Notice that you do not have to do any additional documentation if you do not want to.
After first run the annotation will use the definition generated into $FILE.tool.json and not call gpt-4-turbo. You may also modify the definition there.
It looks something like this for the adder in $FILE.tool.json
"adder": {
"type": "function",
"function": {
"name": "adder",
"description": "Adds two integer numbers together and returns the sum.",
"parameters": {
"type": "object",
"properties": {
"x": {
"type": "integer",
"description": "The first integer to be added."
},
"y": {
"type": "integer",
"description": "The second integer to be added."
}
},
"required": [
"x",
"y"
]
}
}
},
The annotation adds few convenience fields to the function being annotated:
adder.openai_schema # The JSON for tool / function calling definition
...
messages.append(adder.openai_tool_call(response.choices[0].message.tool_calls[0])) # Message handler that returns directly response as valid a function call response message.
...
adder.openai_tool_output(tool_call) # Handler that returns directly response in the Assistant API tool output.
Hope this helps define what the tool does. I think there is still a lot room to improve but the basic idea is there:
Let the ChatGPT define the docs for ChatGPT and re-use the definition. Allow humans to modify the definitions.