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
feat: Add support for ZhipuAI's GLM LLMs #900
base: main
Are you sure you want to change the base?
Conversation
I have a few questions:
Please don't get me wrong, I'm not trying to be rude. I just want to hear from you if you had other concerns so I can adjust my PR. |
@ifsheldon for both the For the last question - we're working on improving the typing in the repo, happy to merge any typing PRs especially if it's just adding hints to existing functions. There's a gradual effort here as well: #855 |
For Zhipu specifically, it would be great if we could incorporate it on top of the existing HTTP ChatCompletion request style instead of adding any client library dependencies. Assuming the API roughly follows OpenAI (the REST API, not the python client), it should be possible to do this via the existing credentials style + local LLM route #835 (it supports POST requests with bearer tokens or api-key headers atm, but we can add more if needed). |
I would say the APIs are a subset of OpenAI's. For example, messages don't have a See the reference code from ZhipuAI to calculate the auth codeimport time
import jwt
def generate_token(apikey: str, exp_seconds: int):
try:
id, secret = apikey.split(".")
except Exception as e:
raise Exception("invalid apikey", e)
payload = {
"api_key": id,
"exp": int(round(time.time() * 1000)) + exp_seconds * 1000,
"timestamp": int(round(time.time() * 1000)),
}
return jwt.encode(
payload,
secret,
algorithm="HS256",
headers={"alg": "HS256", "sign_type": "SIGN"},
) As for dependency management, yeah, managing dependencies is hell in Python. I took a closer look at the code of
See the dependency trees of `memgpt` and `zhipuai`I deleted irrelevant dependency branches. You can see the only addition is
So, I think it's fine to introduce |
Please describe the purpose of this pull request.
This intends to add support for LLMs from ZhipuAI. The new
glm-4
model is comparable to GPT-4-Turbo and better at Chinese. The APIs for calling this model is almost the same as the latest OpenAI APIs, so we think it's fairly straightforward and easy to add the support.How to test
Not yet. This is a draft PR
Have you tested this PR?
Not yet. This is a draft PR
Related issues or PRs
We want to add this for better Chinese support. See #799
Is your PR over 500 lines of code?
No