此仓库不再维护,请前往Chat-API.
若报错,请先将EdgeGPT,BingImageCreator更新到最新版本.
Bing Chat服务端,通过WebSocket/WebAPI实现通讯.
- 语言: Python3.8+.
- 包: fastapi,uvicorn,asyncio,python-multipart,EdgeGPT,BingImageCreator.
- 其他: New Bing账户.
- 监听地址和端口分别在第17行和第18行.
- Proxy在第19行.
- Cookie文件路径在第20行.
- 浏览器安装Cookie-Editor扩展.
- 在https://www.bing.com/chat页面中点击扩展.
- 点击扩展右下角的Export,将复制的内容粘贴到Cookie文件.
名称 | 必填 | 中文名 | 说明 |
---|---|---|---|
token | 否 | 令牌 | 当请求WebAPI时,填则为连续对话,不填则为新对话,值可在响应中获取 |
style | 是 | 风格 | balanced代表平衡,creative代表创造,precise代表精确 |
question | 是 | 问题 |
提示: WebSocket发送需JSON格式.
名称 | 中文名 | 说明 |
---|---|---|
code | 状态码 | |
message | 消息 | |
data | 数据 | |
answer | 回答 | |
urls | 链接 | |
done | 完成 | 部分传输是否完成,当为流传输时存在 |
reset | 重置 | 下次对话是否被重置(code为500时也会被重置) |
token | 令牌 | 用于连续对话,当请求WebAPI时存在 |
等待Bing Chat响应完后返回.
连接/ws.
{"code": 200, "message": "success", "data": {"answer": "您好,这是必应。", "urls":[{"title": "The New Bing - Learn More", "url": "https://www.bing.com/new"}], "reset": false}}
- 请求方式: GET/POST.
- 请求地址: /api.
{"code": 200, "message": "success", "data": {"answer": "您好,这是必应。", "urls":[{"title": "The New Bing - Learn More", "url": "https://www.bing.com/new"}], "reset": false, "token": "7953d67b-eac2-457e-a2ee-fedc8ba53599"}}
一部分一部分返回.
当部分传输完成时,将会返回整体,url才会有值,done改为true,reset显示为真实值(部分传输过程中无论下次是否被重置都显示为false).
WebSocket连接/ws_stream.
{"code": 200, "message": "success", "data": {"answer": "您。", "urls": [], "done": false, "reset": false}}
{"code": 200, "message": "success", "data": {"answer": "好", "urls": [], "done": false, "reset": false}}
{"code": 200, "message": "success", "data": {"answer": ",", "urls": [], "done": false, "reset": false}}
{"code": 200, "message": "success", "data": {"answer": "这。", "urls": [], "done": false, "reset": false}}
{"code": 200, "message": "success", "data": {"answer": "是", "urls": [], "done": false, "reset": false}}
{"code": 200, "message": "success", "data": {"answer": "必应", "urls": [], "done": false, "reset": false}}
{"code": 200, "message": "success", "data": {"answer": "。", "urls": [], "done": false, "reset": false}}
{"code": 200, "message": "success", "data": {"answer": "您好,这是必应。", "urls": [{"title": "The New Bing - Learn More", "url": "https://www.bing.com/new"}], "done": true, "reset": false}}
- 请求方式: GET/POST.
- 请求地址: /api_stream.
data: {"code": 200, "message": "success", "data": {"answer": "您。", "urls": [], "done": false, "reset": false, "token": "7953d67b-eac2-457e-a2ee-fedc8ba53599"}}
data: {"code": 200, "message": "success", "data": {"answer": "好", "urls": [], "done": false, "reset": false, "token": "7953d67b-eac2-457e-a2ee-fedc8ba53599"}}
data: {"code": 200, "message": "success", "data": {"answer": ",", "urls": [], "done": false, "reset": false, "token": "7953d67b-eac2-457e-a2ee-fedc8ba53599"}}
data: {"code": 200, "message": "success", "data": {"answer": "这。", "urls": [], "done": false, "reset": false, "token": "7953d67b-eac2-457e-a2ee-fedc8ba53599"}}
data: {"code": 200, "message": "success", "data": {"answer": "是", "urls": [], "done": false, "reset": false, "token": "7953d67b-eac2-457e-a2ee-fedc8ba53599"}}
data: {"code": 200, "message": "success", "data": {"answer": "必应", "urls": [], "done": false, "reset": false, "token": "7953d67b-eac2-457e-a2ee-fedc8ba53599"}}
data: {"code": 200, "message": "success", "data": {"answer": "。", "urls": [], "done": false, "reset": false, "token": "7953d67b-eac2-457e-a2ee-fedc8ba53599"}}
data: {"code": 200, "message": "success", "data": {"answer": "您好,这是必应。", "urls": [{"title": "The New Bing - Learn More", "url": "https://www.bing.com/new"}], "done": true, "reset": false, "token": "7953d67b-eac2-457e-a2ee-fedc8ba53599"}}
- 方式: GET/POST.
- 网址: /image.
- 参数:
名称 | 必填 | 中文名 | 说明 |
---|---|---|---|
keyword | 是 | 关键词 | 仅支持英文 |
- 格式: JSON.
- 参数:
名称 | 中文名 | 说明 |
---|---|---|
code | 状态码 | |
message | 消息 | |
data | 数据 | 网址 |
- 示例:
{"code": 200, "message": "success", "data": ["https://tse2.mm.bing.net/th/id/OIG.gZ22nCCQkj48ydKsjZKa", "https://tse2.mm.bing.net/th/id/OIG.rAYVVytOqj.ajgCh2ZtZ", "https://tse3.mm.bing.net/th/id/OIG.X8tmgTvvlIwtvSiFyHSE", "https://tse2.mm.bing.net/th/id/OIG.10fmeQUY9GO.wNV5FjzI"]}
- 页面写的有点丑,有能力的大神,可以pull request一下,如果你有的example也可以提交.
- 搭建好建议不要对外开放,因为目前Bing Chat24小时内有次数限制.
- 至于反应快慢的问题,要看回答文本的长度,如果文本长度过长,回复时间会比较长.
- 关于整体传输和流传输,整体传输由于要等待Bing完全响应才能开始传输,所以时间要久一点。流传输会先返回一部分,所以看起来比较快,但其实最终的完成时间都是一样的.
- 连续对话问题:websocket是默认支持连续对话的。对于WebAPI来说,如果需要进行连续对话,首先需要在第一次请求时获取token,然后在后续请求中带上token,就可以实现连续对话了.