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

community[patch]: truncate zhipuai temperature and top_p parameters to [0.01, 0.99] #20261

Merged
merged 8 commits into from
Apr 19, 2024

Conversation

Congyuwang
Copy link
Contributor

@Congyuwang Congyuwang commented Apr 10, 2024

ZhipuAI API only accepts temperature parameter between (0, 1) open interval, and if 0 is passed, it responds with status code 400.

However, 0 and 1 is often accepted by other APIs, for example, OpenAI allows [0, 2] for temperature closed range.

This PR truncates temperature parameter passed to [0.01, 0.99] to improve the compatibility between langchain's ecosystem's and ZhipuAI (e.g., ragas evaluate often generates temperature 0, which results in a lot of 400 invalid responses). The PR also truncates top_p parameter since it has the same restriction.

Reference: glm-4 doc (which unfortunately is in Chinese though).

Copy link

vercel bot commented Apr 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Apr 19, 2024 1:27am

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. 🤖:improvement Medium size change to existing code to handle new use-cases labels Apr 10, 2024
@Congyuwang
Copy link
Contributor Author

This PR follows up #16695

@Congyuwang
Copy link
Contributor Author

Congyuwang commented Apr 10, 2024

@baskaryan @hwchase17

@Congyuwang Congyuwang changed the title community: truncate zhipuai temperature and top_p parameters to [0.01, 0.99] community[patch]: truncate zhipuai temperature and top_p parameters to [0.01, 0.99] Apr 14, 2024
@Congyuwang
Copy link
Contributor Author

Got the lint fixed.

@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Apr 18, 2024
@Congyuwang
Copy link
Contributor Author

Looks like the workflows needs approval too. Thx.

@baskaryan baskaryan enabled auto-merge (squash) April 18, 2024 18:04
auto-merge was automatically disabled April 19, 2024 01:22

Head branch was pushed to by a user without write access

"""Truncate temperature and top_p parameters between [0.01, 0.99].

ZhipuAI only support temperature / top_p between (0, 1) open interval,
so we truncate them to [0.01, 0.99].
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed typo in comment truncate

Comment on lines -216 to +230
or you can use any finetune model of glm series.
Alternatively, you can use any fine-tuned model from the GLM series.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix some grammar in comment too.

@baskaryan baskaryan enabled auto-merge (squash) April 19, 2024 01:27
@baskaryan baskaryan merged commit dd5139e into langchain-ai:master Apr 19, 2024
60 checks passed
@Congyuwang Congyuwang deleted the fix-zhipuai-temperature branch April 19, 2024 03:19
hinthornw pushed a commit that referenced this pull request Apr 26, 2024
…rs to [0.01, 0.99] (#20261)

ZhipuAI API only accepts `temperature` parameter between `(0, 1)` open
interval, and if `0` is passed, it responds with status code `400`.

However, 0 and 1 is often accepted by other APIs, for example, OpenAI
allows `[0, 2]` for temperature closed range.

This PR truncates temperature parameter passed to `[0.01, 0.99]` to
improve the compatibility between langchain's ecosystem's and ZhipuAI
(e.g., ragas `evaluate` often generates temperature 0, which results in
a lot of 400 invalid responses). The PR also truncates `top_p` parameter
since it has the same restriction.

Reference: [glm-4 doc](https://open.bigmodel.cn/dev/api#glm-4) (which
unfortunately is in Chinese though).

---------

Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:improvement Medium size change to existing code to handle new use-cases lgtm PR looks good. Use to confirm that a PR is ready for merging. size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants