Returns a predicted chat completion for the given messages.
createChatCompletion(params)
params
An object with request parameters:
model optional
An identifier of the model to use (Defaults to "gpt-3.5-turbo").
messages
A an array of message objects with the following properties:
A string describing the role ("user", "assistant", "system", or "function").
A string that contains the message text.
The message author name, or the name of the function that generated content.
The name and the arguments of a function call.
functions optional
An array of function description objects that the model can use to generate JSON inputs for. A function object contains:
The function name.
A description of the function.
The function parameters described using JSON Schema.
function_call optional
The way of responding to function calls: a string ("none", "auto") or an object containing
a single key "name" and the name of the function to call.
max_tokens optional
A maximum number of tokens to generate (defaults to 16).
temperature optional
A temperature from 0 to 2 (defaults to 1). Higher values give more random results.
top_p optional
An alternative to temperature.
n optional
The number of completions to generate.
logprobs optional
The number of most likely tokens for which to include the log probabilities (defaults to 5, maximum is 5).
echo optional
Include the prompt in the response.
stop optional
An array of sentences or a string where the API will stop generating tokens (maximum is 4).
presence_penalty optional
A number between -2.0 and 2.0 (defaults to 0).
frequency_penalty optional
A number between -2.0 and 2.0 (defaults to 0).
logit_bias optional
The likelihood of specified tokens appearing in the completion.
user optional
A unique identifier of the end user.
An object containing response from OpenAI API.
await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [
{role: "user", content: "Hello!"},
{role: "assistant", content: "Hello! How can I assist you today?"},
{role: "user", content: "What's the weight of Dacia Sandero?"}
],
})
{
id: chatcmpl-6pOKSz35WXoPaQyhsb8b4FFqLqe3G,
object: chat.completion,
created: 1677706268,
model: gpt-3.5-turbo-0301,
usage: {
prompt_tokens: 38,
completion_tokens: 33,
total_tokens: 71
},
choices: [{
message: {
role: assistant,
content: The weight of Dacia Sandero varies depending on the specific model and equipment, but generally it ranges from 945 kg to 1,180 kg.
},
finish_reason: stop,
index: 0
}]
}