EdgeGPT - 新版Bing聊天功能逆向工程

在这里插入图片描述

本文翻译整理自:https://github.com/acheong08/EdgeGPT


项目已归档 :由于个人原因,作者无法继续维护此代码库。


一、关于 EdgeGPT

逆向工程实现新版Bing的聊天功能


相关链接资源


关键功能特性

  • 通过逆向工程实现Bing聊天功能
  • 支持命令行和Python API两种调用方式
  • 提供图像生成功能
  • 支持多种对话风格(creative/balanced/precise)
  • 支持cookie认证

二、安装


系统要求

  • Python 3.8+
  • 可访问https://bing.com/chat的微软账户(视地区而定)
  • 位于支持New Bing的国家/地区(中国大陆需VPN)
  • Selenium(用于自动设置cookie)

安装命令

python3 -m pip install EdgeGPT --upgrade

三、认证配置

某些地区可能无需认证即可使用聊天功能。您可以通过浏览器(用户代理设置为Edge)尝试在不登录的情况下发起聊天来验证。

如果收到以下错误,可以尝试提供cookie:
Exception: Authentication failed. You have not been accepted into the beta.


获取Cookie步骤

1、使用类似Microsoft Edge的浏览器:

  • a) 安装最新版Microsoft Edge
  • b) 或设置用户代理为Edge样式

2、访问bing.com/chat
3、安装Cookie编辑器扩展(Chrome版Firefox版
4、访问bing.com
5、打开扩展程序
6、点击"Export"→"Export as JSON"
7、将cookie保存为bing_cookies_*.json文件


代码中使用Cookie

cookies = json.loads(open("./path/to/cookies.json", encoding="utf-8").read())
bot = await Chatbot.create(cookies=cookies)

四、使用方法


1、命令行方式

 $ python3 -m EdgeGPT.EdgeGPT -h

        EdgeGPT - A demo of reverse engineering the Bing GPT chatbot
        Repo: github.com/acheong08/EdgeGPT
        By: Antonio Cheong

        !help for help

        Type !exit to exit

usage: EdgeGPT.py [-h] [--enter-once] [--search-result] [--no-stream] [--rich] [--proxy PROXY] [--wss-link WSS_LINK]
                  [--style {creative,balanced,precise}] [--prompt PROMPT] [--cookie-file COOKIE_FILE]
                  [--history-file HISTORY_FILE] [--locale LOCALE]

options:
  -h, --help            show this help message and exit
  --enter-once
  --search-result
  --no-stream
  --rich
  --proxy PROXY         Proxy URL (e.g. socks5://127.0.0.1:1080)
  --wss-link WSS_LINK   WSS URL(e.g. wss://sydney.bing.com/sydney/ChatHub)
  --style {creative,balanced,precise}
  --prompt PROMPT       prompt to start with
  --cookie-file COOKIE_FILE
                        path to cookie file
  --history-file HISTORY_FILE
                        path to history file
  --locale LOCALE       your locale (e.g. en-US, zh-CN, en-IE, en-GB)

支持参数:

  • --style:设置对话风格(creative/balanced/precise)
  • --cookie-file:指定cookie文件路径
  • --locale:设置地区(如en-US/zh-CN)

2、Python API方式


使用Chatbot
import asyncio, json
from EdgeGPT.EdgeGPT import Chatbot, ConversationStyle

async def main():
    bot = await Chatbot.create()
    response = await bot.ask(prompt="Hello world", conversation_style=ConversationStyle.creative)
    print(json.dumps(response, indent=2))
    await bot.close()

asyncio.run(main())

使用Query辅助类
from EdgeGPT.EdgeUtils import Query

q = Query("What are you? Give your answer as Python code")
print(q.output)  # 获取文本输出
print(q.sources)  # 获取来源
print(q.suggestions)  # 获取建议


3、Docker方式运行

docker run --rm -it -v $(pwd)/cookies.json:/cookies.json:ro -e COOKIE_FILE='/cookies.json' ghcr.io/acheong08/edgegpt

五、图像生成功能


命令行方式

$ python3 -m ImageGen.ImageGen -h

Python API方式

from EdgeGPT.EdgeUtils import ImageQuery

q = ImageQuery("Meerkats at a garden party in Devon")

六、高级控制


使用ImageGen

from EdgeGPT.ImageGen import ImageGen
import json

with open("cookies.json", encoding="utf-8") as file:
    cookies = json.load(file)
    _U = next(cookie["value"] for cookie in cookies if cookie["name"] == "_U")

image_generator = ImageGen(_U)
images = image_generator.get_images("Astronaut riding a horse")
image_generator.save_images(images)

伊织 xAI 2025-04-19(六)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程乐园

请我喝杯伯爵奶茶~!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值