赞
踩
本文环境为ubuntu18.04+python3.8
EdgeGPT版本为10.6
bot-on-anything版本为1.1.0
由于bot-on-anything 1.1.0版本不适用于EdgeGPT,所以对bot-on-anything进行了二次开发。二次开发的代码已经上传到csdn了,等审核通过后会发在评论区
二次开发代码包:https://download.csdn.net/download/weixin_43433778/87885491
1、提问后回复等待时间较长。
2、长回复会导致报错
1、打开edge注册账号
2、连接vpn后打开edge,点击右侧快捷工具栏里的new bing图标
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OO4rS4eQ-1686287186158)(C:\Users\Lenovo\Desktop\本地搭建new bing\1686191247522.png)]
3、点击立即聊天,即可使用new bing。
系统:ubuntu 18.04
1、安装python3.11环境
sudo apt install python3.8
3、安装pip
sudo apt install python3.8-distutils \\安装pip依赖
wget https://bootstrap.pypa.io/get-pip.py \\下载 get-pip.py 脚本
sudo python3.8 get-pip.py \\运行pip安装脚本
3、安装selenium
pip install -U selenium
1、使用官网安装命令
python3.11 -m pip install EdgeGPT --upgrade
2、测试是否安装成功
python3.11 -m EdgeGPT.EdgeGPT -h
成功回显帮助列表即为成功
1、edge浏览器安装插件Cookie Editor
2、在new bing页面打开Cookie Editor,并导出cookie为json格式
3、回到系统桌面,创建名为cookie.json的文件,并将导出的cookie粘贴进文件,关闭保存文件。
1、输入命令 python3.8 -m EdgeGPT.EdgeGPT --cookie-file '/home/edgegpt/Desktop/cookie.json' --locale zh-CN
查看是否可以正常对话。
2、以下是参数列表
options:
-h, --help 查看帮助
--enter-once 似乎是开启学习模式?增加该参数后会将后续输入输出进行保存和学习
--search-result 似乎是开启查询模式?但是好像开启与否对结果影响并不大
--no-stream 禁用文本流输出。不建议使用该参数,会报错。大概率是因为返回数据超过限制
--rich 应该是是否使用rich库的参数。对返回数据进行美观修饰,但是没什么太大用处
--proxy PROXY 设置代理。Proxy URL (e.g. socks5://127.0.0.1:1080)
--wss-link WSS_LINK 设置wss连接。WSS URL(e.g. wss://sydney.bing.com/sydney/ChatHub)
--style {creative,balanced,precise} 设置回答风格{创新型,平衡型,精确型}
--prompt PROMPT 设置一个prompt启动,感觉没什么用。prompt to start with
--cookie-file COOKIE_FILE 设置cookie文件路径,必须参数。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)
3、常用的启动命令
python3.8 -m EdgeGPT.EdgeGPT --style creative --cookie-file '/home/edgegpt/Desktop/cookie.json' --locale zh-CN \\以创新模式启动
python3.8 -m EdgeGPT.EdgeGPT --style balanced --cookie-file '/home/edgegpt/Desktop/cookie.json' --locale zh-CN \\以平衡模式启动
python3.8 -m EdgeGPT.EdgeGPT --style precise --cookie-file '/home/edgegpt/Desktop/cookie.json' --locale zh-CN \\以精确模式启动
1、在github上下载bot-on-anything
git clone https://github.com/zhayujie/bot-on-anything
2、进入bot-on-anything文件夹后,安装依赖,命令如下
pip3.8 install -r requirements.txt
3、复制config-template.json并创建config.json
cp config-template.json config.json
4、根据官方文档给出的模板对config.json进行配置
5、启动。
python3.8 app.py
1、经过上面的测试,发现正常启动是没有问题的,但是提出问题之后ai回答会报出错误。错误如下
[ERROR][2023-06-08 06:38:33][log.py:47] - [MultiChannel] Start up failed on terminal: cannot import name 'Chatbot' from 'EdgeGPT' (/home/edgegpt/.local/lib/python3.8/site-packages/EdgeGPT/__init__.py) [ERROR][2023-06-08 06:38:33][log.py:45] - App startup failed! [ERROR][2023-06-08 06:38:33][log.py:50] - cannot import name 'Chatbot' from 'EdgeGPT' (/home/edgegpt/.local/lib/python3.8/site-packages/EdgeGPT/__init__.py) Traceback (most recent call last): File "app.py", line 42, in main start_process(channel_type[0], args.config) File "app.py", line 23, in start_process raise e File "app.py", line 20, in start_process channel.startup() File "/home/edgegpt/Desktop/bot-on-anything/channel/terminal/terminal_channel.py", line 21, in startup for res in super().build_reply_content(prompt, context): File "/home/edgegpt/Desktop/bot-on-anything/channel/channel.py", line 31, in build_reply_content return Bridge().fetch_reply_content(query, context) File "/home/edgegpt/Desktop/bot-on-anything/bridge/bridge.py", line 18, in fetch_reply_content return model_factory.create_bot(type).reply(query, context) File "/home/edgegpt/Desktop/bot-on-anything/model/model_factory.py", line 29, in create_bot from model.bing.new_bing_model import BingModel File "/home/edgegpt/Desktop/bot-on-anything/model/bing/new_bing_model.py", line 6, in <module> from EdgeGPT import Chatbot, ConversationStyle ImportError: cannot import name 'Chatbot' from 'EdgeGPT' (/home/edgegpt/.local/lib/python3.8/site-packages/EdgeGPT/__init__.py)
2、经过后续研究,发现是由于EdgeGPT中Chatbot类缺失导致的报错。
3、由于EdgeGPT更新速度较快,bot-on-anything更新较慢,所以猜测可能是bot-on-anything无法兼容新版EdgeGPT导致的
4、查看EdgeGPT项目更新日志,发现导致问题的原因为EdgeGPT在10.0版本进行了重构,所以引用Chatbot类的命令不再是
from EdgeGPT import Chatbot
而是 from EdgeGPT.EdgeGPT import Chatbot
5、先对model/bing下的两个代码进行修改改动如下:
jailbroken_sydney.py:
将
from EdgeGPT import ChatHubRequest, Chatbot, Conversation, ChatHub
改为
from EdgeGPT.EdgeGPT import ChatHubRequest, Chatbot, Conversation, ChatHub
new_bing_model.py:
将
from EdgeGPT import Chatbot, ConversationStyle
改为
from EdgeGPT.EdgeGPT import Chatbot, ConversationStyle
将
from ImageGen import ImageGen
改为
from EdgeGPT.ImageGen import ImageGen
6、修改之后出现新的报错
[ERROR][2023-06-08 07:12:19][log.py:47] - [MultiChannel] Start up failed on terminal: unsupported operand type(s) for |: 'type' and 'NoneType' [ERROR][2023-06-08 07:12:19][log.py:45] - App startup failed! [ERROR][2023-06-08 07:12:19][log.py:50] - unsupported operand type(s) for |: 'type' and 'NoneType' Traceback (most recent call last): File "app.py", line 42, in main start_process(channel_type[0], args.config) File "app.py", line 23, in start_process raise e File "app.py", line 20, in start_process channel.startup() File "/home/edgegpt/Desktop/bot-on-anything/channel/terminal/terminal_channel.py", line 21, in startup for res in super().build_reply_content(prompt, context): File "/home/edgegpt/Desktop/bot-on-anything/channel/channel.py", line 31, in build_reply_content return Bridge().fetch_reply_content(query, context) File "/home/edgegpt/Desktop/bot-on-anything/bridge/bridge.py", line 18, in fetch_reply_content return model_factory.create_bot(type).reply(query, context) File "/home/edgegpt/Desktop/bot-on-anything/model/model_factory.py", line 29, in create_bot from model.bing.new_bing_model import BingModel File "/home/edgegpt/Desktop/bot-on-anything/model/bing/new_bing_model.py", line 9, in <module> from model.bing.jailbroken_sydney import SydneyBot File "/home/edgegpt/Desktop/bot-on-anything/model/bing/jailbroken_sydney.py", line 13, in <module> class SydneyBot(Chatbot): File "/home/edgegpt/Desktop/bot-on-anything/model/bing/jailbroken_sydney.py", line 17, in SydneyBot cookies: dict | None = None, TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
这是一处语法错误,是由于python版本过低导致的,需进行如下修改
将
cookies: dict | None = None
改为
cookies: Optional[dict] = None
剩下的同类错误都是这样修改。
最后把jailbroken_sydney.py中的
from typing import Generator
改为
from typing import Optional, Generator
7、报错如下:
[ERROR][2023-06-08 07:32:24][log.py:47] - [MultiChannel] Start up failed on terminal: module 'EdgeGPT' has no attribute 'CONVERSATION_STYLE_TYPE' [ERROR][2023-06-08 07:32:24][log.py:45] - App startup failed! [ERROR][2023-06-08 07:32:24][log.py:50] - module 'EdgeGPT' has no attribute 'CONVERSATION_STYLE_TYPE' Traceback (most recent call last): File "app.py", line 42, in main start_process(channel_type[0], args.config) File "app.py", line 23, in start_process raise e File "app.py", line 20, in start_process channel.startup() File "/home/edgegpt/Desktop/bot-on-anything/channel/terminal/terminal_channel.py", line 21, in startup for res in super().build_reply_content(prompt, context): File "/home/edgegpt/Desktop/bot-on-anything/channel/channel.py", line 31, in build_reply_content return Bridge().fetch_reply_content(query, context) File "/home/edgegpt/Desktop/bot-on-anything/bridge/bridge.py", line 18, in fetch_reply_content return model_factory.create_bot(type).reply(query, context) File "/home/edgegpt/Desktop/bot-on-anything/model/model_factory.py", line 29, in create_bot from model.bing.new_bing_model import BingModel File "/home/edgegpt/Desktop/bot-on-anything/model/bing/new_bing_model.py", line 9, in <module> from model.bing.jailbroken_sydney import SydneyBot File "/home/edgegpt/Desktop/bot-on-anything/model/bing/jailbroken_sydney.py", line 13, in <module> class SydneyBot(Chatbot): File "/home/edgegpt/Desktop/bot-on-anything/model/bing/jailbroken_sydney.py", line 49, in SydneyBot conversation_style: EdgeGPT.CONVERSATION_STYLE_TYPE = None, AttributeError: module 'EdgeGPT' has no attribute 'CONVERSATION_STYLE_TYPE'
原因:没有导入CONVERSATION_STYLE_TYPE,CONVERSATION_STYLE_TYPE存在于EdgeGPT
中的conversation_style
添加一个新的引用:
from EdgeGPT import conversation_style
并将所有的
EdgeGPT.CONVERSATION_STYLE_TYPE
修改为
conversation_style.CONVERSATION_STYLE_TYPE
8、报错
[ERROR][2023-06-08 17:55:38][log.py:47] - [MultiChannel] Start up failed on terminal: 'type' object is not subscriptable [ERROR][2023-06-08 17:55:38][log.py:45] - App startup failed! [ERROR][2023-06-08 17:55:38][log.py:50] - 'type' object is not subscriptable Traceback (most recent call last): File "app.py", line 42, in main start_process(channel_type[0], args.config) File "app.py", line 23, in start_process raise e File "app.py", line 20, in start_process channel.startup() File "/home/edgegpt/Desktop/bot-on-anything/channel/terminal/terminal_channel.py", line 21, in startup for res in super().build_reply_content(prompt, context): File "/home/edgegpt/Desktop/bot-on-anything/channel/channel.py", line 31, in build_reply_content return Bridge().fetch_reply_content(query, context) File "/home/edgegpt/Desktop/bot-on-anything/bridge/bridge.py", line 18, in fetch_reply_content return model_factory.create_bot(type).reply(query, context) File "/home/edgegpt/Desktop/bot-on-anything/model/model_factory.py", line 29, in create_bot from model.bing.new_bing_model import BingModel File "/home/edgegpt/Desktop/bot-on-anything/model/bing/new_bing_model.py", line 16, in <module> class BingModel(Model): File "/home/edgegpt/Desktop/bot-on-anything/model/bing/new_bing_model.py", line 74, in BingModel def reply(self, query: str, context=None) -> tuple[str, dict]: TypeError: 'type' object is not subscriptable
原因:在 Python 3.8 及更早版本中,类型提示中使用的 tuple[str, dict]
语法是不支持的。要解决这个问题,你可以尝试使用 typing.Tuple
来替代类型提示中的 tuple
修改代码为:
from typing import Tuple
...
def reply(self, query: str, context=None) -> Tuple[str, dict]: ...
9、版本有点太老了,加上语言冲突,要改的东西很多,后续会直接把可以使用的环境包直接发出来,就不在把坑点写出来了。如果不嫌弃EdgeGPT版本过低,建议使用官方推荐版本。
Python 3.8 及更早版本中,类型提示中使用的 tuple[str, dict]
语法是不支持的。要解决这个问题,你可以尝试使用 typing.Tuple
来替代类型提示中的 tuple
修改代码为:
from typing import Tuple
...
def reply(self, query: str, context=None) -> Tuple[str, dict]: ...
9、版本有点太老了,加上语言冲突,要改的东西很多,后续会直接把可以使用的环境包直接发出来,就不在把坑点写出来了。如果不嫌弃EdgeGPT版本过低,建议使用官方推荐版本。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。