Text Generation
The Text Generation in Compass supports chat completions that take image, text, and audio inputs and generate text and audio outputs. These inputs are accepted as a text message, an audio, a string, an array, or a message object. Each message has a role, either a user, system, or an assistant, and includes content. The user message provides requests or comments for the assistant to respond. Assistant messages store previous responses, but you can also write them to give examples of desired behavior. By default, the system message is ‘You are a helpful assistant’. You can define instructions in the user messages, but the system messages are more effective. Only one system message per conversation can be set.
Text Inputs
Chat models take a list of messages as input and return a model-generated message as output. Although the chat format is designed to make multi-conversations easy, it is also useful for single-turn tasks without any conversation.
Sample Request Format
{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "Hi"
}
],
"stream": false
}
Learn more about text generation through Chat Completions API reference documentation.
Sample Response Format
{
"choices": [
{
"finish_reason": "stop",
"index": 0,
"logprobs": null,
"message": {
"content": "Hi there! How can I assist you today?",
"refusal": null,
"role": "assistant"
}
}
],
"created": 1741094330,
"id": "chatcmpl-B7MSYFDZlO44mbrbW4BRE0wvEN1DQ",
"model": "gpt-4o-2024-08-06",
"object": "chat.completion",
"system_fingerprint": "fp_b705f0c291",
"usage": {
"completion_tokens": 10,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0,
"rejected_prediction_tokens": 0
},
"prompt_tokens": 9,
"prompt_tokens_details": {
"audio_tokens": 0,
"cached_tokens": 0
},
"total_tokens": 19
}
}
The reply can be extracted with message = completion.choices[0].message.content.
Each response includes finish_reason, and the possible values are:
- stop: API returns a complete message or a message terminated by one of the stop sequences provided via the stop parameter
- length: Incomplete model output due to max_tokens parameter or token limit
- function_call: The model decided to call a function
- content_filter: Omitted content due to a flag from our content filters
- null: API response still in progress or incomplete
Based on the input parameters, the model response may include information other than the above parameters.
Text Input and Audio Output
GPT-4o Audio takes text inputs and provides the audio reponse in any of the support voices. The supported voices are alloy, ash, ballad, coral, echo, sage, and shimmer.
curl --location 'https://api.core42.ai/openai/deployments/gpt-4o-audio-preview/chat/completions?api-version=2024-11-01-preview' --header 'api-key: add-api-key' --header 'Content-Type: application/json' --data '
{
"model": "gpt-4o-audio-preview",
"modalities": [
"text",
"audio"
],
"audio": {
"voice": "alloy",
"format": "wav"
},
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is in this recording?"
},
{
"type": "input_audio",
"input_audio": {
"data": "base-64-encoding",
"format": "wav"
}
}
]
}
]
}'
}