#playground testing function calling

1 messages · Page 1 of 1 (latest)

stuck pier
#

im in the openai api playground in the chat mode. i see a spot to add system prompt and user/assistant messages, but i don't see where to specify function calling declartions

faint micaBOT
#

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

#

In the OpenAI API playground, you can specify function calling declarations in the JSON payload that you send to the API. The function declarations are specified in the functions field of the payload. Here's an example of how you might structure your payload:

{
  "model": "gpt-3.5-turbo",
  "messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Translate the following English text to French: 'Hello, how are you?'"}
  ],
  "functions": [
    {
      "name": "translate",
      "description": "Translates English text to French",
      "parameters": {
        "text": {
          "type": "string",
          "description": "The text to translate"
        }
      }
    }
  ]
}

In this example, a function called translate is declared, which takes a single parameter text. The function is then available for the model to call in its responses.

Please note that the actual execution of the function is not handled by the API. The API will generate a function call, but it's up to your application to interpret and execute the function call.

For more information on function calling, you can refer to the OpenAI Cookbook's guide on function calling (https://cookbook.openai.com/examples/how_to_call_functions_with_chat_models) and the OpenAI API documentation (https://platform.openai.com/docs/api-reference).

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

#

@stuck pier kapa.ai is still learning and improving, please let us know how it did by reacting below

stuck pier
#

@faint mica how do i do that in the playground

faint micaBOT
#

Let me check the knowledge base for you. One moment! :books:

#

I'm sorry for any confusion, but currently, the OpenAI Playground does not support function calling directly. The Playground is primarily designed for testing and exploring the capabilities of the models, and it doesn't have the capability to execute custom functions.

However, you can simulate function calling in the Playground by manually adding function call responses to the conversation. For example, if you have a function that translates English to French, you can manually add a message with the role "function" and the content being the translated text.

If you want to use function calling in a real application, you would need to use the OpenAI API and handle the function execution in your own code. You can refer to the OpenAI Cookbook's guide on function calling (https://cookbook.openai.com/examples/how_to_call_functions_with_chat_models) and the OpenAI API documentation (https://platform.openai.com/docs/api-reference) for more information on how to do this.

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

#

@stuck pier kapa.ai is still learning and improving, please let us know how it did by reacting below

stuck pier
#

@faint mica i guess what i'm saying is that the OpenAI Playground only allows setting a system prompt and then a series of user/assistant messages. so the only roles available are system, user, assistant. in reality, the system message does not need to come first, and you are not limited to only one of them. and there is no support for providing function declarations with the prompt, and no support for the necessary function_call and function roles necessary to properly play with function calling simulation. i totally understand the API will not execute the function handlers of course, but i would expect to be able to simulate the actual production API where i can send a prompt that includes function declarations and messages with roles of system, user, assistant, function_call, and function. i guess the web interface needs improvement by the devs

faint micaBOT
#

Let me check the knowledge base for you. One moment! :books:

#

You're correct in your understanding. The OpenAI Playground currently supports system, user, and assistant roles for messages, and it doesn't directly support function declarations or function calling simulation. The Playground is a simplified interface designed primarily for testing and exploring the capabilities of the models.

In a real application using the OpenAI API, you would have more flexibility. You can include function declarations in your API calls, and you can include messages with roles of system, user, assistant, function_call, and function. The API will generate function calls based on the function declarations and the conversation, and your application can then execute these function calls and add the results back into the conversation.

Your feedback about the limitations of the Playground is valuable, and I'm sure the OpenAI team would appreciate it. OpenAI is continually working to improve its tools and interfaces, and user feedback is an important part of that process.

For more detailed information on function calling and how to use it in your applications, you can refer to the OpenAI Cookbook's guide on function calling (https://cookbook.openai.com/examples/how_to_call_functions_with_chat_models) and the OpenAI API documentation (https://platform.openai.com/docs/api-reference).

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