GaiZhenbiao / ChuanhuChatGPT

GUI for ChatGPT API and many LLMs. Supports agents, file-based QA, GPT finetuning and query with web search. All with a neat UI.
https://huggingface.co/spaces/JohnSmith9982/ChuanhuChatGPT
GNU General Public License v3.0
15.07k stars 2.28k forks source link

[Bug]: 自定义模型没有使用自定义api_host #1117

Closed zodiacg closed 1 month ago

zodiacg commented 2 months ago

这个bug是否已存在现有issue了?

错误表现

使用自定义模型添加模型:

"extra_model_metadata": {
        "GLM-4": {
            "model_type": "OpenAIVision",
            "model_name": "glm-4",
            "multimodal": false,
            "api_host": "http://one-api:3000/",
            "api_key": "sk-XXXXXXXXXXXXXXXXXX",
         }
}

选择模型进行使用时,会报错:

{    "error": {        "message": "Incorrect API key provided: sk-XX*****************************XXX. You can find your API key at https://platform.openai.com/account/api-keys.",        "type": "invalid_request_error",        "param": null,        "code": "invalid_api_key"    }}

经检查发现OpenAPIVision中第40行处,虽然使用api_host生成了新的API URL,但并没有使用。实际使用中使用的是shared.state中的对应OpenAI原始URL

复现操作

  1. Docker部署Chuanhu Chat和OneAPI
  2. 使用自定义模型添加模型:
    "extra_model_metadata": {
        "GLM-4": {
            "model_type": "OpenAIVision",
            "model_name": "glm-4",
            "multimodal": false,
            "api_host": "http://one-api:3000/",
            "api_key": "sk-XXXXXXXXXXXXXXXXXX",
         }
    }
  3. 使用时选择自定义模型
  4. 控制台报错Incorrect API key

错误日志

No response

运行环境

帮助解决

补充说明

No response

GaiZhenbiao commented 2 months ago

我看看

vc12345679 commented 2 months ago

举例: extra_model_metadata 设置如下时

"extra_model_metadata": {
      "DeepSeek V2": {
            "model_name": "deepseek-chat",
            "description": "This is DeepSeek's powerful open source LLM.",
            "model_type": "OpenAIVision",
            "multimodal": false,
            "api_host": "https://api.deepseek.com",
            "api_key": "sk-xxxxxxxx",
            "token_limit": 4096,
            "system": "You are a helpful AI assistant.",
            "placeholder": {
                "logo": "https://avatars.githubusercontent.com/u/148330874",
            }
      },
},

OpenAIVision.py 里 __init__(), _get_response(), _single_query_at_once() 三个函数中的变量分别为

self.api_host               https://api.deepseek.com
self.chat_completion_url        https://api.deepseek.com/v1/chat/completions
self.images_completion_url      https://api.deepseek.com/v1/images/generations
self.openai_api_base            https://api.deepseek.com/v1
self.balance_api_url            https://api.deepseek.com/dashboard/billing/credit_grants
self.usage_api_url          https://api.deepseek.com/dashboard/billing/usage
shared.state.chat_completion_url    https://api.openai.com/v1/chat/completions
CHAT_COMPLETION_URL         https://api.openai.com/v1/chat/completions

requests.post() 时的 url 为 shared.state.chat_completion_url,应更正为 self.chat_completion_url #1125 。更正后运行正常

chat_DeepSeek-V2

Keldos-Li commented 1 month ago

closed via #1125