-
-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Description
Steps to reproduce:
- Collect a sequence of messages to pass to open AI (of type {:role role :content content}) that exceed the model's token limit. In my case, GPT-3.5 turbo with 4097 tokens
- Hit the synchronous chat completions endpoint. I use OpenAI without Azure. You get an exception HTTP response with status 400 and the following body
:body
"{\n \"error\": {\n \"message\": \"This model's maximum context length is 4097 tokens. However, your messages resulted in <more>. Please reduce the length of the messages"
- Repeat the same experiment, this time setting the
:stream
parameter to true. My setup doesn't have a handler in order to receive a channel back - You should see a similar HTTP 400 exception thrown, but in the body you will see your request body rather than the helpful error message.
Attached below is the function I use to invoke the OpenAI endpoint:
(defn ask
([questions]
(ask questions {} {}))
([questions payload-params]
(ask questions payload-params {}))
([questions payload-params opts]
(let [payload (merge payload-params {:model "gpt-3.5-turbo"
:messages questions
:temperature 0})
options (assoc opts :api-key openai-token)]
(api/create-chat-completion payload options))))
In this case it was invoked as (ask messages {:stream true}
Thank you for making this library, it was tremendously helpful in avoiding a lot of really boring work.
Metadata
Metadata
Assignees
Labels
No labels