-
Notifications
You must be signed in to change notification settings - Fork 7.9k
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
docker配置智谱AI环境变量运行报错,已给出相应的解决方案 #2289
Comments
看你日志,应该是配置文件没生效,走的还是gpt模型 |
|
补充一下,我使用的是glm-4-flash |
在config.json中加入 "model": "glm-4-air", "zhipu_ai_api_key": "", 即可使用 |
前置确认
操作系统类型?
MacOS
运行的python版本是?
python 3.8
使用的chatgpt-on-wechat版本是?
Latest Release
运行的
channel
类型是?wx(个人微信, itchat)
复现步骤 🕹
docker-compose文件配置
问题描述 😯
从你提供的错误信息中,可以看到两个主要的问题:
num_tokens_from_messages() is not implemented for model GLM-4 这表明在使用 GLM-4 模型时,代码逻辑尝试计算消息的 token 数量,但目前没有为 GLM-4 实现该功能。系统默认返回的是 gpt-3.5-turbo 的 token 数计算方式。这表明你的代码在处理不同模型时可能没有处理得当。
Incorrect API key provided: YOUR API KEY 错误提示 API 密钥无效。这是因为你在代码或配置中提供了错误的 API 密钥,也可能是你在调用 OpenAI 的 API 而不是 Zhipu AI 的 API。
问题原因分析
num_tokens_from_messages() 函数是用于计算消息中 token 数量的,但该函数可能只针对 OpenAI 的 GPT 模型有效。如果你使用 GLM-4,需要确保在代码中处理该模型时不调用该函数,或者为 GLM-4 模型实现相应的 token 计算逻辑。
检查文件 /mnt/data/chatgpt-on-wechat/chatgpt-on-wechat/bot/zhipuai/zhipuai_bot.py 或相关代码中的 token 计算逻辑,特别是 num_tokens_from_messages() 的调用。你可能需要为 GLM-4 实现一个自定义的 token 计算方法,或者跳过这个步骤。
错误信息表明代码正在调用 OpenAI 的 API (openai.ChatCompletion.create()),并且 API Key 错误,说明配置中提供的 ZHIPU_AI_API_KEY 和 ZHIPU_AI_API_BASE 并没有在正确的地方被使用,仍在使用 OpenAI 的 API 逻辑。
你需要确保:
确认 docker-compose.yml 中的 ZHIPU_AI_API_KEY 和 ZHIPU_AI_API_BASE 已正确传递到代码中。
确认在代码中调用 Zhipu AI API 时,正确使用了 ZHIPU_AI_API_KEY 和 ZHIPU_AI_API_BASE,而不是错误地调用了 OpenAI 的 API。
修复方法
你可以通过添加模型判断条件来避免在 GLM-4 模型下调用不适用的函数。
python
检查代码中的 API 调用逻辑,确保在调用 Zhipu AI API 时,使用的是正确的 ZHIPU_AI_API_KEY 和 ZHIPU_AI_API_BASE。特别是在 zhipuai_bot.py 中,API 的调用应如下所示:
python
如果仍在使用 OpenAI 的 API,请确保逻辑正确切换为 Zhipu AI 的 API。
此外,确保代码中打印日志以调试是否正确加载了 Zhipu AI 的 API Key 和 Base URL:
python
总结
你需要修复 num_tokens_from_messages() 函数在 GLM-4 模型下的调用问题。
确保在代码中正确使用 Zhipu AI 的 API,而不是 OpenAI 的 API。
检查环境变量是否正确传递并在代码中生效,避免使用错误的 API 密钥。
终端日志 📒
The text was updated successfully, but these errors were encountered: