-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ChatCompletionRequest
discards stream
field when set to false
#435
Comments
@odannyc The 'stream' field is optional, and its default value is false. Therefore, even if we don't remove 'omitempty', it will be set to false unless explicitly specified otherwise. Refs: |
Thank you for the quick response @vvatanabe - that is true for open AI. But there are other services to might default to IMO if I set it to the |
I have summarized the pros and cons for both cases: removing the omitempty and not removing it. Removing omitempty Pros:
Cons:
Not removing omitempty Pros:
Cons:
|
Given that the Stream field is optional according to the OpenAI API specifications, it might be better to change it to a pointer as follows:
With this change, the value won't be sent unless the developer explicitly sets the Stream field. The value is sent only when it's explicitly set. This behavior aligns with the OpenAI API specifications. |
This behavior is not actually a bug, so I change the label. |
Thank you! Let me know if you need help with implementing this. |
@vvatanabe @odannyc This will indeed work, but be advised that it'll be hacky as you cannot pass untyped bool constants in struct literals "cleanly". Meaning that for every request that will require a change, the code will be littered w/ the following: val := true // this is a hack to pass a pointer to a bool to the stream field
stream, err := client.CreateChatCompletionStream(context.Background(), ChatCompletionRequest{
MaxTokens: 5,
Model: GPT3Dot5Turbo,
Messages: []ChatCompletionMessage{
{
Role: ChatMessageRoleUser,
Content: "Hello!",
},
},
Stream: &val,
}) Or stream, err := client.CreateChatCompletionStream(context.Background(), ChatCompletionRequest{
MaxTokens: 5,
Model: GPT3Dot5Turbo,
Messages: []ChatCompletionMessage{
{
Role: ChatMessageRoleUser,
Content: "Hello!",
},
},
// another hack: this creates an array with a single bool element set to true,
// and then takes the address of the first element.
Stream: &[]bool{true}[0],
}) Or We can build a "cleaner" hack and create a function instead: func BoolPtr(b bool) *bool { return &b }
// then call it in the struct literal
Stream: BoolPtr(true) There's also a way to do this by creating default structs or the builder pattern, etc. With all of that being said. I still think that the trade-off may be worth it (and I would choose the first example), but it is important to note it for codebase readability. Please advise |
Your issue may already be reported!
Please search on the issue tracker before creating one.
Describe the bug
A clear and concise description of what the bug is. If it's an API-related bug, please provide relevant endpoint(s).
I'd like to explicitly set the
stream
field tofalse
and have that sent over to the server. Unfortunately, that field has theomitempty
json tag which causes it to be discarded from the final request payload. Can we remove theomitempty
json tag?Source:
go-openai/chat.go
Line 51 in c3b2451
The text was updated successfully, but these errors were encountered: