Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin(tool): 新增tool插件 #663

Merged
merged 11 commits into from Apr 4, 2023
Merged

plugin(tool): 新增tool插件 #663

merged 11 commits into from Apr 4, 2023

Conversation

goldfishh
Copy link
Contributor

@goldfishh goldfishh commented Mar 28, 2023

插件描述

一个能让chatgpt联网,搜索,数字运算的插件,将赋予强大且丰富的扩展能力
使用该插件需在触发机器人回复条件时,在对话内容前加$tool

本插件所有工具同步存放至专用仓库:chatgpt-tool-hub

使用说明

使用该插件后将默认使用4个工具, 无需额外配置长期生效:

1. python_repl

python解释器,使用它来解释执行python指令

2. requests

往往用来获取某个网站具体内容

3. terminal

在你运行的电脑里执行shell命令

4. meteo-weather

回答你有关天气的询问, 本工具使用了meteo open api

注:该工具需提供时间,地点信息,且获取的数据不一定准确

使用本插件对话(prompt)技巧

1. 有指引的询问

例如:

2. 使用搜索引擎工具

  • 如果有搜索工具就能让chatgpt获取到你的未传达清楚的上下文信息,chatgpt不知道你的地理位置,现在时间等,所以不可能给你正确回答

其他工具

除上述以外还有其他工具,比如搜索联网、数学运算、百科、新闻需要获取api-key,
由于这些工具使用方法暂时还在整理中,如果你不熟悉请不要尝试使用这些工具

config.json 配置说明

一个例子
{
  "tools": ["wikipedia"],
  "kwargs": {
      "top_k_results": 2
  }
}

不创建该文件也能使用本tool

  • tools:本插件初始化时加载的工具, 目前可选集:["wikipedia", "wolfram-alpha", "google-search", "news-api"]
  • kwargs:工具执行时的配置,一般在这里存放api-key

备注

  • 虽然我会有意加入一些限制,但请不要使用本插件做危害他人的事情,请提前了解清楚某些内容是否会违反相关规定,建议提前做好过滤
  • 未来一段时间我会实现一些有意思的工具,比如stable diffusion 中文prompt翻译、cv方向的模型推理,欢迎有想法的朋友关注,一起扩展这个项目

@goldfishh goldfishh force-pushed the master branch 2 times, most recently from 56590bb to 04fad2a Compare March 30, 2023 01:10
logger.error(str(e))

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

@lanvent lanvent Mar 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里需要改e_context['context'].content,将它做为新的问题。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前表述有误,要让chatgpt来处理你更改后的query,需使用以下写法

e_context['context'].content = "请你随机用一种聊天风格,提醒用户:如果想重置tool插件,reset之后不要加任何字符"
e_context.action = EventAction.BREAK

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我没仔细看插件具体实现,这样 e_context['reply']需要更改吗?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果是交付给chatgpt处理就不用改reply,它查询完会覆盖reply。

@zwssunny
Copy link
Contributor

建议拆成几个插件,功能太复杂不是好事,而且有些工具比较危险

@goldfishh
Copy link
Contributor Author

建议拆成几个插件,功能太复杂不是好事,而且有些工具比较危险

谢谢你的建议,这个tool插件是tool执行引擎,使用哪个tool可以个性化定制,而且多个tool同时运行是有必要的,之后欢迎使用tool插件体验多个tool联动的特性。
对于工具的危险性,我会有意识的微调各个tool的执行过程,但是无法避免使用工具者强行做出危险行为。
我觉得不是工具危险,而是工具使用者的行为危险。水果刀也是危险的不是吗?

@sleikang
Copy link

  • 使用python查询今天日期

这个插件是不是不是调用当前项目的机器人,插件依赖库里面自己使用了自己的机器人?因为我自己新增了HttpChatGPT调用网页版,api太费钱了,结果调用插件直接报错,是不是没有调用我本身的机器人插件
[WARNING][2023-03-31 10:22:39][before_sleep.py:65] - Retrying chatgpt_tool_hub.models.chatgpt.chatgpt.ChatOpenAI.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: You exceeded your current quota, please check your plan and billing details..
[WARNING][2023-03-31 10:22:43][before_sleep.py:65] - Retrying chatgpt_tool_hub.models.chatgpt.chatgpt.ChatOpenAI.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: You exceeded your current quota, please check your plan and billing details..
You exceeded your current quota, please check your plan and billing details.

@goldfishh
Copy link
Contributor Author

goldfishh commented Mar 31, 2023 via email

@sleikang
Copy link

你好这个错误应该是你api_key欠费了使用tool插件会走我这边的接口调用逻辑,正常会比项目的多一倍用于tool调优输出,请知悉在 2023年3月31日,10:30,sleikang @.> 写道: 使用python查询今天日期 这个插件是不是不是调用当前项目的机器人,插件依赖库里面自己使用了自己的机器人?因为我自己新增了HttpChatGPT调用网页版,api太费钱了,结果调用插件直接报错,是不是没有调用我本身的机器人插件 [WARNING][2023-03-31 10:22:39][before_sleep.py:65] - Retrying chatgpt_tool_hub.models.chatgpt.chatgpt.ChatOpenAI.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: You exceeded your current quota, please check your plan and billing details.. [WARNING][2023-03-31 10:22:43][before_sleep.py:65] - Retrying chatgpt_tool_hub.models.chatgpt.chatgpt.ChatOpenAI.completion_with_retry.._completion_with_retry in 4.0 seconds as it raised RateLimitError: You exceeded your current quota, please check your plan and billing details.. You exceeded your current quota, please check your plan and billing details. —Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.>

嗯嗯 我通过修改你源码调用机器人的位置解决了这个问题
image

@lanvent lanvent merged commit eca3695 into zhayujie:master Apr 4, 2023
@6vision
Copy link
Collaborator

6vision commented Apr 5, 2023

使用$tool 查询天气,会出现由于api密钥无效,无法查询的回复!
使用$tool 查询日期,会出现没有执行tool,直接使用gpt查询的情况

@goldfishh
Copy link
Contributor Author

你好,感谢提出问题。
我不清楚你使用tool插件的上下文,所以无法针对性的理解问题。
目前天气tool使用的是公开meteo接口,使用该接口构建参数较复杂,如经纬度,起止时间等,需要很强的prompt支撑,目前我在不断调优
其实有其他更优质使用性更高的实现方式,不过大部分需要主动申请key,这会带来一定使用成本
另一个没有触发tool问题,我觉得你可以暗示下某个工具可以做到这件事

@nagaki09
Copy link

nagaki09 commented Apr 6, 2023

image
请问ji教程中的这段代码加在哪里?

@theLastWinner
Copy link

你好,感谢提出问题。 我不清楚你使用tool插件的上下文,所以无法针对性的理解问题。 目前天气tool使用的是公开meteo接口,使用该接口构建参数较复杂,如经纬度,起止时间等,需要很强的prompt支撑,目前我在不断调优 其实有其他更优质使用性更高的实现方式,不过大部分需要主动申请key,这会带来一定使用成本 另一个没有触发tool问题,我觉得你可以暗示下某个工具可以做到这件事

@goldfishh 你好,使用之后,有时候会出现链接超时情况,报错如下:
[WARNING][2023-04-07 14:52:07][before_sleep.py:65] - Retrying chatgpt_tool_hub.models.chatgpt.chatgpt.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised Timeout: Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=12).
请问是否有调用系统配置的proxy,还是需要怎么搞?

@yiyi0724
Copy link

yiyi0724 commented Apr 10, 2023

为什么我执行的$tool都只有input没有output,例如:$tool 查询2023.4.10 厦门未来七天的天气情况。他给出的结果是:
[bot] the response to the original input question in chineseThought: Do I need to use a tool? Yes
Action: Meteo Weather
Action Input: 查询2023年4月10日厦门未来七天的天气情况

@6vision
Copy link
Collaborator

6vision commented Apr 10, 2023

你好,感谢提出问题。 我不清楚你使用tool插件的上下文,所以无法针对性的理解问题。 目前天气tool使用的是公开meteo接口,使用该接口构建参数较复杂,如经纬度,起止时间等,需要很强的prompt支撑,目前我在不断调优 其实有其他更优质使用性更高的实现方式,不过大部分需要主动申请key,这会带来一定使用成本 另一个没有触发tool问题,我觉得你可以暗示下某个工具可以做到这件事

@goldfishh 你好,使用之后,有时候会出现链接超时情况,报错如下: [WARNING][2023-04-07 14:52:07][before_sleep.py:65] - Retrying chatgpt_tool_hub.models.chatgpt.chatgpt.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised Timeout: Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=12). 请问是否有调用系统配置的proxy,还是需要怎么搞?

你使用的应该给是openai赠送免费额度的api吧,速度太慢了,我换了收费的key,这个问题就没有了

@theLastWinner
Copy link

你好,感谢提出问题。 我不清楚你使用tool插件的上下文,所以无法针对性的理解问题。 目前天气tool使用的是公开meteo接口,使用该接口构建参数较复杂,如经纬度,起止时间等,需要很强的prompt支撑,目前我在不断调优 其实有其他更优质使用性更高的实现方式,不过大部分需要主动申请key,这会带来一定使用成本 另一个没有触发tool问题,我觉得你可以暗示下某个工具可以做到这件事

@goldfishh 你好,使用之后,有时候会出现链接超时情况,报错如下: [WARNING][2023-04-07 14:52:07][before_sleep.py:65] - Retrying chatgpt_tool_hub.models.chatgpt.chatgpt.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised Timeout: Request timed out: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=12). 请问是否有调用系统配置的proxy,还是需要怎么搞?

你使用的应该给是openai赠送免费额度的api吧,速度太慢了,我换了收费的key,这个问题就没有了

@6vision 好的,还有20天才过期。到时再切换为付费的key

@2755346859
Copy link

我使用$tool 用谷歌查的命令,日志输出看到了许多链接的查询结果,但到最后返回如下
[INFO][2023-06-24 07:55:51][base.py:177] - 执行Tool: url-get中...
[INFO][2023-06-24 07:55:52][wechat_channel.py:183] - [WX] sendMsg=Reply(type=TEXT, content=[bot] 受think_depth限制,系统强制终止了LLM-OS)

@kokojacket
Copy link

请问docker compose下如何用环境变量的写法,添加tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants