yihong0618 / xiaogpt

Play ChatGPT and other LLM with Xiaomi AI Speaker
MIT License
6.08k stars 846 forks source link

支持自定义BASE URL #325

Closed VectorZhao closed 10 months ago

VectorZhao commented 1 year ago

比如我自建了一个openai的base url,https://openai.xxx.xxx 我填到了api_base这里,后面加上了/v1

Running xiaogpt now, 用`请问`开头来提问
或用`开始对话`开始持续对话
--------------------
问题:CHINA G BT?
以下是小爱的回答:  这个问题我暂时还回答不上,需要再学习一下
以下是 CHATGPTAPI 的回答: 
[07/27/23 12:16:45] ERROR    list index out of range              xiaogpt.py:387

回答完毕
Unclosed connection
client_connection: Connection<ConnectionKey(host='openai.xxx.xxx', port=443, is_ssl=True, ssl=None, proxy=None, proxy_auth=None, proxy_headers_hash=None)>
--------------------
问题:你是谁?
以下是小爱的回答:  我叫小爱,很高兴这次的遇见,我会一直陪伴你的。
以下是 CHATGPTAPI 的回答: 
[07/27/23 12:26:46] ERROR    list index out of range              xiaogpt.py:387

回答完毕
[07/27/23 12:29:02] INFO     Serving on 192.168.125.104:9527      xiaogpt.py:303
Running xiaogpt now, 用`请问`开头来提问
或用`开始对话`开始持续对话
--------------------
frostming commented 1 year ago

https://github.com/yihong0618/xiaogpt/issues/304#issuecomment-1615724990

VectorZhao commented 1 year ago

这个issue看到了,下面是不带/v1的测试log

[07/27/23 13:43:50] INFO     Serving on 192.168.125.104:9527      xiaogpt.py:303
Running xiaogpt now, 用`请问`开头来提问
或用`开始对话`开始持续对话
--------------------
问题:你是谁?
以下是小爱的回答:  我叫小爱,很高兴这次的遇见,我会一直陪伴你的。
以下是 CHATGPTAPI 的回答: HTTP code 200 from API (<!doctype html><html lang="en"><head><meta 
charset="utf-8"/><link rel="icon" href="logo.png"/><meta name="viewport" 
content="width=device-width,initial-scale=1"/><meta name="theme-color" 
content="#ffffff"/><meta name="description" content="OpenAI 
接口聚合管理,支持多种渠道包括 Azure,可用于二次分发管理 
key,仅单可执行文件,已打包好 Docker 镜像,一键部署,开箱即用"/><title>One 
API</title><script defer="defer" 
src="/static/js/main.dc155304.js"></script><link 
href="/static/css/main.44582e8c.css" rel="stylesheet"></head><body><noscript>You
need to enable JavaScript to run this app.</noscript><div 
id="root"></div></body></html>)

回答完毕

下面是config的配置

{
  "hardware": "LX06",
  "account": "17xxxxxxxx",
  "password": "xxxxxxxxx",
  "openai_key": "sk-qxxxxxxxxxxx",
  "cookie": "",
  "mi_did": "xxxxxxxx",
  "use_command": false,
  "mute_xiaoai": true,
  "verbose": false,
  "bot": "chatgptapi",
  "enable_edge_tts": true,
  "edge_tts_voice": "zh-CN-XiaoxiaoNeural",
  "prompt": "请用100字以内回答",
  "keyword": ["请问"],
  "change_prompt_keyword": ["更改提示词"],
  "start_conversation": "开始对话",
  "end_conversation": "结束对话",
  "stream": true,
  "proxy": "",
  "gpt_options": {},
  "bing_cookie_path": "",
  "bing_cookies": {},
  "api_base": "https://openai.xxx.xxx",
  "deployment_id": "",
  "localhost": true
}

我用的是这个项目配置的api,实测其他应用是可以正常请求的。 https://github.com/songquanpeng/one-api

VectorZhao commented 1 year ago

为什么最近 "bot": "chatgptapi" 小爱说话说的是“正在问chatcopy,请耐心等待” 日志里面现实的是chatgptapi,我记得之前小爱会说“正在问gpt,请耐心等待”

chatgptapi跟gpt3,他俩啥区别啊?

azure的自定义base url始终不能成功,config.json 里面的 api_base为https://xx.xxx.xxx/v1,都是双引号括起来的。

yihong0618 commented 1 year ago

@VectorZhao 没太大区别,gpt3 我们之后会去掉。 有的原因是开始的时候 chatgpt 还没 api.

zhjnerv commented 1 year ago

这个issue看到了,下面是不带/v1的测试log

[07/27/23 13:43:50] INFO     Serving on 192.168.125.104:9527      xiaogpt.py:303
Running xiaogpt now, 用`请问`开头来提问
或用`开始对话`开始持续对话
--------------------
问题:你是谁?
以下是小爱的回答:  我叫小爱,很高兴这次的遇见,我会一直陪伴你的。
以下是 CHATGPTAPI 的回答: HTTP code 200 from API (<!doctype html><html lang="en"><head><meta 
charset="utf-8"/><link rel="icon" href="logo.png"/><meta name="viewport" 
content="width=device-width,initial-scale=1"/><meta name="theme-color" 
content="#ffffff"/><meta name="description" content="OpenAI 
接口聚合管理,支持多种渠道包括 Azure,可用于二次分发管理 
key,仅单可执行文件,已打包好 Docker 镜像,一键部署,开箱即用"/><title>One 
API</title><script defer="defer" 
src="/static/js/main.dc155304.js"></script><link 
href="/static/css/main.44582e8c.css" rel="stylesheet"></head><body><noscript>You
need to enable JavaScript to run this app.</noscript><div 
id="root"></div></body></html>)
�
回答完毕

下面是config的配置

{
  "hardware": "LX06",
  "account": "17xxxxxxxx",
  "password": "xxxxxxxxx",
  "openai_key": "sk-qxxxxxxxxxxx",
  "cookie": "",
  "mi_did": "xxxxxxxx",
  "use_command": false,
  "mute_xiaoai": true,
  "verbose": false,
  "bot": "chatgptapi",
  "enable_edge_tts": true,
  "edge_tts_voice": "zh-CN-XiaoxiaoNeural",
  "prompt": "请用100字以内回答",
  "keyword": ["请问"],
  "change_prompt_keyword": ["更改提示词"],
  "start_conversation": "开始对话",
  "end_conversation": "结束对话",
  "stream": true,
  "proxy": "",
  "gpt_options": {},
  "bing_cookie_path": "",
  "bing_cookies": {},
  "api_base": "https://openai.xxx.xxx",
  "deployment_id": "",
  "localhost": true
}

我用的是这个项目配置的api,实测其他应用是可以正常请求的。 https://github.com/songquanpeng/one-api

哥,你这使用one api的地址,最后到底成功了没?

VectorZhao commented 1 year ago

没有成功,

可以确定其他支持配置base url的应用都可以正常调用自建的one api

zhjnerv commented 1 year ago

好吧,谢谢回复。

VectorZhao commented 10 months ago

好吧,谢谢回复。 参考一下

{
"hardware": "LX06",
"account": "1xxxxxxxxa",
"password": "xxxxxxxxx",
"openai_key": "sk-qVaxxxxxxxxxxxx",
"cookie": "",
"mi_did": "x",xxxxxxxx
"use_command": false,
"mute_xiaoai": true,
"verbose": false,
"bot": "chatgptapi",
"enable_edge_tts": true,
"edge_tts_voice": "zh-CN-XiaoxiaoNeural",
"prompt": "你是家庭智能音箱语音助手,可以解答任何问题,每次询问你问题时,请用100字以内回答",
"keyword": ["请问"],
"change_prompt_keyword": ["更改提示词"],
"start_conversation": "开始对话",
"end_conversation": "结束对话",
"stream": false,
"proxy": "",
"gpt_options": {
"model": "gpt-4"
},
"api_base": "https://api.xxx.xxx/v1",
"deployment_id": "",
"localhost": true
}