Skip to content
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

Workaround openai issue with temperature: 0 being omitted from request #342

Merged
merged 1 commit into from
May 10, 2024

Conversation

sd2k
Copy link
Contributor

@sd2k sd2k commented May 10, 2024

This PR adds a workaround for this GitHub discussion, describing
how chat completion requests which explicitly set temperature = 0 are
marshalled to JSON incorrectly (due to the 0 being indistinguishable
from the zero value of the field).

To do so we add a custom unmarshal method which checks whether the field
was defined and set to zero, and explicitly set the temperature to
math.SmallestNonzeroFloat32 in such cases. This isn't perfect but is
likely to get very similar results in practice.

This PR adds a workaround for [this GitHub discussion][gh], describing
how chat completion requests which explicitly set temperature = 0 are
marshalled to JSON incorrectly (due to the 0 being indistinguishable
from the zero value of the field).

To do so we add a custom unmarshal method which checks whether the field
was defined and set to zero, and explicitly set the temperature to
`math.SmallestNonzeroFloat32` in such cases. This isn't perfect but is
likely to get very similar results in practice.

[gh]: sashabaranov/go-openai#9 (comment)
Copy link
Contributor

@yoziru yoziru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Close enough, works 👍

@yoziru yoziru added the bug Something isn't working label May 10, 2024
@sd2k sd2k merged commit edfb330 into main May 10, 2024
3 checks passed
@sd2k sd2k deleted the workaround-temperature-0 branch May 10, 2024 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants