openai.createChatCompletion

Returns a predicted chat completion for the given messages.

Syntax

createChatCompletion(params)

Parameters

Return value

An object containing response from OpenAI API.

Example

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
           }]
}

External resources