Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.
/ Bing-Chat Public archive

Bing Chat服务端,通过WebSocket/WebAPI实现通讯.

License

Notifications You must be signed in to change notification settings

XiaoXinYo/Bing-Chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

此仓库不再维护,请前往Chat-API.

提示

若报错,请先将EdgeGPT,BingImageCreator更新到最新版本.

介绍

Bing Chat服务端,通过WebSocket/WebAPI实现通讯.

需求

  1. 语言: Python3.8+.
  2. 包: fastapi,uvicorn,asyncio,python-multipart,EdgeGPT,BingImageCreator.
  3. 其他: New Bing账户.

配置

  1. 监听地址和端口分别在第17行和第18行.
  2. Proxy在第19行.
  3. Cookie文件路径在第20行.

Cookie

  1. 浏览器安装Cookie-Editor扩展.
  2. https://www.bing.com/chat页面中点击扩展.
  3. 点击扩展右下角的Export,将复制的内容粘贴到Cookie文件.

参数

请求

名称 必填 中文名 说明
token 令牌 当请求WebAPI时,填则为连续对话,不填则为新对话,值可在响应中获取
style 风格 balanced代表平衡,creative代表创造,precise代表精确
question 问题

提示: WebSocket发送需JSON格式.

响应(JSON)

名称 中文名 说明
code 状态码
message 消息
data 数据
answer 回答
urls 链接
done 完成 部分传输是否完成,当为流传输时存在
reset 重置 下次对话是否被重置(code为500时也会被重置)
token 令牌 用于连续对话,当请求WebAPI时存在

整体传输

等待Bing Chat响应完后返回.

WebSocket

连接/ws.

{"code": 200, "message": "success", "data": {"answer": "您好,这是必应。", "urls":[{"title": "The New Bing - Learn More", "url": "https://www.bing.com/new"}], "reset": false}}

WebAPI

  1. 请求方式: GET/POST.
  2. 请求地址: /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

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}}

WebAPI

  1. 请求方式: GET/POST.
  2. 请求地址: /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"}}

图像生成

请求

  1. 方式: GET/POST.
  2. 网址: /image.
  3. 参数:
名称 必填 中文名 说明
keyword 关键词 仅支持英文

响应

  1. 格式: JSON.
  2. 参数:
名称 中文名 说明
code 状态码
message 消息
data 数据 网址
  1. 示例:
{"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"]}

emm

  1. 页面写的有点丑,有能力的大神,可以pull request一下,如果你有的example也可以提交.
  2. 搭建好建议不要对外开放,因为目前Bing Chat24小时内有次数限制.
  3. 至于反应快慢的问题,要看回答文本的长度,如果文本长度过长,回复时间会比较长.
  4. 关于整体传输和流传输,整体传输由于要等待Bing完全响应才能开始传输,所以时间要久一点。流传输会先返回一部分,所以看起来比较快,但其实最终的完成时间都是一样的.
  5. 连续对话问题:websocket是默认支持连续对话的。对于WebAPI来说,如果需要进行连续对话,首先需要在第一次请求时获取token,然后在后续请求中带上token,就可以实现连续对话了.

About

Bing Chat服务端,通过WebSocket/WebAPI实现通讯.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •