#15 tips and steps to use "functions" of the api
1 messages · Page 1 of 1 (latest)
Hi @amber ivy. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Here are some tips and steps to use the "functions" feature of the OpenAI API:
-
Understand the Purpose: Functions in the API allow you to describe functions and have the model intelligently choose to output a JSON object containing arguments to call one or many functions. The model generates JSON that you can use to call the function in your code (source (https://platform.openai.com/docs/guides/function-calling)).
-
Use the Latest Models: The latest models (
gpt-3.5-turbo-0125andgpt-4-turbo-preview) have been trained to both detect when a function should to be called (depending on the input) and to respond with JSON that adheres to the function signature more closely than previous models (source (https://platform.openai.com/docs/guides/function-calling)). -
Consider User Confirmation Flows: OpenAI recommends building in user confirmation flows before taking actions that impact the world on behalf of users (sending an email, posting something online, making a purchase, etc) (source (https://platform.openai.com/docs/guides/function-calling)).
-
Use Function Calling for Structured Data: Function calling allows you to more reliably get structured data back from the model (source (https://platform.openai.com/docs/guides/function-calling)).
-
Define Functions: Define functions like
send_email(to: string, body: string), orget_current_weather(location: string, unit: 'celsius' | 'fahrenheit')(source (https://platform.openai.com/docs/guides/function-calling)). -
Convert Natural Language into API Calls: Convert "Who are my top customers?" to
get_customers(min_revenue: int, created_before: string, limit: int)and call your internal API (source (https://platform.openai.com/docs/guides/function-calling)).
-
Extract Structured Data from Text: Define a function called
extract_data(name: string, birthday: string), orsql_query(query: string)(source (https://platform.openai.com/docs/guides/function-calling)). -
Call the Model with User Query and Functions: Call the model with the user query and a set of functions defined in the functions parameter (source (https://platform.openai.com/docs/guides/function-calling)).
-
Write Detailed Function Descriptions: You can use the main function description to write several paragraphs about how the function operates, just separated by linefeeds (\n) (source (https://community.openai.com/t/665368)).
-
Refer to User Conversation History: You can specifically refer to the user conversation history as a source of information (source (https://community.openai.com/t/665368)).
-
Integrate with External APIs: You can integrate the function calling with external APIs like Google Places API to enhance location-based searches (source (https://cookbook.openai.com/examples/function_calling_finding_nearby_places)).
-
Define Functions in Assistants API: Similar to the Chat Completions API, the Assistants API supports function calling. You can define your functions when creating an Assistant (source (https://platform.openai.com/docs/assistants/tools)).
-
Understand the Difference Between Assistant Functions and GPT Actions: The assistant functions are different from the GPT actions. The assistant can provide you with parameters to a function, it can't call the API itself (source (https://community.openai.com/t/523101)).
-
Use Legacy Format for Fine-Tuning API: The
function_calland