Here is how I think ‘function calling’ works:
* User asks a question.
* The model recognizes the need for a function call and outputs a JSON object with the function call’s name and required arguments.
* My application backend then makes the appropriate API call or database query.
* The response from this API call is sent back to the model.
* The model then crafts a human-readable response based on this data and sends it back to the user.
When function calling is available in fine-tuned models (i don’t believe it’s available yet but I understand it’s coming), In preparation for this new feature I want to build out my training data to support getting data from multiple functions and leveraging it in a formatted response.
I’m making an assumption (I know… that’s bad…) that the training data instructs the model on how to respond to user queries and, more importantly for this use case, when to invoke a function call to fetch external data. I believe that the “bridge” between the training data and the function calls is the learned behavior of the model to recognize when it should fetch external data based on user input and the context of the conversation. Given this, I’m wondering if I can structure training data to teach the model when to make a function call.
For Example:
User: “What will a 2% rise in the inflation rate in the US do to my portfolio?”
Assistant: (Recognizing the need for real-time data) “Let me get your portfolio and also check the current inflation rate for you.”
Model’s Function Call: The model then makes a function call to get_portfolio.
Function’s Response: User owns 10 shares of Apple.
Model’s Function Call: The model then makes a function call to get_current_inflation with the argument { “country”: “US” }.
Function’s Response: The function returns with a data point, for example, 5.4% and adds 2% for new inflation rate of 7.4%.
Model’s Function Call: The model then makes a function call to calculate_what_a_rise_in_inflation_will_do to each asset in the portfolio.
Function’s Response: The function returns the potential impact to Apple
Assistant’s Final Response: “The current inflation rate in the US is 5.4% and a 2% increase will make the inflation rate 7.4% and impact on Apple may be ZZZ”
My Question: In the training data, would it look something like:
{
"model": "gpt-3.5-turbo-0613",
"messages": [
{"role": "user", "content": "What will a 2% rise in the inflation rate in the US do to my portfolio?"},
{"role": "assistant", "content": null, "function_call": {"name": "get_current_inflation", "arguments": "{ \"country\": \"US\"}"}},
{"role": "function", "name": "get_current_inflation", "content": "{\"rate\": \"5.4%\"}"},
{"role": "assistant", "content": null, "function_call": {"name": "get_portfolio"}},
{"role": "function", "name": "get_portfolio", "content": "{\"asset\": \"Apple\",\"shares\": \"10\"}"},
{"role": "assistant", "content": null, "function_call": {"name": "what_a_rise_in_inflation_will_do", "arguments": "{\"inflation\": \"5.4%\", \"portfolio\":{\"asset\": \"Apple\",\"shares\": \"10\"}}"}},
{"role": "function", "name": "what_a_rise_in_inflation_will_do", "content": "{\"impact\": \"ZZZ\"}"},
{"role": "assistant", "content": "The current inflation rate in the US is 5.4%. With a 2% increase, this would reach 7.4%. Given your portfolio holding 10 shares of Apple, the impact would be ZZZ."}
]
}