Compare commits

..

11 Commits

Author SHA1 Message Date
lanvent
78332d882b Update source.json 2023-04-13 21:34:04 +08:00
lanvent
2dfbc840b3 chore: save model args as a dict 2023-04-13 20:44:08 +08:00
lanvent
0b4bf15163 Update nixpacks.toml 2023-04-13 20:08:53 +08:00
lanvent
2989249e4b chore: add calc_tokens method on session 2023-04-13 20:06:33 +08:00
lanvent
9cef559a05 feat: support receive_message event 2023-04-13 10:50:18 +08:00
zhayujie
47fe16c92a Merge pull request #818 from goldfishh/master
plugin(tool): 新增morning-news tool
2023-04-12 23:09:43 +08:00
goldfishh
36b5c821ff plugin(tool): 新增morning-news tool 2023-04-12 22:23:00 +08:00
lanvent
82ec440b45 banwords: support reply filter 2023-04-12 20:16:21 +08:00
JS00000
88f4a45cae 微信公众号语音输入支持 (#808) 2023-04-12 15:10:51 +08:00
lanvent
28bd917c9f Update config.py 2023-04-11 19:01:40 +08:00
zhayujie
0eb1b94300 docs: update README.md 2023-04-11 00:23:43 +08:00
23 changed files with 171 additions and 87 deletions

View File

@@ -7,18 +7,17 @@
- [x] **文本对话:** 接收私聊及群组中的微信消息使用ChatGPT生成回复内容完成自动回复
- [x] **规则定制化:** 支持私聊中按指定规则触发自动回复,支持对群组设置自动回复白名单
- [x] **多账号** 支持多微信账号同时运行
- [x] **图片生成:** 支持根据描述生成图片,并自动发送至个人聊天或群聊
- [x] **图片生成** 支持根据描述生成图片,支持图片修复
- [x] **上下文记忆**:支持多轮对话记忆,且为每个好友维护独立的上下会话
- [x] **语音识别:** 支持接收和处理语音消息,通过文字或语音回复
- [x] **插件化:** 支持个性化功能插件,提供角色扮演、文字冒险游戏等预设插件
- [x] **插件化:** 支持个性化插件,提供角色扮演、文字冒险、与操作系统交互、访问网络数据等能力
> 目前支持微信和微信个人号部署,欢迎接入更多应用,参考[`Terminal`代码](https://github.com/zhayujie/chatgpt-on-wechat/blob/master/channel/terminal/terminal_channel.py)实现接收和发送消息逻辑即可接入。
> 目前支持微信和微信公众号部署,欢迎接入更多应用,参考 [Terminal代码](https://github.com/zhayujie/chatgpt-on-wechat/blob/master/channel/terminal/terminal_channel.py)实现接收和发送消息逻辑即可接入。 同时欢迎增加新的插件,参考 [插件说明文档](https://github.com/zhayujie/chatgpt-on-wechat/tree/master/plugins)。
快速部署:
>
>[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/qApznZ?referralCode=RC3znh)
**一键部署:**
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/qApznZ?referralCode=RC3znh)
# 更新日志
@@ -217,6 +216,6 @@ FAQs <https://github.com/zhayujie/chatgpt-on-wechat/wiki/FAQs>
## 联系
欢迎提交PR、Issues以及Star支持一下。程序运行遇到问题优先查看 [常见问题列表](https://github.com/zhayujie/chatgpt-on-wechat/wiki/FAQs) ,其次前往 [Issues](https://github.com/zhayujie/chatgpt-on-wechat/issues) 中搜索若无相似问题可创建Issue或加微信 eijuyahz 交流。
欢迎提交PR、Issues以及Star支持一下。程序运行遇到问题优先查看 [常见问题列表](https://github.com/zhayujie/chatgpt-on-wechat/wiki/FAQs) ,其次前往 [Issues](https://github.com/zhayujie/chatgpt-on-wechat/issues) 中搜索。如果你想了解更多项目细节并与开发者们交流更多关于AI技术的实践欢迎加入星球:
<a href="https://public.zsxq.com/groups/88885848842852.html"><img width="360" src="./docs/images/planet.jpg"></a>

1
app.py
View File

@@ -15,6 +15,7 @@ def sigterm_handler_wrap(_signo):
conf().save_user_datas()
if callable(old_handler): # check old_handler
return old_handler(_signo, _stack_frame)
sys.exit(0)
signal.signal(_signo, func)
def run():

View File

@@ -28,6 +28,16 @@ class ChatGPTBot(Bot,OpenAIImage):
self.tb4chatgpt = TokenBucket(conf().get('rate_limit_chatgpt', 20))
self.sessions = SessionManager(ChatGPTSession, model= conf().get("model") or "gpt-3.5-turbo")
self.args ={
"model": conf().get("model") or "gpt-3.5-turbo", # 对话模型的名称
"temperature":conf().get('temperature', 0.9), # 值在[0,1]之间,越大表示回复越具有不确定性
# "max_tokens":4096, # 回复最大的字符数
"top_p":1,
"frequency_penalty":conf().get('frequency_penalty', 0.0), # [-2,2]之间,该值越大则更倾向于产生不同的内容
"presence_penalty":conf().get('presence_penalty', 0.0), # [-2,2]之间,该值越大则更倾向于产生不同的内容
"request_timeout": conf().get('request_timeout', None), # 请求超时时间openai接口默认设置为600对于难问题一般需要较长时间
"timeout": conf().get('request_timeout', None), #重试超时时间,在这个时间内,将会自动重试
}
def reply(self, query, context=None):
# acquire reply content
@@ -58,7 +68,7 @@ class ChatGPTBot(Bot,OpenAIImage):
# # reply in stream
# return self.reply_text_stream(query, new_query, session_id)
reply_content = self.reply_text(session, session_id, api_key, 0)
reply_content = self.reply_text(session, api_key)
logger.debug("[CHATGPT] new_query={}, session_id={}, reply_cont={}, completion_tokens={}".format(session.messages, session_id, reply_content["content"], reply_content["completion_tokens"]))
if reply_content['completion_tokens'] == 0 and len(reply_content['content']) > 0:
reply = Reply(ReplyType.ERROR, reply_content['content'])
@@ -82,19 +92,7 @@ class ChatGPTBot(Bot,OpenAIImage):
reply = Reply(ReplyType.ERROR, 'Bot不支持处理{}类型的消息'.format(context.type))
return reply
def compose_args(self):
return {
"model": conf().get("model") or "gpt-3.5-turbo", # 对话模型的名称
"temperature":conf().get('temperature', 0.9), # 值在[0,1]之间,越大表示回复越具有不确定性
# "max_tokens":4096, # 回复最大的字符数
"top_p":1,
"frequency_penalty":conf().get('frequency_penalty', 0.0), # [-2,2]之间,该值越大则更倾向于产生不同的内容
"presence_penalty":conf().get('presence_penalty', 0.0), # [-2,2]之间,该值越大则更倾向于产生不同的内容
"request_timeout": conf().get('request_timeout', None), # 请求超时时间openai接口默认设置为600对于难问题一般需要较长时间
"timeout": conf().get('request_timeout', None), #重试超时时间,在这个时间内,将会自动重试
}
def reply_text(self, session:ChatGPTSession, session_id, api_key, retry_count=0) -> dict:
def reply_text(self, session:ChatGPTSession, api_key=None, retry_count=0) -> dict:
'''
call openai's ChatCompletion to get the answer
:param session: a conversation session
@@ -107,7 +105,7 @@ class ChatGPTBot(Bot,OpenAIImage):
raise openai.error.RateLimitError("RateLimitError: rate limit exceeded")
# if api_key == None, the default openai.api_key will be used
response = openai.ChatCompletion.create(
api_key=api_key, messages=session.messages, **self.compose_args()
api_key=api_key, messages=session.messages, **self.args
)
# logger.info("[ChatGPT] reply={}, total_tokens={}".format(response.choices[0]['message']['content'], response["usage"]["total_tokens"]))
return {"total_tokens": response["usage"]["total_tokens"],
@@ -133,11 +131,11 @@ class ChatGPTBot(Bot,OpenAIImage):
else:
logger.warn("[CHATGPT] Exception: {}".format(e))
need_retry = False
self.sessions.clear_session(session_id)
self.sessions.clear_session(session.session_id)
if need_retry:
logger.warn("[CHATGPT] 第{}次重试".format(retry_count+1))
return self.reply_text(session, session_id, api_key, retry_count+1)
return self.reply_text(session, api_key, retry_count+1)
else:
return result
@@ -147,10 +145,4 @@ class AzureChatGPTBot(ChatGPTBot):
super().__init__()
openai.api_type = "azure"
openai.api_version = "2023-03-15-preview"
def compose_args(self):
args = super().compose_args()
args["deployment_id"] = conf().get("azure_deployment_id")
#args["engine"] = args["model"]
#del(args["model"])
return args
self.args["deployment_id"] = conf().get("azure_deployment_id")

View File

@@ -17,7 +17,7 @@ class ChatGPTSession(Session):
def discard_exceeding(self, max_tokens, cur_tokens= None):
precise = True
try:
cur_tokens = num_tokens_from_messages(self.messages, self.model)
cur_tokens = self.calc_tokens()
except Exception as e:
precise = False
if cur_tokens is None:
@@ -29,7 +29,7 @@ class ChatGPTSession(Session):
elif len(self.messages) == 2 and self.messages[1]["role"] == "assistant":
self.messages.pop(1)
if precise:
cur_tokens = num_tokens_from_messages(self.messages, self.model)
cur_tokens = self.calc_tokens()
else:
cur_tokens = cur_tokens - max_tokens
break
@@ -40,11 +40,14 @@ class ChatGPTSession(Session):
logger.debug("max_tokens={}, total_tokens={}, len(messages)={}".format(max_tokens, cur_tokens, len(self.messages)))
break
if precise:
cur_tokens = num_tokens_from_messages(self.messages, self.model)
cur_tokens = self.calc_tokens()
else:
cur_tokens = cur_tokens - max_tokens
return cur_tokens
def calc_tokens(self):
return num_tokens_from_messages(self.messages, self.model)
# refer to https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
def num_tokens_from_messages(messages, model):

View File

@@ -26,6 +26,17 @@ class OpenAIBot(Bot, OpenAIImage):
openai.proxy = proxy
self.sessions = SessionManager(OpenAISession, model= conf().get("model") or "text-davinci-003")
self.args = {
"model": conf().get("model") or "text-davinci-003", # 对话模型的名称
"temperature":conf().get('temperature', 0.9), # 值在[0,1]之间,越大表示回复越具有不确定性
"max_tokens":1200, # 回复最大的字符数
"top_p":1,
"frequency_penalty":conf().get('frequency_penalty', 0.0), # [-2,2]之间,该值越大则更倾向于产生不同的内容
"presence_penalty":conf().get('presence_penalty', 0.0), # [-2,2]之间,该值越大则更倾向于产生不同的内容
"request_timeout": conf().get('request_timeout', None), # 请求超时时间openai接口默认设置为600对于难问题一般需要较长时间
"timeout": conf().get('request_timeout', None), #重试超时时间,在这个时间内,将会自动重试
"stop":["\n\n\n"]
}
def reply(self, query, context=None):
# acquire reply content
@@ -42,11 +53,9 @@ class OpenAIBot(Bot, OpenAIImage):
reply = Reply(ReplyType.INFO, '所有人记忆已清除')
else:
session = self.sessions.session_query(query, session_id)
new_query = str(session)
logger.debug("[OPEN_AI] session query={}".format(new_query))
total_tokens, completion_tokens, reply_content = self.reply_text(new_query, session_id, 0)
logger.debug("[OPEN_AI] new_query={}, session_id={}, reply_cont={}, completion_tokens={}".format(new_query, session_id, reply_content, completion_tokens))
result = self.reply_text(session)
total_tokens, completion_tokens, reply_content = result['total_tokens'], result['completion_tokens'], result['content']
logger.debug("[OPEN_AI] new_query={}, session_id={}, reply_cont={}, completion_tokens={}".format(str(session), session_id, reply_content, completion_tokens))
if total_tokens == 0 :
reply = Reply(ReplyType.ERROR, reply_content)
@@ -63,47 +72,42 @@ class OpenAIBot(Bot, OpenAIImage):
reply = Reply(ReplyType.ERROR, retstring)
return reply
def reply_text(self, query, session_id, retry_count=0):
def reply_text(self, session:OpenAISession, retry_count=0):
try:
response = openai.Completion.create(
model= conf().get("model") or "text-davinci-003", # 对话模型的名称
prompt=query,
temperature=0.9, # 值在[0,1]之间,越大表示回复越具有不确定性
max_tokens=1200, # 回复最大的字符数
top_p=1,
frequency_penalty=0.0, # [-2,2]之间,该值越大则更倾向于产生不同的内容
presence_penalty=0.0, # [-2,2]之间,该值越大则更倾向于产生不同的内容
stop=["\n\n\n"]
prompt=str(session), **self.args
)
res_content = response.choices[0]['text'].strip().replace('<|endoftext|>', '')
total_tokens = response["usage"]["total_tokens"]
completion_tokens = response["usage"]["completion_tokens"]
logger.info("[OPEN_AI] reply={}".format(res_content))
return total_tokens, completion_tokens, res_content
return {"total_tokens": total_tokens,
"completion_tokens": completion_tokens,
"content": res_content}
except Exception as e:
need_retry = retry_count < 2
result = [0,0,"我现在有点累了,等会再来吧"]
result = {"completion_tokens": 0, "content": "我现在有点累了,等会再来吧"}
if isinstance(e, openai.error.RateLimitError):
logger.warn("[OPEN_AI] RateLimitError: {}".format(e))
result[2] = "提问太快啦,请休息一下再问我吧"
result['content'] = "提问太快啦,请休息一下再问我吧"
if need_retry:
time.sleep(5)
elif isinstance(e, openai.error.Timeout):
logger.warn("[OPEN_AI] Timeout: {}".format(e))
result[2] = "我没有收到你的消息"
result['content'] = "我没有收到你的消息"
if need_retry:
time.sleep(5)
elif isinstance(e, openai.error.APIConnectionError):
logger.warn("[OPEN_AI] APIConnectionError: {}".format(e))
need_retry = False
result[2] = "我连接不到你的网络"
result['content'] = "我连接不到你的网络"
else:
logger.warn("[OPEN_AI] Exception: {}".format(e))
need_retry = False
self.sessions.clear_session(session_id)
self.sessions.clear_session(session.session_id)
if need_retry:
logger.warn("[OPEN_AI] 第{}次重试".format(retry_count+1))
return self.reply_text(query, session_id, retry_count+1)
return self.reply_text(session, retry_count+1)
else:
return result

View File

@@ -29,7 +29,7 @@ class OpenAISession(Session):
def discard_exceeding(self, max_tokens, cur_tokens= None):
precise = True
try:
cur_tokens = num_tokens_from_string(str(self), self.model)
cur_tokens = self.calc_tokens()
except Exception as e:
precise = False
if cur_tokens is None:
@@ -41,7 +41,7 @@ class OpenAISession(Session):
elif len(self.messages) == 1 and self.messages[0]["role"] == "assistant":
self.messages.pop(0)
if precise:
cur_tokens = num_tokens_from_string(str(self), self.model)
cur_tokens = self.calc_tokens()
else:
cur_tokens = len(str(self))
break
@@ -52,11 +52,13 @@ class OpenAISession(Session):
logger.debug("max_tokens={}, total_tokens={}, len(conversation)={}".format(max_tokens, cur_tokens, len(self.messages)))
break
if precise:
cur_tokens = num_tokens_from_string(str(self), self.model)
cur_tokens = self.calc_tokens()
else:
cur_tokens = len(str(self))
return cur_tokens
def calc_tokens(self):
return num_tokens_from_string(str(self), self.model)
# refer to https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
def num_tokens_from_string(string: str, model: str) -> int:

View File

@@ -31,6 +31,8 @@ class Session(object):
def discard_exceeding(self, max_tokens=None, cur_tokens=None):
raise NotImplementedError
def calc_tokens(self):
raise NotImplementedError
class SessionManager(object):

View File

@@ -48,9 +48,6 @@ class ChatChannel(Channel):
if first_in: # context首次传入时receiver是None根据类型设置receiver
config = conf()
cmsg = context['msg']
if cmsg.from_user_id == self.user_id and not config.get('trigger_by_self', True):
logger.debug("[WX]self message skipped")
return None
if context.get("isgroup", False):
group_name = cmsg.other_user_nickname
group_id = cmsg.other_user_id
@@ -69,6 +66,13 @@ class ChatChannel(Channel):
else:
context['session_id'] = cmsg.other_user_id
context['receiver'] = cmsg.other_user_id
e_context = PluginManager().emit_event(EventContext(Event.ON_RECEIVE_MESSAGE, {'channel': self, 'context': context}))
context = e_context['context']
if e_context.is_pass() or context is None:
return context
if cmsg.from_user_id == self.user_id and not config.get('trigger_by_self', True):
logger.debug("[WX]self message skipped")
return None
# 消息内容匹配过程并处理content
if ctype == ContextType.TEXT:

View File

@@ -45,8 +45,11 @@ sudo iptables-save > /etc/iptables/rules.v4
## 私有api_key
公共api有访问频率限制免费账号每分钟最多20次ChatGPT的API调用这在服务多人的时候会遇到问题。因此这里多加了一个设置私有api_key的功能。目前通过godcmd插件的命令来设置私有api_key。
## 语音输入
利用微信自带的语音识别功能,提供语音输入能力。需要在公众号管理页面的“设置与开发”->“接口权限”页面开启“接收语音识别结果”。
## 测试范围
目前在`RoboStyle`这个公众号上进行了测试(基于[wechatmp-stable分支](https://github.com/JS00000/chatgpt-on-wechat/tree/wechatmp-stable),而[master分支](https://github.com/zhayujie/chatgpt-on-wechat)含有最新功能,但是稳定性有待测试)感兴趣的可以关注并体验。开启了godcmd, Banwords, role, dungeon, finish这五个插件其他的插件还没有测试。百度的接口暂未测试。语音对话没有测试。图片直接以链接形式回复没有临时素材上传接口的权限
目前在`RoboStyle`这个公众号上进行了测试基于[wechatmp分支](https://github.com/JS00000/chatgpt-on-wechat/tree/wechatmp)感兴趣的可以关注并体验。开启了godcmd, Banwords, role, dungeon, finish这五个插件其他的插件还没有测试。百度的接口暂未测试。语音对话没有测试。图片直接以链接形式回复没有临时素材上传接口的权限
## TODO
* 服务号交互完善

View File

@@ -21,7 +21,7 @@ class Query():
webData = web.data()
# logger.debug("[wechatmp] Receive request:\n" + webData.decode("utf-8"))
wechatmp_msg = receive.parse_xml(webData)
if wechatmp_msg.msg_type == 'text':
if wechatmp_msg.msg_type == 'text' or wechatmp_msg.msg_type == 'voice':
from_user = wechatmp_msg.from_user_id
message = wechatmp_msg.content.decode("utf-8")
message_id = wechatmp_msg.msg_id

View File

@@ -22,7 +22,7 @@ class Query():
webData = web.data()
logger.debug("[wechatmp] Receive request:\n" + webData.decode("utf-8"))
wechatmp_msg = receive.parse_xml(webData)
if wechatmp_msg.msg_type == 'text':
if wechatmp_msg.msg_type == 'text' or wechatmp_msg.msg_type == 'voice':
from_user = wechatmp_msg.from_user_id
to_user = wechatmp_msg.to_user_id
message = wechatmp_msg.content.decode("utf-8")

View File

@@ -54,7 +54,7 @@ available_setting = {
"group_speech_recognition": False, # 是否开启群组语音识别
"voice_reply_voice": False, # 是否使用语音回复语音需要设置对应语音合成引擎的api key
"always_reply_voice": False, # 是否一直使用语音回复
"voice_to_text": "openai", # 语音识别引擎支持openai,google,azure
"voice_to_text": "openai", # 语音识别引擎支持openai,baidu,google,azure
"text_to_voice": "baidu", # 语音合成引擎支持baidu,google,pytts(offline),azure
# baidu 语音api配置 使用百度语音识别和语音合成时需要

BIN
docs/images/planet.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@@ -2,6 +2,6 @@ providers = ['python']
[phases.setup]
nixPkgs = ['python310']
cmds = ['apt-get update','apt-get install -y --no-install-recommends ffmpeg espeak']
cmds = ['apt-get update','apt-get install -y --no-install-recommends ffmpeg espeak','python -m venv /opt/venv && . /opt/venv/bin/activate && pip install -r requirements-optional.txt']
[start]
cmd = "python ./app.py"

View File

@@ -1,9 +1,27 @@
## 插件描述
简易的敏感词插件,暂不支持分词,请自行导入词库到插件文件夹中的`banwords.txt`,每行一个词,一个参考词库是[1](https://github.com/cjh0613/tencent-sensitive-words/blob/main/sensitive_words_lines.txt)。
`config.json`中能够填写默认的处理行为,目前行为有:
使用前将`config.json.template`复制为`config.json`,并自行配置。
目前插件对消息的默认处理行为有如下两种:
- `ignore` : 无视这条消息。
- `replace` : 将消息中的敏感词替换成"*",并回复违规。
```json
"action": "replace",
"reply_filter": true,
"reply_action": "ignore"
```
在以上配置项中:
- `action`: 对用户消息的默认处理行为
- `reply_filter`: 是否对ChatGPT的回复也进行敏感词过滤
- `reply_action`: 如果开启了回复过滤,对回复的默认处理行为
## 致谢
搜索功能实现来自https://github.com/toolgood/ToolGood.Words

View File

@@ -36,6 +36,9 @@ class Banwords(Plugin):
words.append(word)
self.searchr.SetKeywords(words)
self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context
if conf.get("reply_filter",True):
self.handlers[Event.ON_DECORATE_REPLY] = self.on_decorate_reply
self.reply_action = conf.get("reply_action","ignore")
logger.info("[Banwords] inited")
except Exception as e:
logger.warn("[Banwords] init failed, ignore or see https://github.com/zhayujie/chatgpt-on-wechat/tree/master/plugins/banwords .")
@@ -53,7 +56,7 @@ class Banwords(Plugin):
if self.action == "ignore":
f = self.searchr.FindFirst(content)
if f:
logger.info("Banwords: %s" % f["Keyword"])
logger.info("[Banwords] %s in message" % f["Keyword"])
e_context.action = EventAction.BREAK_PASS
return
elif self.action == "replace":
@@ -63,5 +66,26 @@ class Banwords(Plugin):
e_context.action = EventAction.BREAK_PASS
return
def on_decorate_reply(self, e_context: EventContext):
if e_context['reply'].type not in [ReplyType.TEXT]:
return
reply = e_context['reply']
content = reply.content
if self.reply_action == "ignore":
f = self.searchr.FindFirst(content)
if f:
logger.info("[Banwords] %s in reply" % f["Keyword"])
e_context['reply'] = None
e_context.action = EventAction.BREAK_PASS
return
elif self.reply_action == "replace":
if self.searchr.ContainsAny(content):
reply = Reply(ReplyType.INFO, "已替换回复中的敏感词: \n"+self.searchr.Replace(content))
e_context['reply'] = reply
e_context.action = EventAction.CONTINUE
return
def get_help_text(self, **kwargs):
return Banwords.desc

View File

@@ -1,3 +1,5 @@
{
"action": "ignore"
"action": "replace",
"reply_filter": true,
"reply_action": "ignore"
}

View File

@@ -4,7 +4,10 @@ from enum import Enum
class Event(Enum):
# ON_RECEIVE_MESSAGE = 1 # 收到消息
ON_RECEIVE_MESSAGE = 1 # 收到消息
"""
e_context = { "channel": 消息channel, "context" : 本次消息的context}
"""
ON_HANDLE_CONTEXT = 2 # 处理消息前
"""

View File

@@ -7,6 +7,10 @@
"replicate": {
"url": "https://github.com/lanvent/plugin_replicate.git",
"desc": "利用replicate api画图的插件"
},
"summary": {
"url": "https://github.com/lanvent/plugin_summary.git",
"desc": "总结聊天记录的插件"
}
}
}

View File

@@ -1,6 +1,6 @@
## 插件描述
一个能让chatgpt联网搜索数字运算的插件将赋予强大且丰富的扩展能力
使用该插件需在触发机器人回复条件时,在对话内容前加$tool
使用该插件需在机器人回复你的前提下,在对话内容前加$tool;仅输入$tool将返回tool插件帮助信息用于测试插件是否加载成功
### 本插件所有工具同步存放至专用仓库:[chatgpt-tool-hub](https://github.com/goldfishh/chatgpt-tool-hub)
@@ -9,15 +9,19 @@
### 1. python
###### python解释器使用它来解释执行python指令可以配合你想要chatgpt生成的代码输出结果或执行事务
### 2. requests
### 2. url-get
###### 往往用来获取某个网站具体内容,结果可能会被反爬策略影响
### 3. terminal
###### 在你运行的电脑里执行shell命令可以配合你想要chatgpt生成的代码使用给予自然语言控制手段
> terminal调优记录https://github.com/zhayujie/chatgpt-on-wechat/issues/776#issue-1659347640
### 4. meteo-weather
###### 回答你有关天气的询问, 需要获取时间、地点上下文信息,本工具使用了[meteo open api](https://open-meteo.com/)
注:该工具需提供时间,地点信息,获取的数据不保证准确性
注:该工具需要较高的对话技巧,不保证你问的任何问题均能得到满意的回复
> meteo调优记录https://github.com/zhayujie/chatgpt-on-wechat/issues/776#issuecomment-1500771334
## 使用本插件对话prompt技巧
### 1. 有指引的询问
@@ -37,12 +41,20 @@
### 6. news *
###### 从全球 80,000 多个信息源中获取当前和历史新闻文章
### 7. bing-search *
### 7. morning-news *
###### 每日60秒早报每天凌晨一点更新本工具使用了[alapi-每日60秒早报](https://alapi.cn/api/view/93)
> 该tool每天返回内容相同
### 8. bing-search *
###### bing搜索引擎从此你不用再烦恼搜索要用哪些关键词
### 8. wolfram-alpha *
### 9. wolfram-alpha *
###### 知识搜索引擎、科学问答系统,常用于专业学科计算
### 10. google-search *
###### google搜索引擎申请流程较bing-search繁琐
###### 注1带*工具需要获取api-key才能使用部分工具需要外网支持
#### [申请方法](https://github.com/goldfishh/chatgpt-tool-hub/blob/master/docs/apply_optional_tool.md)
@@ -50,17 +62,19 @@
###### 默认工具无需配置,其它工具需手动配置,一个例子:
```json
{
"tools": ["wikipedia"],
"tools": ["wikipedia"], // 填入你想用到的额外工具名
"kwargs": {
"top_k_results": 2,
"no_default": false,
"model_name": "gpt-3.5-turbo"
"request_timeout": 60, // openai接口超时时间
"no_default": false, // 是否不使用默认的4个工具
"OPTIONAL_API_NAME": "OPTIONAL_API_KEY" // 带*工具需要申请api-key在这里填入api_name参考前述`申请方法`
}
}
```
config.json文件非必须未创建仍可使用本tool
- `tools`:本插件初始化时加载的工具, 目前可选集:["wikipedia", "wolfram-alpha", "bing-search", "google-search", "news"]其中后4个工具需要申请服务api
- `kwargs`工具执行时的配置一般在这里存放api-key或环境配置
config.json文件非必须未创建仍可使用本tool;带*工具需在kwargs填入对应api-key键值对
- `tools`:本插件初始化时加载的工具, 目前可选集:["wikipedia", "wolfram-alpha", "bing-search", "google-search", "news", "morning-news"] & 默认工具除wikipedia工具之外均需要申请api-key
- `kwargs`:工具执行时的配置,一般在这里存放**api-key**,或环境配置
- `request_timeout`: 访问openai接口的超时时间默认与wechat-on-chatgpt配置一致可单独配置
- `no_default`: 用于配置默认加载4个工具的行为如果为true则仅使用tools列表工具不加载默认工具
- `top_k_results`: 控制所有有关搜索的工具返回条目数数字越高则参考信息越多但无用信息可能干扰判断该值一般为2
- `model_name`: 用于控制tool插件底层使用的llm模型目前暂未测试3.5以外的模型,一般保持默认
@@ -69,4 +83,6 @@
## 备注
- 强烈建议申请搜索工具搭配使用推荐bing-search
- 虽然我会有意加入一些限制,但请不要使用本插件做危害他人的事情,请提前了解清楚某些内容是否会违反相关规定,建议提前做好过滤
- 未来一段时间我会实现一些有意思的工具比如stable diffusion 中文prompt翻译、cv方向的模型推理欢迎有想法的朋友关注一起扩展这个项目
- 如有本插件问题请将debug设置为true无上下文重新问一遍如仍有问题请访问[chatgpt-tool-hub](https://github.com/goldfishh/chatgpt-tool-hub)建个issue将日志贴进去我无法处理不能复现的问题
- 欢迎 star & 宣传有能力请提pr

View File

@@ -1,5 +1,5 @@
{
"tools": ["python", "requests", "terminal", "meteo-weather"],
"tools": ["python", "url-get", "terminal", "meteo-weather"],
"kwargs": {
"top_k_results": 2,
"no_default": false,

View File

@@ -121,6 +121,7 @@ class Tool(Plugin):
return {
"openai_api_key": conf().get("open_ai_api_key", ""),
"proxy": conf().get("proxy", ""),
"request_timeout": conf().get("request_timeout", 60),
# note: 目前tool暂未对其他模型测试但这里仍对配置来源做了优先级区分一般插件配置可覆盖全局配置
"model_name": tool_model_name if tool_model_name else conf().get("model", "gpt-3.5-turbo"),
"no_default": kwargs.get("no_default", False),
@@ -136,6 +137,12 @@ class Tool(Plugin):
"searx_host": kwargs.get("searx_host", ""),
# for wolfram-alpha tool
"wolfram_alpha_appid": kwargs.get("wolfram_alpha_appid", ""),
# for morning-news tool
"zaobao_api_key": kwargs.get("zaobao_api_key", ""),
# for visual_dl tool
"cuda_device": kwargs.get("cuda_device", "cpu"),
# for browser tool
"phantomjs_exec_path": kwargs.get("phantomjs_exec_path", ""),
}
def _filter_tool_list(self, tool_list: list):

View File

@@ -21,4 +21,4 @@ web.py
# chatgpt-tool-hub plugin
--extra-index-url https://pypi.python.org/simple
chatgpt_tool_hub>=0.3.7
chatgpt_tool_hub>=0.3.9