#feature call openai feature

1 messages · Page 1 of 1 (latest)

frank quail
#

with function call openai feature, i want to get directly response instead of having a question for example the openai response is "{
role: 'assistant',
content: 'I can find the prices for you, but I need additional information to ensure accuracy. Could you please specify the year or the model specifications of the MacBook Pro 16-inch you are referring to? This could include details like the processor type, storage capacity, or any special configurations.'
} but instead i want directly the response including tool_calls even if data is approximate

wet trenchBOT
#

Hi @frank quail. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To get a direct response from the OpenAI model that includes tool_calls, you need to use the function calling feature of the OpenAI API. This feature allows the model to generate a JSON object containing arguments to call one or many functions based on the user's input. However, the model does not actually call the function; it only generates the JSON that you can use to call the function in your code.

Here's a basic sequence of steps for function calling:

  1. Call the model with the user query and a set of functions defined in the functions parameter.
  2. If the model decides a function needs to be called, it will return a message with role='assistant' and content=null, and a tool_calls field containing the function call details.
  3. You then need to run the function in your code and return the results using the submitToolOuputs endpoint. The model then uses the results to form a response.

Here's an example of how a function call might look in the model's response:

{
 "role": "assistant",
 "content": null,
 "tool_calls": [
  {
   "id": "call_CBwbo9qoXUn1kTR5pPuv6vR1",
   "type": "function",
   "function": {
    "name": "getLocation",
    "arguments": "{}"
   }
  }
 ]
}

In this example, the model is instructing you to call a function named getLocation. You would then need to call this function in your code and return the results.

Please note that the model's ability to generate function calls depends on the user's input and the functions you have defined. If the user's input does not trigger a function call, the model will not generate one. Also, the model does not have the ability to make assumptions or provide approximate data if the necessary information is not provided in the user's input.