wkok / openai-clojure

Clojure functions to drive the OpenAI API
https://cljdoc.org/d/net.clojars.wkok/openai-clojure
MIT License
208 stars 28 forks source link

[Support] Allow nil to be a value in parameters #30

Closed jungwookim closed 1 year ago

jungwookim commented 1 year ago

I'm unsure whether this report should be included in this library, but I want to mention that the error below occurs when the content is nil during function calls.

; Execution error (ExceptionInfo) at schema-tools.coerce/coerce-or-error! (coerce.cljc:24).
; Could not coerce the value to schema: {:body {:messages [nil nil nil nil nil nil {:content (not (instance? java.lang.String nil))} nil]}}

This issue can be reproduced when using function calls as a response of create-chat-completion. The response value appears as {:role "assistant", :content nil, :function_call {:name "some-function", :arguments "{\n \"name\": \"someName\"\n}"}}), but it's an invalid schema in the API. I may have a workaround, but I'd like to inquire if supporting nil as a value is allowed.

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

content string Optional
The contents of the message. content is required for all messages except assistant messages with function calls.
wkok commented 1 year ago

There was an update to the openai spec not so long ago that now allows null for content

I have updated this latest schema in v0.9.0 so this issue should now be fixed

jungwookim commented 1 year ago

Great for the work. Thanks!