OpenAI -> Create a Chat Completion
Action summary
OpenAI -> Create a Chat Completion
Function Documentation: OpenAI -> Create a Chat Completion
Overview
This function generates a chat completion using the OpenAI API based on a user-provided input text. It requires parameters such as the model & input message. The function validates environment variables and conditions before making an API request and processing the response.
Inputs
- openai_api_key (registry|text) Required Sensitive data
- Description: The API key for your OpenAI account.
- model (enum) Required
- Description: Specifies the model to be used for generating the chat completion.
- Options:
gpt-4o-mini
(default)gpt-4o
- message (text) Required
- Description: The input message or prompt that will be sent to the OpenAI API for generating the chat completion.
Function Stack
1. OpenAI API Request
- API Request to
https://api.openai.com
- Purpose: Sends a request to the OpenAI API using the specified model and message.
- Precondition:
openai_api_response.status == 200
- Purpose: Confirms that the API request was successful (HTTP status code 200).
2. OpenAI API Response
- Create Variable:
response
- Purpose: Stores the response from the OpenAI API.
Response
- The function returns the generated chat completion
Success response
{"Barack Obama is 6 feet 1 inch tall (185 cm)."}
Error response
{
"message": "Incorrect API key provided: ssk-None*********************************************GQPD. You can find your API key at https://platform.openai.com/account/api-keys."
}
Example
Input
{ "model": "gpt-4o-mini", "message": "What is Obama's height?" }
Response
{"Barack Obama is 6 feet 1 inch tall (185 cm)."}
Version notes
2024-10-04 14:44:00
Current