-
Notifications
You must be signed in to change notification settings - Fork 238
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
Idea - Use OpenAI functions fine tunings for param parsing #115
Comments
Hi @hardcorebadger , thank you for raising this. We do something similar when using local models, by constraining output using GBNF. For functions fine-tuning, is this example reflective of what you're referring to, where function signature is being passed to OpenAI as a # Example dummy function hard coded to return the same weather
# In production, this could be your backend API or an external API
def get_current_weather(location, unit="fahrenheit"):
"""Get the current weather in a given location"""
if "tokyo" in location.lower():
return json.dumps({"location": "Tokyo", "temperature": "10", "unit": unit})
elif "san francisco" in location.lower():
return json.dumps({"location": "San Francisco", "temperature": "72", "unit": unit})
elif "paris" in location.lower():
return json.dumps({"location": "Paris", "temperature": "22", "unit": unit})
else:
return json.dumps({"location": location, "temperature": "unknown"})
def run_conversation():
# Step 1: send the conversation and available functions to the model
messages = [{"role": "user", "content": "What's the weather like in San Francisco, Tokyo, and Paris?"}]
tools = [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location"],
},
},
}
]
response = client.chat.completions.create(
model="gpt-3.5-turbo-0125",
messages=messages,
tools=tools,
tool_choice="auto", # auto is default, but we'll be explicit
) |
Looking into implementing this: |
PR for this here: #258 |
Exciting stuff, will try it out!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Love the concept, but ran into issues with param parsing on dynamic routes with openAI, even with simple functions, when compared to running a completion on their functions fine tuning. There's likely an optimal way to parse function params using openAI's fine tuning and format, rather than having to prompt engineer 3.5-turbo into a JSON function call.
Obviously it's a bit less agnostic to foundational model, but could be dealt with via inheritance, and would make the "easy mode" work a lot better out of the box :)
The text was updated successfully, but these errors were encountered: