ruby-openai icon indicating copy to clipboard operation
ruby-openai copied to clipboard

Configure maximum length

Open eslamodeh opened this issue 1 year ago • 4 comments

Hey everyone 👋

In Chat GPT UI, you can configure the maximum length / token the model(assistance) should return. Is it possible to configure this at the moment?

image

eslamodeh avatar Feb 20 '24 22:02 eslamodeh

Fairly sure this is "max_tokens" as per the API Docs and seems to work fine.

https://platform.openai.com/docs/api-reference/chat/create

MyklClason avatar Feb 25 '24 18:02 MyklClason

Thanks @MyklClason

Is this configurable in this SDK?

eslamodeh avatar Feb 26 '24 08:02 eslamodeh

Check the docs for "Chat." You just set it as one of the parameters. max_tokens: 500 or something.

response = client.chat(
    parameters: {
        model: "gpt-3.5-turbo", # Required.
        messages: [{ role: "user", content: "Hello!"}], # Required.
        temperature: 0.7,
        max_tokens: 500,
    })
puts response.dig("choices", 0, "message", "content")
# => "Hello! How may I assist you today?"

MyklClason avatar Feb 26 '24 13:02 MyklClason

P.S. That model isn't the one you want to be using, so make sure to update that.

MyklClason avatar Feb 26 '24 13:02 MyklClason

Thanks for the question @eslamodeh and the answer @MyklClason !

alexrudall avatar Apr 27 '24 21:04 alexrudall