#15 tips and steps to use "functions" of the api

1 messages · Page 1 of 1 (latest)

amber ivy
#

15 tips and steps to use "functions" of the api

late ferryBOT
#

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:

  1. 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)).

  2. Use the Latest Models: The latest models (gpt-3.5-turbo-0125 and gpt-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)).

  3. 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)).

  4. 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)).

  5. Define Functions: Define functions like send_email(to: string, body: string), or get_current_weather(location: string, unit: 'celsius' | 'fahrenheit') (source (https://platform.openai.com/docs/guides/function-calling)).

  6. 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)).

#
  1. Extract Structured Data from Text: Define a function called extract_data(name: string, birthday: string), or sql_query(query: string) (source (https://platform.openai.com/docs/guides/function-calling)).

  2. 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)).

  3. 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)).

  4. 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)).

  5. 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)).

  6. 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)).

  7. 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)).

  8. Use Legacy Format for Fine-Tuning API: The function_call and


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: