Chat Completion

Once you initialized the client and stored it as a variable, we can simply use the TextCompletion function in the client like this:

 local response = client.ChatCompletion({
    messages = {
        {
            role = 'system',
            content = 'You are an helpful assistant.'
        },
        {
            role = 'user',
            content = 'Who are you?'
        }
    }
})

The response variable will contain the following:

  • Used model "response.model" (string)

  • The first choice "response.choice" (table)

  • The first choice's message object "response.choice_message" (table)

  • Token usage "response.usage" (table)

All arguments/Options

model (string) (optional) (default: gpt-3.5-turbo)

messages (table) (required)

max_tokens (number) (optional) (default: 256)

Last updated

Was this helpful?