소스 검색

plugin tool: big fix

master
goldfishh 1 년 전
부모
커밋
f5f8033d4d
2개의 변경된 파일30개의 추가작업 그리고 8개의 파일을 삭제
  1. +2
    -1
      plugins/tool/README.md
  2. +28
    -7
      plugins/tool/tool.py

+ 2
- 1
plugins/tool/README.md 파일 보기

@@ -1,5 +1,6 @@
## 插件描述
一个能让chatgpt联网,搜索,数字运算的插件,将赋予强大且丰富的扩展能力
一个能让chatgpt联网,搜索,数字运算的插件,将赋予强大且丰富的扩展能力
使用该插件需在对话内容前加$tool
### 本插件所有工具同步存放至专用仓库:[chatgpt-tool-hub](https://github.com/goldfishh/chatgpt-tool-hub)


+ 28
- 7
plugins/tool/tool.py 파일 보기

@@ -5,14 +5,16 @@ from chatgpt_tool_hub.apps import load_app
from chatgpt_tool_hub.apps.app import App

import plugins
from bridge.bridge import Bridge
from bridge.context import ContextType
from bridge.reply import Reply, ReplyType
from common import const
from common.log import logger
from config import conf
from plugins import *


@plugins.register(name="tool", desc="Arming your ChatGPT bot with various tools", version="0.1", author="goldfishh", desire_priority=0)
@plugins.register(name="tool", desc="Arming your ChatGPT bot with various tools", version="0.2", author="goldfishh", desire_priority=0)
class Tool(Plugin):
def __init__(self):
super().__init__()
@@ -32,6 +34,10 @@ class Tool(Plugin):
if e_context['context'].type != ContextType.TEXT:
return

# 暂时不支持未来扩展的bot
if Bridge().get_bot_type("chat") not in (const.CHATGPT, const.OPEN_AI, const.CHATGPTONAZURE):
return

content = e_context['context'].content
content_list = e_context['context'].content.split(maxsplit=1)

@@ -54,24 +60,39 @@ class Tool(Plugin):
elif len(content_list) > 1:
if content_list[1].strip() == "reset":
logger.debug("[tool]: reset config")
self._reset_app()
self.app = self._reset_app()
reply.content = "重置工具成功"
e_context['reply'] = reply
e_context.action = EventAction.BREAK_PASS
return
elif content_list[1].startswith("reset"):
logger.debug("[tool]: remind")
reply.content = "你随机挑一个方式,提醒用户如果想重置tool插件,reset之后不要加任何字符"
reply.content = "请你随机用一种聊天风格,提醒用户:如果想重置tool插件,reset之后不要加任何字符"
e_context['reply'] = reply
e_context.action = EventAction.BREAK
return
logger.debug("[tool]: just-go")

query = content_list[1].strip()

# Don't modify bot name
all_sessions = Bridge().get_bot("chat").sessions
user_session = all_sessions.session_query(query, e_context['context']['session_id'])

# chatgpt-tool-hub will reply you with many tools
# todo: I don't know how to pass someone session into this ask method yet
reply.content = self.app.ask(content_list[1])
logger.debug("[tool]: just-go")
try:
_reply = self.app.ask(content_list[1], user_session)
e_context.action = EventAction.BREAK_PASS
except ValueError as e:
logger.exception(e)
logger.error(str(e))

_reply = "请你随机用一种聊天风格,提醒用户:这个问题你无法处理"
reply.type = ReplyType.ERROR
e_context.action = EventAction.BREAK
reply.content = _reply

e_context['reply'] = reply
e_context.action = EventAction.BREAK_PASS
return

def _read_json(self) -> dict:


Loading…
취소
저장