该项目已存档。由于个人情况,我没有时间来维持此存储库。
边缘GPT
反向工程新版本的bing的聊天功能
英语 - 简体中文-繁体中文 -Español-日本语
设置
设置
安装软件包
python3 -m pip install EdgeGPT --upgrade要求
- Python 3.8+
- Microsoft帐户,可访问https://b**ing.co*m/chat(可选,取决于您的地区)
- 在受支持的国家或地区需要新的Bing(需要中国大陆VPN)
- 硒(用于自动饼干设置)
验证
!!!!可能不再需要!!!
在某些地区,微软使每个人都可以使用聊天功能,因此您可以跳过此步骤。您可以通过尝试在不登录的情况下启动聊天来使用浏览器(用用户代理设置以反射边缘)检查一下。
还发现它可能取决于您的IP地址。例如,如果您尝试从已知属于数据中心范围的IP中访问聊天功能(VSERVERS,根服务器,VPN,Common Proxies,...),则可能需要登录,同时可以从您的家庭IP地址访问该功能。
如果收到以下错误,则可以尝试提供cookie并查看它是否有效,然后:
例外:身份验证失败。您尚未被接受到Beta。
收集饼干
- 获取一个看起来像Microsoft Edge的浏览器。
- A)(轻松)安装最新版本的Microsoft Edge
- b)(提前)您可以使用任何浏览器,并将用户设置为看起来像使用边缘(例如,Mozilla/5.0(Windows NT 10.0; Win64; x64)AppleWebkit/537.36(Khtml,Khtml,喜欢Gecko)Chrome/111.0.0.0.0.0.0.0.0.0.0.0.0.111111.11.11.0.11.0.11.0.0.0.61.0.0.0.0.0.0.61.0.0.0.66.0.0.61.0.0.61.0.b/ed。您可以使用Chrome和Firefox的“用户代理切换器和管理器”(例如“用户代理切换器和管理器”)轻松执行此操作。
- 打开bing.com/chat
- 如果您看到聊天功能,那么您可以继续...
- 安装chrome或firefox的曲奇编辑器扩展程序
- 转到bing.com
- 打开扩展名
- 单击右下方的“导出”,然后“导出为JSON”(这将您的cookie保存到剪贴板))
- 将您的cookie粘贴到文件bing_cookies _*。json中。
- 注意: cookies文件名必须遵循正则示意bing_cookies _*。json ,以便可以通过内部cookie处理机制识别它们
在代码中使用cookie:
cookies = json . loads ( open ( "./path/to/cookies.json" , encoding = "utf-8" ). read ()) # might omit cookies option
bot = await Chatbot . create ( cookies = cookies )如何使用聊天机器人
如何使用聊天机器人
从指令行跑
$ 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)
(中国/美国/英国/挪威对地方的支持得到了增强)
在Python跑
1。聊天机器人类和异步
例如,使用异步来获得最佳体验,例如:
import asyncio , json
from EdgeGPT . EdgeGPT import Chatbot , ConversationStyle
async def main ():
bot = await Chatbot . create () # Passing cookies is "optional", as explained above
response = await bot . ask ( prompt = "Hello world" , conversation_style = ConversationStyle . creative , simplify_response = True )
print ( json . dumps ( response , indent = 2 )) # Returns
"""
{
"text": str,
"author": str,
"sources": list[dict],
"sources_text": str,
"suggestions": list[str],
"messages_left": int
}
"""
await bot . close ()
if __name__ == "__main__" :
asyncio . run ( main ())
2)查询和饼干助手课程
创建一个简单的Bing Chat AI查询(默认使用“精确”对话样式),仅查看主要文本输出,而不是整个API响应:
remeber以特定格式存储您的cookie:bing_cookies _*。json。
from EdgeGPT . EdgeUtils import Query , Cookie
q = Query ( "What are you? Give your answer as Python code" )
print ( q )
存储cookie文件的默认目录是Home/bing_cookies,但您可以通过以下方式更改它:
Cookie . dir_path = Path ( r"..." )或更改要使用的对话样式或cookie文件:
q = Query (
"What are you? Give your answer as Python code" ,
style = "creative" , # or: 'balanced', 'precise'
cookie_file = "./bing_cookies_alternative.json"
)
# Use `help(Query)` to see other supported parameters.快速提取文本输出,代码段,源/参考列表或使用以下属性从响应中提出的后续问题:
q . output # Also: print(q)
q . sources
q . sources_dict
q . suggestions
q . code
q . code_blocks
q . code_block_formatsgiven )获取您指定的原始提示和对话样式:
q . prompt
q . ignore_cookies
q . style
q . simplify_response
q . locale
repr ( q )自导入查询以来进行的访问以前的查询:
Query . index # A list of Query objects; updated dynamically
Query . image_dir_path最后,cookie类支持多个cookie文件,因此,如果您使用命名约定的bing_cookies _*。json创建其他cookie文件,您的查询将自动尝试使用下一个文件(如果您超过了每日的请求的配额)(当前设置为200)。
这是您可以访问的主要属性:
Cookie . current_file_index
Cookie . current_file_path
Cookie . current_data
Cookie . dir_path
Cookie . search_pattern
Cookie . files
Cookie . image_token
Cookie . import_next
Cookie . rotate_cookies
Cookie . ignore_files
Cookie . supplied_files
Cookie . request_count 与Docker一起运行
这假设您当前的工作目录中有一个文件cookies.json
docker run --rm -it -v $( pwd ) /cookies.json:/cookies.json:ro -e COOKIE_FILE= ' /cookies.json ' ghcr.io/acheong08/ EdgeGPT您可以添加任何额外的标志如下
docker run --rm -it -v $( pwd ) /cookies.json:/cookies.json:ro -e COOKIE_FILE= ' /cookies.json ' ghcr.io/acheong08/ EdgeGPT --rich --style creative如何使用图像生成器
如何使用图像生成器
从指令行跑
$ python3 -m ImageGen.ImageGen -h
usage: ImageGen.py [-h] [-U U] [--cookie-file COOKIE_FILE] --prompt PROMPT [--output-dir OUTPUT_DIR] [--quiet] [--asyncio]
optional arguments:
-h, --help show this help message and exit
-U U Auth cookie from browser
--cookie-file COOKIE_FILE
File containing auth cookie
--prompt PROMPT Prompt to generate images for
--output-dir OUTPUT_DIR
Output directory
--quiet Disable pipeline messages
--asyncio Run ImageGen using asyncio在Python跑
1)ImageQuery助手课程
根据简单的提示生成图像,然后下载到当前的工作目录:
from EdgeGPT . EdgeUtils import ImageQuery
q = ImageQuery ( "Meerkats at a garden party in Devon" )
更改本会话中所有未来图像的下载目录:
Query.image_dirpath = Path("./to_another_folder")
2)图像Gen类和异步用于更颗粒的控制
from EdgeGPT . ImageGen import ImageGen
import argparse
import json
async def async_image_gen ( args ) -> None :
async with ImageGenAsync ( args . U , args . quiet ) as image_generator :
images = await image_generator . get_images ( args . prompt )
await image_generator . save_images ( images , output_dir = args . output_dir )
if __name__ == "__main__" :
parser = argparse . ArgumentParser ()
parser . add_argument ( "-U" , help = "Auth cookie from browser" , type = str )
parser . add_argument ( "--cookie-file" , help = "File containing auth cookie" , type = str )
parser . add_argument (
"--prompt" ,
help = "Prompt to generate images for" ,
type = str ,
required = True ,
)
parser . add_argument (
"--output-dir" ,
help = "Output directory" ,
type = str ,
default = "./output" ,
)
parser . add_argument (
"--quiet" , help = "Disable pipeline messages" , action = "store_true"
)
parser . add_argument (
"--asyncio" , help = "Run ImageGen using asyncio" , action = "store_true"
)
args = parser . parse_args ()
# Load auth cookie
with open ( args . cookie_file , encoding = "utf-8" ) as file :
cookie_json = json . load ( file )
for cookie in cookie_json :
if cookie . get ( "name" ) == "_U" :
args . U = cookie . get ( "value" )
break
if args . U is None :
raise Exception ( "Could not find auth cookie" )
if not args . asyncio :
# Create image generator
image_generator = ImageGen ( args . U , args . quiet )
image_generator . save_images (
image_generator . get_images ( args . prompt ),
output_dir = args . output_dir ,
)
else :
asyncio . run ( async_image_gen ( args ))
星历史
星历史
贡献者
贡献者
由于所有贡献的人,该项目的存在。
通过命令行克隆项目: