mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-11-05 07:12:02 +08:00
第二次重大更改
This commit is contained in:
+38
-10
@@ -8,7 +8,28 @@ export default sidebar({
|
||||
icon: "blog",
|
||||
prefix: "posts/deploymentTutorial/",
|
||||
link: "posts/deploymentTutorial/",
|
||||
children: "structure",
|
||||
children: [
|
||||
{
|
||||
text: "手动部署(推荐,可以在所有平台上使用)",
|
||||
icon: "support",
|
||||
link: "manual",
|
||||
},
|
||||
{
|
||||
text: "安装器部署(Win)(不推荐,长时间未维护)",
|
||||
icon: "list",
|
||||
link: "auto_app_win",
|
||||
},
|
||||
{
|
||||
text: "Docker部署(仅推荐在Linux上使用)",
|
||||
icon: "list",
|
||||
link: "auto_docker",
|
||||
},
|
||||
{
|
||||
text: "安装器部署(Linux)(不推荐,已经长时间未维护)",
|
||||
icon: "list",
|
||||
link: "auto_app_linux",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
text: "功能介绍",
|
||||
@@ -17,13 +38,6 @@ export default sidebar({
|
||||
link: "posts/functionIntroduction",
|
||||
children: "structure",
|
||||
},
|
||||
{
|
||||
text: "插件使用",
|
||||
icon: "plugin",
|
||||
prefix: "posts/PluginsUse/",
|
||||
link: "posts/PluginsUse/",
|
||||
children: "structure",
|
||||
},
|
||||
{
|
||||
text: "常见报错",
|
||||
icon: "info",
|
||||
@@ -38,11 +52,25 @@ export default sidebar({
|
||||
prefix: "posts/Q&A",
|
||||
children: "structure",
|
||||
},
|
||||
{
|
||||
text: "插件介绍",
|
||||
icon: "plugin",
|
||||
prefix: "posts/pluginsAbout/",
|
||||
link: "posts/pluginsAbout/pluginsIntro",
|
||||
collapsible: true,
|
||||
children: [
|
||||
{
|
||||
text: "插件列表",
|
||||
icon: "list",
|
||||
link: "pluginsList",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
text: "插件开发",
|
||||
icon: "code",
|
||||
icon: "editor",
|
||||
link: "posts/PluginsDevelop",
|
||||
prefix: "posts/PluginsDevelop",
|
||||
prefix: "posts/PluginsDevelop",
|
||||
children: "structure",
|
||||
},
|
||||
],
|
||||
|
||||
@@ -12,8 +12,8 @@ category:
|
||||
index: false
|
||||
---
|
||||
|
||||
> 请先阅读[插件使用页](https://github.com/RockChinQ/QChatGPT/wiki/5-%E6%8F%92%E4%BB%B6%E4%BD%BF%E7%94%A8)
|
||||
> 请先阅读[技术信息页](https://github.com/RockChinQ/QChatGPT/wiki/4-%E6%8A%80%E6%9C%AF%E4%BF%A1%E6%81%AF)
|
||||
> 请先阅读[插件使用页](/posts/pluginsAbout/pluginsIntro)
|
||||
> 请先阅读[技术信息页](/posts/developTutorial/technologyInfo)
|
||||
> 建议先阅读本项目源码,了解项目架构
|
||||
|
||||
> 问题、需求请到仓库issue发起
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
---
|
||||
head:
|
||||
- - meta
|
||||
- name: keywords
|
||||
content: ChatGPT QQ机器人插件,QChatGPT项目插件
|
||||
title: 插件使用
|
||||
icon: blog
|
||||
date: 2023-09-30
|
||||
category:
|
||||
- 插件使用
|
||||
index: false
|
||||
---
|
||||
<AutoCatalog base='/posts/PluginsUse/'/>
|
||||
@@ -12,7 +12,7 @@ category:
|
||||
- 部署教程
|
||||
---
|
||||
:::warning
|
||||
请使用Python 3.9.x以上版本
|
||||
请使用Python 3.9.x以上版本,没有Python的需自行安装,参考[此教程](/posts/deploymentTutorial/yirimiraiAndPythonForManual/pythonInstall.md)
|
||||
:::
|
||||
|
||||
:::info 目录
|
||||
@@ -26,7 +26,7 @@ category:
|
||||
<details>
|
||||
<summary>mirai</summary>
|
||||
|
||||
1. 按照[此教程](https://yiri-mirai.wybxc.cc/tutorials/01/configuration)配置Mirai及mirai-api-http
|
||||
1. 按照[此教程](/posts/deploymentTutorial/yirimiraiANDpythonForManual/yirimirai.md)配置Mirai及mirai-api-http
|
||||
2. 启动mirai-console后,使用`login`命令登录QQ账号,保持mirai-console运行状态
|
||||
3. 在下一步配置主程序时请在config.py中将`msg_source_adapter`设为`yirimirai`
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
---
|
||||
head:
|
||||
- - meta
|
||||
- name: keywords
|
||||
content: Python的安装教程
|
||||
title: 手动部署
|
||||
icon: support
|
||||
order: 3
|
||||
author: Lazy
|
||||
date: 2023-12-18
|
||||
category:
|
||||
- 部署教程
|
||||
---
|
||||
|
||||
## 第一步:安装Python
|
||||
|
||||
打开这个网址,[点我跳转](https://www.python.org/downloads/release/python-3109/)
|
||||
|
||||
翻到最下边,点击这个下载python安装器
|
||||
|
||||

|
||||
|
||||
然后,双击打开你刚才下载的,记得勾选下面的
|
||||
|
||||

|
||||
|
||||
然后,所有项保持默认即可
|
||||
|
||||
## 第二步:检测Python是否安装成功
|
||||
|
||||
按win+R键,输入cmd,回车,在输入python,回车
|
||||
|
||||

|
||||
|
||||
提示如图时,表明安装成功了
|
||||
@@ -0,0 +1,153 @@
|
||||
---
|
||||
head:
|
||||
- - meta
|
||||
- name: keywords
|
||||
content: Yiri-mirai的部署教程
|
||||
title: 手动部署
|
||||
icon: support
|
||||
order: 3
|
||||
author: Lazy
|
||||
date: 2023-12-18
|
||||
category:
|
||||
- 部署教程
|
||||
---
|
||||
|
||||
## 第一步:准备工作
|
||||
|
||||
> 注意:由于网络环境多样复杂,很多步骤中,有可能需要使用网络魔法,懂的都懂
|
||||
|
||||
1. 创建文件夹
|
||||
|
||||
在你的任意盘(D,E,F什么都都可以)里面新建一个文件夹(例如命名qqbot)
|
||||
|
||||

|
||||
|
||||
2. 创建子文件夹
|
||||
|
||||
双击进入刚刚创建的文件夹,分别新建两个文件夹(建议命名保持一致)
|
||||
|
||||

|
||||
|
||||
## 第二步:安装 mirai-console
|
||||
|
||||
在 [mcl-installer 的 releases 页面](https://github.com/iTXTech/mcl-installer/releases)下载对应版本的安装包,找到最新的安装包,即有“Latest”标志的安装包,点击`show all 14 assets`,下载 mcl-installer-X.X.X-windows-amd64.exe,如图,则下载`mcl-installer-1.0.7-windows-amd64.exe`,保存在刚才创建的`mirai文件夹`中
|
||||

|
||||
|
||||

|
||||
|
||||
双击打开,一路回车。然后,你可以看到多出来一些文件。
|
||||
|
||||

|
||||
|
||||
继续点击`mcl.cmd`,看不到文件后缀的,参考这个文章来显示文件后缀名:[如何查看文件后缀](https://jingyan.baidu.com/article/9158e0004c6cbea2541228da.html)
|
||||
|
||||
双击后会显示如下图所示的类似界面,当出现`Enter to continue`时,表明你需要按回车健
|
||||
|
||||

|
||||
当出现上面的一行绿字时,说明安装完成,到这里输入 exit,回车退出
|
||||
|
||||
## 第三步:安装 mirai-api-http
|
||||
|
||||
打开 `mcl.cmd`,输入`mcl --update-package net.mamoe:mirai-api-http --channel stable-v2 --type plugin` ,回车
|
||||
|
||||
再次打开`mcl.cmd`,一路回车,直至退出。
|
||||
|
||||
再打开 mcl.cmd,看到如以下界面,说明成功
|
||||

|
||||
键盘按下`Ctrl+C`,退出。
|
||||
找到mira/config/net.mamoe.mirai-api-http/setting.yml文件,右键用记事本打开
|
||||
|
||||

|
||||
|
||||
把内容全部删掉,换成
|
||||
|
||||
```yml
|
||||
adapters:
|
||||
- ws
|
||||
debug: true
|
||||
enableVerify: true
|
||||
verifyKey: yirimirai
|
||||
singleMode: false
|
||||
cacheSize: 4096
|
||||
adapterSettings:
|
||||
ws:
|
||||
host: localhost
|
||||
port: 8080
|
||||
reservedSyncId: -1
|
||||
```
|
||||
|
||||
再打开 `mcl.cmd`,可以看到输出
|
||||

|
||||
则 mirai-api-http 安装成功。
|
||||
|
||||
## 第四步:配置签名服务
|
||||
|
||||
在这个链接下载qsign一键签名包,点击下载最新的那个zip压缩包,如下图的`qsign-1.2.1-beta-dev-d62ddce-all.zip`【写于2023年12月19日】,[点我跳转下载页面](https://github.com/MrXiaoM/qsign/releases)
|
||||
|
||||

|
||||
|
||||
下载完成后,解压得到如图文件
|
||||
|
||||

|
||||
|
||||
将两个文件复制到mirai文件夹中
|
||||
|
||||

|
||||
|
||||
打开`txlib`文件夹,发现有若干数字命名的文件夹,记录下最大的那个
|
||||
|
||||

|
||||
|
||||
然后,双击运行`mcl.cmd`,稍等一会儿后,当提示`mirai-console started successfully`时,qsign就安装上了
|
||||
|
||||
之后,打开`mirai/config/top.mrxiaom.qsign`下的`config.yml`文件,用记事本打开
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
然后,按下`Ctrl+S`保存
|
||||
|
||||
然后,再次双击运行`mcl.cmd`,可以看到类似提示,如图
|
||||
|
||||

|
||||
|
||||
## 第五步:运行mirai
|
||||
|
||||
到这里,你已经安装并配置成功了,接下来,你就可以登录机器人QQ了
|
||||
|
||||
输入,其中 123456 是替换为你机器人的 QQ 号,67890 替换为你机器人 QQ 的密码
|
||||
|
||||
```bash
|
||||
login 12345 67890
|
||||
```
|
||||
|
||||
然后,可以看到提示
|
||||
|
||||

|
||||
|
||||
把`Captcha link: `后边的链接复制下来,用Chrome或者Edge浏览器打开,按F12打开开发者工具
|
||||
|
||||
点开 `Network`
|
||||
|
||||

|
||||
|
||||
在浏览器中完成验证, 在 `Network` 中找到名为 `cap_union_new_verify` 的请求, 在最下面
|
||||
|
||||

|
||||
|
||||
ticket 后那一坨就是要输入回 mirai 的内容,但不包括首尾的双引号
|
||||
|
||||
**注意**
|
||||
|
||||
- 复制的时候记得删掉引号(`"`, 前后都有一个), 那个不是ticket内容
|
||||
- 速度要快
|
||||
- 注意不要漏字符(没复制完, 后面还有很长)
|
||||
|
||||
把复制下来的东西,粘贴到运行mirai的终端中
|
||||
|
||||

|
||||
|
||||
然后回车,如果运气好的话,会提示你要收验证码,输入yes并回车,之后把验证码输入上去,然后回车即可成功登录了
|
||||
|
||||
如果运气不好,报错code=237了,建议换号
|
||||
@@ -0,0 +1,491 @@
|
||||
---
|
||||
head:
|
||||
- - meta
|
||||
- name: keywords
|
||||
content: QChatGPT插件开发教程
|
||||
title: 插件开发
|
||||
icon: code
|
||||
author: RockChinQ
|
||||
date: 2023-09-30
|
||||
category:
|
||||
- 插件开发
|
||||
index: false
|
||||
---
|
||||
|
||||
> 请先阅读[插件使用页](/posts/pluginsAbout/pluginsIntro)
|
||||
> 请先阅读[技术信息页](https://github.com/RockChinQ/QChatGPT/wiki/4-%E6%8A%80%E6%9C%AF%E4%BF%A1%E6%81%AF)
|
||||
> 建议先阅读本项目源码,了解项目架构
|
||||
|
||||
> 问题、需求请到仓库issue发起
|
||||
> **提问前请先靠自己尝试**
|
||||
:::info 目录
|
||||
[[toc]]
|
||||
:::
|
||||
## 💬简介
|
||||
|
||||
尽管“为一个基于OpenAI API的QQ机器人开发插件支持”这事看起来有点小题大做,但萌生此想法后的几天内好几个人提出了这个需求,最终促使此项目正式支持插件。
|
||||
|
||||
## 🧱实现
|
||||
|
||||
基于`importlib`库加载模块的方法动态加载额外Python程序文件以便实现插件加载,插件均存放在`plugins`文件夹,其中的所有`.py`文件都将被加载(除了所有`__init__.py`)
|
||||
|
||||
## 📚示例代码
|
||||
|
||||
请查看代码目录`tests/plugin_examples`中的插件目录
|
||||
|
||||
## 💻快速开始
|
||||
|
||||
按照文档部署此项目,并使其正常运行。
|
||||
在`plugins`目录下新建目录`hello`,在其中新建空文件`__init__.py`以标记此目录为软件包,继续新建文件`main.py`。
|
||||
|
||||
> 您也可以使用[hello_plugin](https://github.com/RockChinQ/hello_plugin)作为模板直接生成插件代码仓库
|
||||
|
||||
编辑`main.py`输入以下内容:
|
||||
|
||||
```Python
|
||||
from pkg.plugin.models import *
|
||||
from pkg.plugin.host import EventContext, PluginHost
|
||||
|
||||
"""
|
||||
在收到私聊或群聊消息"hello"时,回复"hello, <发送者id>!"或"hello, everyone!"
|
||||
"""
|
||||
|
||||
|
||||
# 注册插件
|
||||
@register(name="Hello", description="hello world", version="0.1", author="RockChinQ")
|
||||
class HelloPlugin(Plugin):
|
||||
|
||||
# 插件加载时触发
|
||||
# plugin_host (pkg.plugin.host.PluginHost) 提供了与主程序交互的一些方法,详细请查看其源码
|
||||
def __init__(self, plugin_host: PluginHost):
|
||||
pass
|
||||
|
||||
# 当收到个人消息时触发
|
||||
@on(PersonNormalMessageReceived)
|
||||
def person_normal_message_received(self, event: EventContext, **kwargs):
|
||||
msg = kwargs['text_message']
|
||||
if msg == "hello": # 如果消息为hello
|
||||
|
||||
# 输出调试信息
|
||||
logging.debug("hello, {}".format(kwargs['sender_id']))
|
||||
|
||||
# 回复消息 "hello, <发送者id>!"
|
||||
event.add_return("reply", ["hello, {}!".format(kwargs['sender_id'])])
|
||||
|
||||
# 阻止该事件默认行为(向接口获取回复)
|
||||
event.prevent_default()
|
||||
|
||||
# 当收到群消息时触发
|
||||
@on(GroupNormalMessageReceived)
|
||||
def group_normal_message_received(self, event: EventContext, **kwargs):
|
||||
msg = kwargs['text_message']
|
||||
if msg == "hello": # 如果消息为hello
|
||||
|
||||
# 输出调试信息
|
||||
logging.debug("hello, {}".format(kwargs['sender_id']))
|
||||
|
||||
# 回复消息 "hello, everyone!"
|
||||
event.add_return("reply", ["hello, everyone!"])
|
||||
|
||||
# 阻止该事件默认行为(向接口获取回复)
|
||||
event.prevent_default()
|
||||
|
||||
# 插件卸载时触发
|
||||
def __del__(self):
|
||||
pass
|
||||
|
||||
```
|
||||
|
||||
此插件将实现:私聊收到`hello`消息时回复`hello, <发送者QQ号>!`,群聊收到`hello`消息时回复`hello, everyone!`
|
||||
|
||||
### 解读此插件程序
|
||||
|
||||
- `import`从`pkg.plugin`引入`models`模块的所有字段(此程序使用了其中的`register函数`、`on函数`、`Plugin类`、`PersonNormalMessageReceived事件`、`GroupNormalMessageReceived事件`)
|
||||
- `@register()`将类`HelloPlugin`标记为一个插件类,声明插件名称为`Hello`以及插件简介、版本、作者
|
||||
- 声明类`HelloPlugin`继承于`Plugin`,此类可以随意命名,插件名称只与`register`调用时的参数有关
|
||||
- 声明此类的`__init__`方法,此方法是可选的,其中的代码将在主程序启动时加载插件的时候被执行
|
||||
- `@on`将方法`person_normal_message_received`标记为一个事件处理器,处理`PersonNormalMessageReceived`(收到私聊消息并在获取OpenAI回复前触发)事件,此方法可以随意命名,绑定的事件只与`on`中的参数有关,更多支持的事件可到`pkg.plugin.models.py`文件中查看或查看下方`API`节
|
||||
- 输出调试信息,程序中可通过`logging`将日志输出到控制台和`qchatgpt.log`文件
|
||||
- 方法内部从参数中取出`text_message`参数,判断是否为`hello`,如果是就将返回值`reply`设置为`["hello, {}!".format(kwargs['sender_id'])]`,接下来调用`event`对象的`prevent_default`方法,阻止原程序默认行为
|
||||
- 每个事件`提供的参数`和`支持的返回值`请查看`pkg.plugin.models`中的每个事件的注释或查看下方`API`节
|
||||
- `event`对象提供的方法请查看`pkg.plugin.host`中的`EventContext`类或查看下方`API`节
|
||||
- 用相似的程序注册`GroupNormalMessageReceived`事件处理群消息
|
||||
|
||||
编写完毕保存后,重新启动主程序,查看到输出中包含以下内容,即为加载成功:
|
||||
|
||||
```
|
||||
[2023-01-16 18:29:47.193] host.py (43) - [INFO] : 加载模块: hello.main
|
||||
[2023-01-16 18:29:47.194] models.py (209) - [INFO] : 插件注册完成: n='Hello', d='hello world', v=0.1, a='RockChinQ' (<class 'plugins.hello.main.HelloPlugin'>)
|
||||
```
|
||||
|
||||
> 建议在`config.py`中设置`logging_level = logging.DEBUG`以便开启调试输出
|
||||
|
||||
## ❗规范(重要)
|
||||
|
||||
- 请每个插件独立一个目录以便管理,建议在Github上创建一个仓库储存单个插件,以便获取和更新
|
||||
- 插件名使用`大驼峰命名法`,如`Hello`、`ExamplePlugin`、`ChineseCommands`等
|
||||
- 一个目录内可以存放多个Python程序文件,以独立出插件的各个功能,便于开发者管理,但不建议在一个目录内注册多个插件
|
||||
- 插件需要的依赖库请在插件目录下的`requirements.txt`中指定,程序从储存库获取此插件时将自动安装依赖
|
||||
|
||||
## 🪝内容函数
|
||||
|
||||
通过[GPT的Function Calling能力](https://platform.openai.com/docs/guides/gpt/function-calling)实现的`内容函数`,这是一种嵌入对话中,由GPT自动调用的函数。
|
||||
|
||||
> 您的插件不一定必须包含内容函数,请先查看内容函数页了解此功能
|
||||
|
||||
<details>
|
||||
<summary>示例:联网插件</summary>
|
||||
|
||||
加载含有联网功能的内容函数的插件[WebwlkrPlugin](https://github.com/RockChinQ/WebwlkrPlugin),向机器人询问在线内容
|
||||
|
||||
```
|
||||
# 控制台输出
|
||||
[2023-07-29 17:37:18.698] message.py (26) - [INFO] : [person_1010553892]发送消息:介绍一下这个项目:https://git...
|
||||
[2023-07-29 17:37:21.292] util.py (67) - [INFO] : message='OpenAI API response' path=https://api.openai.com/v1/chat/completions processing_ms=1902 request_id=941afc13b2e1bba1e7877b92a970cdea response_code=200
|
||||
[2023-07-29 17:37:21.293] chat_completion.py (159) - [INFO] : 执行函数调用: name=Webwlkr-access_the_web, arguments={'url': 'https://github.com/RockChinQ/QChatGPT', 'brief_len': 512}
|
||||
[2023-07-29 17:37:21.848] chat_completion.py (164) - [INFO] : 函数执行完成。
|
||||
```
|
||||
|
||||

|
||||
|
||||
</details>
|
||||
|
||||
### 内容函数编写步骤
|
||||
|
||||
1️⃣ 请先按照上方步骤编写您的插件基础结构,现在请删除(当然你也可以不删,只是为了简洁)上述插件内容的诸个由`@on`装饰的类函数
|
||||
|
||||
<details>
|
||||
<summary>删除后的结构</summary>
|
||||
|
||||
```python
|
||||
from pkg.plugin.models import *
|
||||
from pkg.plugin.host import EventContext, PluginHost
|
||||
|
||||
"""
|
||||
在收到私聊或群聊消息"hello"时,回复"hello, <发送者id>!"或"hello, everyone!"
|
||||
"""
|
||||
|
||||
|
||||
# 注册插件
|
||||
@register(name="Hello", description="hello world", version="0.1", author="RockChinQ")
|
||||
class HelloPlugin(Plugin):
|
||||
|
||||
# 插件加载时触发
|
||||
# plugin_host (pkg.plugin.host.PluginHost) 提供了与主程序交互的一些方法,详细请查看其源码
|
||||
def __init__(self, plugin_host: PluginHost):
|
||||
pass
|
||||
|
||||
# 插件卸载时触发
|
||||
def __del__(self):
|
||||
pass
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
2️⃣ 现在我们将以下函数添加到刚刚删除的函数的位置
|
||||
|
||||
```Python
|
||||
|
||||
# 要添加的函数
|
||||
|
||||
@func(name="access_the_web") # 设置函数名称
|
||||
def _(url: str):
|
||||
"""Call this function to search about the question before you answer any questions.
|
||||
- Do not search through baidu.com at any time.
|
||||
- If you need to search somthing, visit https://www.google.com/search?q=xxx.
|
||||
- If user ask you to open a url (start with http:// or https://), visit it directly.
|
||||
- Summary the plain content result by yourself, DO NOT directly output anything in the result you got.
|
||||
|
||||
Args:
|
||||
url(str): url to visit
|
||||
|
||||
Returns:
|
||||
str: plain text content of the web page
|
||||
"""
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
# 你需要先使用
|
||||
# pip install beautifulsoup4
|
||||
# 安装依赖
|
||||
|
||||
r = requests.get(
|
||||
url,
|
||||
timeout=10,
|
||||
headers={
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.183"
|
||||
}
|
||||
)
|
||||
soup = BeautifulSoup(r.text, 'html.parser')
|
||||
|
||||
s = soup.get_text()
|
||||
|
||||
# 删除多余的空行或仅有\t和空格的行
|
||||
s = re.sub(r'\n\s*\n', '\n', s)
|
||||
|
||||
if len(s) >= 512: # 截取获取到的网页纯文本内容的前512个字
|
||||
return s[:512]
|
||||
|
||||
return s
|
||||
|
||||
```
|
||||
<details>
|
||||
<summary>现在这个文件内容应该是这样</summary>
|
||||
|
||||
```python
|
||||
from pkg.plugin.models import *
|
||||
from pkg.plugin.host import EventContext, PluginHost
|
||||
|
||||
"""
|
||||
在收到私聊或群聊消息"hello"时,回复"hello, <发送者id>!"或"hello, everyone!"
|
||||
"""
|
||||
|
||||
|
||||
# 注册插件
|
||||
@register(name="Hello", description="hello world", version="0.1", author="RockChinQ")
|
||||
class HelloPlugin(Plugin):
|
||||
|
||||
# 插件加载时触发
|
||||
# plugin_host (pkg.plugin.host.PluginHost) 提供了与主程序交互的一些方法,详细请查看其源码
|
||||
def __init__(self, plugin_host: PluginHost):
|
||||
pass
|
||||
|
||||
@func(name="access_the_web")
|
||||
def _(url: str):
|
||||
"""Call this function to search about the question before you answer any questions.
|
||||
- Do not search through baidu.com at any time.
|
||||
- If you need to search somthing, visit https://www.google.com/search?q=xxx.
|
||||
- If user ask you to open a url (start with http:// or https://), visit it directly.
|
||||
- Summary the plain content result by yourself, DO NOT directly output anything in the result you got.
|
||||
|
||||
Args:
|
||||
url(str): url to visit
|
||||
|
||||
Returns:
|
||||
str: plain text content of the web page
|
||||
"""
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
# 你需要先使用
|
||||
# pip install beautifulsoup4
|
||||
# 安装依赖
|
||||
|
||||
r = requests.get(
|
||||
url,
|
||||
timeout=10,
|
||||
headers={
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.183"
|
||||
}
|
||||
)
|
||||
soup = BeautifulSoup(r.text, 'html.parser')
|
||||
|
||||
s = soup.get_text()
|
||||
|
||||
# 删除多余的空行或仅有\t和空格的行
|
||||
s = re.sub(r'\n\s*\n', '\n', s)
|
||||
|
||||
if len(s) >= 512: # 截取获取到的网页纯文本内容的前512个字
|
||||
return s[:512]
|
||||
|
||||
return s
|
||||
|
||||
# 插件卸载时触发
|
||||
def __del__(self):
|
||||
pass
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
#### 请注意:
|
||||
|
||||
- 函数的注释必须严格按照要求的格式进行书写,具体格式请查看[此文档](https://github.com/RockChinQ/CallingGPT/wiki/1.-Function-Format#function-format)
|
||||
- 内容函数和`以@on装饰的行为函数`可以同时存在于同一个插件,并同时受到`switch.json`中的插件开关的控制
|
||||
- 务必确保您使用的模型支持函数调用功能,可以到`config.py`的`completion_api_params`中修改模型,推荐使用`gpt-3.5-turbo-16k`
|
||||
|
||||
3️⃣ 现在您的程序已具备网络访问功能,重启程序,询问机器人有关在线的内容或直接发送文章链接请求其总结。
|
||||
|
||||
- 这仅仅是一个示例,需要更高效的网络访问能力支持插件,请查看[WebwlkrPlugin](https://github.com/RockChinQ/WebwlkrPlugin)
|
||||
|
||||
## 🔒版本要求
|
||||
|
||||
若您的插件对主程序的版本有要求,可以使用以下函数进行断言,若不符合版本,此函数将报错并打断此函数所在的流程:
|
||||
|
||||
```python
|
||||
require_ver("v2.5.1") # 要求最低版本为 v2.5.1
|
||||
```
|
||||
|
||||
```python
|
||||
require_ver("v2.5.1", "v2.6.0") # 要求最低版本为 v2.5.1, 同时要求最高版本为 v2.6.0
|
||||
```
|
||||
|
||||
- 此函数在主程序`v2.5.1`中加入
|
||||
- 此函数声明在`pkg.plugin.models`模块中,在插件示例代码最前方已引入此模块所有内容,故可直接使用
|
||||
|
||||
## 📄API参考
|
||||
|
||||
### 说明
|
||||
|
||||
事件处理函数将会获得一系列参数,可以在`kwargs`中取出。
|
||||
其中`host`参数(`pkg.plugin.host.PluginHost`类的实例)是插件宿主,提供与主程序各个模块交互的一些方法。
|
||||
`event`参数(`pkg.plugin.host.EventContext`类的实例)是事件执行期间的上下文,提供对此次事件执行的一些操作方法。
|
||||
|
||||
事件返回值均为**可选**的,可以通过调用`event.add_return(key: str, ret)`来提交返回值
|
||||
|
||||
### 事件
|
||||
|
||||
所有事件参数均有`host`和`event`,以下仅展示其他参数
|
||||
关于`YiriMirai`支持的消息链组件,请查看 [YiriMirai的文档](https://yiri-mirai.wybxc.cc/docs/basic/message-chain)
|
||||
|
||||
```Python
|
||||
PersonMessageReceived = "person_message_received"
|
||||
"""收到私聊消息时,在判断是否应该响应前触发
|
||||
kwargs:
|
||||
launcher_type: str 发起对象类型(group/person)
|
||||
launcher_id: int 发起对象ID(群号/QQ号)
|
||||
sender_id: int 发送者ID(QQ号)
|
||||
message_chain: mirai.models.message.MessageChain 消息链
|
||||
"""
|
||||
|
||||
GroupMessageReceived = "group_message_received"
|
||||
"""收到群聊消息时,在判断是否应该响应前触发(所有群消息)
|
||||
kwargs:
|
||||
launcher_type: str 发起对象类型(group/person)
|
||||
launcher_id: int 发起对象ID(群号/QQ号)
|
||||
sender_id: int 发送者ID(QQ号)
|
||||
message_chain: mirai.models.message.MessageChain 消息链
|
||||
"""
|
||||
|
||||
PersonNormalMessageReceived = "person_normal_message_received"
|
||||
"""判断为应该处理的私聊普通消息时触发
|
||||
kwargs:
|
||||
launcher_type: str 发起对象类型(group/person)
|
||||
launcher_id: int 发起对象ID(群号/QQ号)
|
||||
sender_id: int 发送者ID(QQ号)
|
||||
text_message: str 消息文本
|
||||
|
||||
returns (optional):
|
||||
alter: str 修改后的消息文本
|
||||
reply: list 回复消息组件列表,元素为YiriMirai支持的消息组件
|
||||
"""
|
||||
|
||||
PersonCommandSent = "person_command_sent"
|
||||
"""判断为应该处理的私聊命令时触发
|
||||
kwargs:
|
||||
launcher_type: str 发起对象类型(group/person)
|
||||
launcher_id: int 发起对象ID(群号/QQ号)
|
||||
sender_id: int 发送者ID(QQ号)
|
||||
command: str 命令
|
||||
params: list[str] 参数列表
|
||||
text_message: str 完整命令文本
|
||||
is_admin: bool 是否为管理员
|
||||
|
||||
returns (optional):
|
||||
alter: str 修改后的完整命令文本
|
||||
reply: list 回复消息组件列表,元素为YiriMirai支持的消息组件
|
||||
"""
|
||||
|
||||
GroupNormalMessageReceived = "group_normal_message_received"
|
||||
"""判断为应该处理的群聊普通消息时触发
|
||||
kwargs:
|
||||
launcher_type: str 发起对象类型(group/person)
|
||||
launcher_id: int 发起对象ID(群号/QQ号)
|
||||
sender_id: int 发送者ID(QQ号)
|
||||
text_message: str 消息文本
|
||||
|
||||
returns (optional):
|
||||
alter: str 修改后的消息文本
|
||||
reply: list 回复消息组件列表,元素为YiriMirai支持的消息组件
|
||||
"""
|
||||
|
||||
GroupCommandSent = "group_command_sent"
|
||||
"""判断为应该处理的群聊命令时触发
|
||||
kwargs:
|
||||
launcher_type: str 发起对象类型(group/person)
|
||||
launcher_id: int 发起对象ID(群号/QQ号)
|
||||
sender_id: int 发送者ID(QQ号)
|
||||
command: str 命令
|
||||
params: list[str] 参数列表
|
||||
text_message: str 完整命令文本
|
||||
is_admin: bool 是否为管理员
|
||||
|
||||
returns (optional):
|
||||
alter: str 修改后的完整命令文本
|
||||
reply: list 回复消息组件列表,元素为YiriMirai支持的消息组件
|
||||
"""
|
||||
|
||||
NormalMessageResponded = "normal_message_responded"
|
||||
"""获取到对普通消息的文字响应时触发
|
||||
kwargs:
|
||||
launcher_type: str 发起对象类型(group/person)
|
||||
launcher_id: int 发起对象ID(群号/QQ号)
|
||||
sender_id: int 发送者ID(QQ号)
|
||||
session: pkg.openai.session.Session 会话对象
|
||||
prefix: str 回复文字消息的前缀
|
||||
response_text: str 响应文本
|
||||
finish_reason: str 响应结束原因
|
||||
|
||||
returns (optional):
|
||||
prefix: str 修改后的回复文字消息的前缀
|
||||
reply: list 替换回复消息组件列表
|
||||
"""
|
||||
|
||||
SessionFirstMessageReceived = "session_first_message_received"
|
||||
"""会话被第一次交互时触发
|
||||
kwargs:
|
||||
session_name: str 会话名称(<launcher_type>_<launcher_id>)
|
||||
session: pkg.openai.session.Session 会话对象
|
||||
default_prompt: str 预设值
|
||||
"""
|
||||
|
||||
SessionExplicitReset = "session_reset"
|
||||
"""会话被用户手动重置时触发,此事件不支持阻止默认行为
|
||||
kwargs:
|
||||
session_name: str 会话名称(<launcher_type>_<launcher_id>)
|
||||
session: pkg.openai.session.Session 会话对象
|
||||
"""
|
||||
|
||||
SessionExpired = "session_expired"
|
||||
"""会话过期时触发
|
||||
kwargs:
|
||||
session_name: str 会话名称(<launcher_type>_<launcher_id>)
|
||||
session: pkg.openai.session.Session 会话对象
|
||||
session_expire_time: int 已设置的会话过期时间(秒)
|
||||
"""
|
||||
|
||||
KeyExceeded = "key_exceeded"
|
||||
"""api-key超额时触发
|
||||
kwargs:
|
||||
key_name: str 超额的api-key名称
|
||||
usage: dict 超额的api-key使用情况
|
||||
exceeded_keys: list[str] 超额的api-key列表
|
||||
"""
|
||||
|
||||
KeySwitched = "key_switched"
|
||||
"""api-key超额切换成功时触发,此事件不支持阻止默认行为
|
||||
kwargs:
|
||||
key_name: str 切换成功的api-key名称
|
||||
key_list: list[str] api-key列表
|
||||
"""
|
||||
|
||||
PromptPreProcessing = "prompt_pre_processing" # 于v2.5.1加入
|
||||
"""每回合调用接口前对prompt进行预处理时触发,此事件不支持阻止默认行为
|
||||
kwargs:
|
||||
session_name: str 会话名称(<launcher_type>_<launcher_id>)
|
||||
default_prompt: list 此session使用的情景预设内容
|
||||
prompt: list 此session现有的prompt内容
|
||||
text_message: str 用户发送的消息文本
|
||||
|
||||
returns (optional):
|
||||
default_prompt: list 修改后的情景预设内容
|
||||
prompt: list 修改后的prompt内容
|
||||
text_message: str 修改后的消息文本
|
||||
"""
|
||||
```
|
||||
|
||||
### host: PluginHost 详解
|
||||
|
||||
提供与主程序各个模块交互的一些方法,具体查看`pkg.plugin.host`中的`PluginHost`类
|
||||
|
||||
### event: EventContext 详解
|
||||
|
||||
提供对此次事件执行的一些操作方法,具体查看`pkg.plugin.host`中的`EventContext`类
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
---
|
||||
head:
|
||||
- - meta
|
||||
- name: keywords
|
||||
content: QChatGPT插件开发教程
|
||||
title: 技术信息
|
||||
icon: code
|
||||
author: RockChinQ
|
||||
date: 2023-09-30
|
||||
category:
|
||||
- 技术信息
|
||||
index: false
|
||||
---
|
||||
以下是QChatGPT实现原理等技术信息,贡献之前请仔细阅读
|
||||
|
||||
> 太久没更了,过时了,建议读源码,~~注释还挺全的~~
|
||||
> 请先阅读OpenAI API的相关文档 https://beta.openai.com/docs/ ,以下信息假定您已了解OpenAI模型的相关特性及其接口的调用方法。
|
||||
|
||||
## 术语
|
||||
|
||||
包含OpenAI API涉及的术语和项目中的概念的命名
|
||||
括号中是程序中相应术语的命名,无括号的为抽象概念
|
||||
|
||||
### 模型(model)
|
||||
|
||||
AI模型,程序调用OpenAI的接口获取的内容均为OpenAI的模型生成的内容。
|
||||
|
||||
### 字符(tokens)
|
||||
|
||||
OpenAI定义的字符,ASCII字符为1 token,其他为2 token。
|
||||
|
||||
### 提示符(prompt)
|
||||
|
||||
i. 调用OpenAI的文字补全模型时的提示语,模型接口会根据提示语返回回复内容。程序底层会将对话内容进行封装生成提示符。调用文字补全模型时的提示符均由`user_name`(默认为`You`,可在配置文件修改)和`bot_name`(默认为`Bot`,可在配置文件修改)标记对话角色以供模型识别,以下是实例:
|
||||
|
||||
```
|
||||
You:今天天气真不错
|
||||
Bot:很高兴你喜欢今天的天气:)
|
||||
You:谢谢你
|
||||
Bot:不客气:)
|
||||
```
|
||||
补全模型调用的程序实现请查看下文`实现`节。
|
||||
|
||||
ii. 调用OpenAI的绘图模型时的提示语,模型会根据提示语进行绘图并返回图片URL。
|
||||
|
||||
### 对象
|
||||
|
||||
程序将单个人或单个QQ群视为一个对象,对象和模型是一次会话中的对话双方。
|
||||
|
||||
### 会话(session)
|
||||
|
||||
会话只对文字补全功能有效,绘图功能无会话概念。每个对象使用同一个会话,会话中仅有对象和模型两个角色,故群内所有的人都将被视为同一个角色与模型进行对话。
|
||||
|
||||
程序获取回复的本质是`文字补全`。
|
||||
由于对话需要实现联系上下文,故程序会将模型与对象的对话历史记录作为`提示符`发送给OpenAI的接口以获取符合前文的回复。
|
||||
而OpenAI的文字补全接口的提示符具有长度限制(默认使用的`text-davinci-003`限制为4096 tokens),
|
||||
所以增加`会话`概念以管理向接口发送的提示符内容。
|
||||
|
||||
会话的存活时间可以在`config.py`中设置,默认为20分钟。会话过期之后会被存入数据库并重置。下一次该对象发起对话时将重启新的会话。
|
||||
|
||||
### 预设值、人格(default_prompt)
|
||||
|
||||
每个会话的预设对话信息,可在`config.py`中设置,程序会在每个会话创建时向提示符写入以下内容:
|
||||
|
||||
```
|
||||
You:<预设信息>
|
||||
Bot:好的
|
||||
```
|
||||
|
||||
## 实现
|
||||
|
||||
### QQ机器人
|
||||
|
||||
> 程序路径:
|
||||
> pkg.qqbot
|
||||
|
||||
- `pkg.qqbot.manager`中的`QQBotManager`实现了接收消息、调用OpenAI模块处理消息、报告审计模块记录使用量等功能,并提供通知管理员、发送消息等方法供其他模块调用。
|
||||
- `pkg.qqbot.filter`提供了敏感词过滤的相关操作。
|
||||
- `pkg.qqbot.process`提供了私聊消息和群聊消息的统一处理逻辑。
|
||||
|
||||
使用mirai及YiriMirai作为Python与QQ交互的框架,详细请见其文档。
|
||||
在启动时会调用YiriMirai的函数以创建一个bot对象,用于程序通过mirai与QQ进行交互,在上层程序调用此bot对象的方法进行消息处理。
|
||||
由于YiriMirai暂时无法关闭机器人,故在热重载前后维持同一个bot对象,这意味着QQ机器人的相关配置(QQ号、适配器等)信息不支持热重载。
|
||||
|
||||
### 数据库
|
||||
|
||||
> 程序路径:
|
||||
> pkg.database
|
||||
|
||||
- `pkg.database.manager`中的`DatabaseManager`封装了诸多调用数据库的方法以供其他模块调用。
|
||||
|
||||
使用SQLite作为数据库,储存所有对象的历史会话信息、api-key的费用情况、api-key的使用量情况。
|
||||
|
||||
### OpenAI交互
|
||||
|
||||
> 程序路径:
|
||||
> pkg.openai
|
||||
|
||||
- `pkg.openai.manager`中的`OpenAIInteract`类封装了OpenAI的文字补全`Completion`API和绘图API供机器人模块调用,并在接口调用成功之后向审计模块报告当前使用的api-key的使用量信息。
|
||||
- `pkg.openai.keymgr`实现了多api-key的管理,其中以`exceeded`变量在运行时记录api-key的超额报错记录,并提供根据超额记录进行的api-key切换功能。
|
||||
- `pkg.openai.pricing`记录各个模型的费用信息,供调用接口时估算费用,费用估算功能不再与api-key的切换挂钩,api-key仅在调用接口报错超额时进行切换。
|
||||
- `pkg.openai.session`中的`Session`进行会话管理。
|
||||
|
||||
### utils模块
|
||||
|
||||
#### context模块
|
||||
|
||||
保存前述模块中的对象,并允许各个模块从此处获取其他模块的对象以调用其方法。
|
||||
|
||||
#### 热重载功能
|
||||
|
||||
> pkg.utils.reloader
|
||||
|
||||
重载前保存context中的所有对象,执行`main.py`中的程序关闭流程,使用`importlib`的`reload`函数重载所有模块(包含配置文件,包含新增的模块),重载后将context恢复,并执行程序启动流程。
|
||||
所有模块都会重新创建对象,但QQ机器人模块中的bot对象不会被重新创建,这是因为YiriMirai提供的shutdown方法无法使用,这意味着`config.py`中关于QQ机器人的配置不支持热重载。
|
||||
|
||||
#### 热更新功能
|
||||
|
||||
> pkg.utils.updater
|
||||
|
||||
使用`dulwich`库执行pull操作拉取远程仓库的最新源码,并进行一次热重载加载最新代码。
|
||||
@@ -0,0 +1,117 @@
|
||||
---
|
||||
head:
|
||||
- - meta
|
||||
- name: keywords
|
||||
content: ChatGPT QQ机器人插件,QChatGPT项目插件
|
||||
title: 插件介绍
|
||||
icon: blog
|
||||
date: 2023-09-30
|
||||
category:
|
||||
- 插件介绍
|
||||
index: false
|
||||
---
|
||||
|
||||
# QChatGPT的插件
|
||||
|
||||
## 插件是什么?
|
||||
|
||||
**插件**,是QChatGPT的扩展模块,分为**行为插件**和**内容函数**两种类型。行为插件由主程序运行中的事件驱动,而内容函数由GPT生成的内容驱动。
|
||||
|
||||
### 行为插件
|
||||
|
||||
1. **事件驱动行为:** 行为插件可以响应运行时发生的事件,如用户发送消息、机器人启动、定时任务触发等。
|
||||
2. **自定义行为:** 通过行为插件,你可以为机器人定义特定的行为,使其在特定条件下执行某些操作,例如自动回复、处理指令等。
|
||||
3. **功能扩展:** 行为插件可以扩展机器人的功能,使其具有更强大的处理能力,例如与外部API交互、数据存储、日志记录等。
|
||||
|
||||
### 内容函数
|
||||
|
||||
> 说白了就是ChatGPT官方插件那种东西
|
||||
|
||||
内容函数是基于[GPT的Function Calling能力](https://platform.openai.com/docs/guides/gpt/function-calling)实现的,这是一种嵌入对话中,由GPT自动调用的函数。
|
||||
|
||||
例如我们为GPT提供一个函数`access_the_web`,并提供其详细的描述以及其参数的描述,那么当我们在与GPT对话时涉及类似以下内容时:
|
||||
|
||||
```
|
||||
Q: 请搜索一下github上有那些QQ机器人项目?
|
||||
Q: 请为我搜索一些不错的云服务商网站?
|
||||
Q:阅读并总结这篇文章:https://zhuanlan.zhihu.com/p/607570830
|
||||
Q:搜一下清远今天天气如何
|
||||
```
|
||||
|
||||
GPT将会回复一个对`access_the_web`的函数调用请求,QChatGPT将自动处理执行该调用,并返回结果给GPT使其生成新的回复。
|
||||
|
||||
当然,函数调用功能不止局限于网络访问,还可以实现图片处理、科学计算、行程规划等需要调用函数的功能,理论上我们可以通过内容函数实现与`ChatGPT Plugins`相同的功能。
|
||||
|
||||
- 您需要使用`v2.5.0`以上的版本才能加载包含内容函数的插件
|
||||
- 您需要同时在`config.py`中的`completion_api_params`中设置`model`为支持函数调用的模型,推荐使用`gpt-3.5-turbo-16k`
|
||||
- 使用此功能可能会造成难以预期的账号余额消耗,请关注
|
||||
- [逆向库插件](https://github.com/RockChinQ/revLibs)现在也支持函数调用了..您可以在完全免费的情况下使用GPT-3.5进行函数调用,若您在主程序配置了内容函数并启用,逆向ChatGPT会自动使用这些函数
|
||||
|
||||
> **QChatGPT的一些不错的内容函数插件**
|
||||
>
|
||||
> [WebwlkrPlugin](https://github.com/RockChinQ/WebwlkrPlugin) - 让机器人能联网!!
|
||||
|
||||
## 插件能干什么?
|
||||
|
||||
- **自定义回复逻辑:** 定义特定关键词或指令的回复方式。
|
||||
- **集成外部服务:** 与外部API交互,获取信息或执行操作。
|
||||
- **数据存储和检索:** 将数据存储在数据库中,并能够检索和更新。
|
||||
- **自动化任务:** 在特定事件触发时执行自动化任务,如定时任务、特定用户消息触发等。
|
||||
- **内容函数调用:** 利用GPT的Function Calling能力执行各种任务,如网络搜索、图片处理等。
|
||||
- **更多……**
|
||||
|
||||
## 插件怎么用?
|
||||
|
||||
### 安装
|
||||
|
||||
> 这里只是给出了插件的基本安装方法,详细需查看各插件文档或咨询其开发者
|
||||
|
||||
#### 储存库克隆(推荐)
|
||||
|
||||
在运行期间,使用管理员账号对机器人私聊发送`!plugin get <Git储存库地址>`即可自动获取源码并安装插件,程序会根据仓库中的`requirements.txt`文件自动安装依赖库
|
||||
|
||||
例如安装`hello_plugin`插件
|
||||
```
|
||||
!plugin get https://github.com/RockChinQ/hello_plugin
|
||||
```
|
||||
|
||||
安装完成后重启程序或使用管理员账号私聊机器人发送`!reload`进行热重载加载插件
|
||||
|
||||
#### 手动安装
|
||||
|
||||
将获取到的插件程序放置到`plugins`目录下,具体使用方式请查看各插件文档或咨询其开发者。
|
||||
|
||||
### 管理
|
||||
|
||||
#### !plugin 命令
|
||||
|
||||
```
|
||||
!plugin 列出所有已安装的插件
|
||||
!plugin get <储存库地址> 从Git储存库安装插件(需要管理员权限)
|
||||
!plugin update all 更新所有插件(需要管理员权限,仅支持从储存库安装的插件)
|
||||
!plugin update <插件名> 更新指定插件
|
||||
!plugin del <插件名> 删除插件(需要管理员权限)
|
||||
!plugin on <插件名> 启用插件(需要管理员权限)
|
||||
!plugin off <插件名> 禁用插件(需要管理员权限)
|
||||
|
||||
!func 列出所有内容函数
|
||||
```
|
||||
|
||||
#### 控制插件执行顺序
|
||||
|
||||
可以通过修改`plugins/settings.json`中`order`字段中每个插件名称的前后顺序,以更改插件**初始化**和**事件执行**顺序
|
||||
|
||||
#### 启用或关闭插件
|
||||
|
||||
无需卸载即可管理插件的开关
|
||||
编辑`plugins`目录下的`switch.json`文件,将相应的插件的`enabled`字段设置为`true/false(开/关)`,之后重启程序或执行热重载即可控制插件开关
|
||||
|
||||
#### 控制全局内容函数开关
|
||||
|
||||
内容函数是基于[GPT的Function Calling能力](https://platform.openai.com/docs/guides/gpt/function-calling)实现的,这是一种嵌入对话中,由GPT自动调用的函数。
|
||||
每个插件可以自行注册内容函数,您可以在`plugins`目录下的`settings.json`中设置`functions`下的`enabled`为`true`或`false`控制这些内容函数的启用或禁用。
|
||||
|
||||
## 如何自定义插件?
|
||||
|
||||
> QChatGPT的插件具有高度的可拓展性,你可以自行编写python代码来实现无限的功能,插件开发方法具体阅读:[插件开发](/posts/PluginsDevelop.html)
|
||||
|
||||
@@ -9,24 +9,42 @@ order: 1
|
||||
author: Lazy
|
||||
date: 2023-09-30
|
||||
category:
|
||||
- 插件使用
|
||||
- 插件介绍
|
||||
---
|
||||
插件列表
|
||||
|
||||
- [WebwlkrPlugin](https://github.com/RockChinQ/WebwlkrPlugin) - 让机器人能联网!!**[点我查看插件使用方法](./plugin_network.md)**
|
||||
|
||||
- [revLibs](https://github.com/RockChinQ/revLibs) - 将ChatGPT网页版、Claude、Bard、Hugging Chat等破解版接入此项目,关于[官方接口和网页版有什么区别](https://github.com/RockChinQ/QChatGPT/wiki/8-%E5%AE%98%E6%96%B9%E6%8E%A5%E5%8F%A3%E3%80%81ChatGPT%E7%BD%91%E9%A1%B5%E7%89%88%E3%80%81ChatGPT-API%E5%8C%BA%E5%88%AB)
|
||||
|
||||
- [Switcher](https://github.com/RockChinQ/Switcher) - 支持通过命令切换使用的模型
|
||||
|
||||
- [hello_plugin](https://github.com/RockChinQ/hello_plugin) - `hello_plugin` 的储存库形式,插件开发模板
|
||||
- [oliverkirk-sudo/chat_voice](https://github.com/oliverkirk-sudo/chat_voice) - 文字转语音输出,支持HuggingFace上的[VITS模型](https://huggingface.co/spaces/Plachta/VITS-Umamusume-voice-synthesizer),azure语音合成,vits本地语音合成,sovits语音合成 **[点我查看插件使用方法](./plugin_network.md)**
|
||||
|
||||
- [oliverkirk-sudo/chat_voice](https://github.com/oliverkirk-sudo/chat_voice) - 文字转语音输出,支持HuggingFace上的[VITS模型](https://huggingface.co/spaces/Plachta/VITS-Umamusume-voice-synthesizer),azure语
|
||||
音合成,vits本地语音合成,sovits语音合成 **[点我查看插件使用方法](./plugin_network.md)**
|
||||
|
||||
- [RockChinQ/WaitYiYan](https://github.com/RockChinQ/WaitYiYan) - 实时获取百度`文心一言`等待列表人数
|
||||
|
||||
- [chordfish-k/QChartGPT_Emoticon_Plugin](https://github.com/chordfish-k/QChartGPT_Emoticon_Plugin) - 使机器人根据回复内容发送表情包
|
||||
|
||||
- [oliverkirk-sudo/ChatPoeBot](https://github.com/oliverkirk-sudo/ChatPoeBot) - 接入[Poe](https://poe.com/)上的机器人
|
||||
|
||||
- [lieyanqzu/WeatherPlugin](https://github.com/lieyanqzu/WeatherPlugin) - 天气查询插件
|
||||
|
||||
- [SysStatPlugin](https://github.com/RockChinQ/SysStatPlugin) - 查看系统状态
|
||||
|
||||
- [oliverkirk-sudo/qchat_system_status](https://github.com/oliverkirk-sudo/qchat_system_status) - 以图片的形式输出系统状态
|
||||
|
||||
- [oliverkirk-sudo/QChatAIPaint](https://github.com/oliverkirk-sudo/QChatAIPaint) - 基于[Holara](https://holara.ai/)的ai绘图插件
|
||||
|
||||
- [oliverkirk-sudo/QChatCodeRunner](https://github.com/oliverkirk-sudo/QChatCodeRunner) - 基于[CodeRunner-Plugin](https://github.com/oliverkirk-sudo/CodeRunner-Plugin)的代码运行与图表生成插件
|
||||
|
||||
- [oliverkirk-sudo/QChatWeather](https://github.com/oliverkirk-sudo/QChatWeather) - 生成好看的天气图片,基于和风天气
|
||||
|
||||
- [oliverkirk-sudo/QChatMarkdown](https://github.com/oliverkirk-sudo/QChatMarkdown) - 将机器人输出的markdown转换为图片,基于[playwright](https://playwright.dev/python/docs/intro)
|
||||
|
||||
- [ruuuux/WikipediaSearch](https://github.com/ruuuux/WikipediaSearch) - Wikipedia 搜索插件
|
||||
|
||||
- [查看更多插件](https://github.com/stars/RockChinQ/lists/qchatgpt-%E6%8F%92%E4%BB%B6)这里列出了更多插件
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
---
|
||||
head:
|
||||
- - meta
|
||||
- name: keywords
|
||||
content: ChatGPT QQ机器人插件,QChatGPT项目插件
|
||||
title: 插件使用
|
||||
icon: list
|
||||
order: 1
|
||||
author: Lazy
|
||||
date: 2023-09-30
|
||||
category:
|
||||
- 插件使用
|
||||
---
|
||||
:::info 目录
|
||||
[[toc]]
|
||||
:::
|
||||
# QChatGPT 的插件使用
|
||||
|
||||
## 简介
|
||||
|
||||
`plugins`目录下的所有`.py`程序都将被加载,除了`__init__.py`之外的模块支持热加载
|
||||
|
||||
> 插件分为`行为插件`和`内容插件`两种,行为插件由主程序运行中的事件驱动,内容插件由GPT生成的内容驱动,请查看内容插件页
|
||||
> 已有插件列表:[QChatGPT 插件](https://github.com/stars/RockChinQ/lists/qchatgpt-%E6%8F%92%E4%BB%B6)
|
||||
|
||||
## 安装
|
||||
|
||||
### 储存库克隆(推荐)
|
||||
|
||||
在运行期间,使用管理员账号对机器人私聊发送`!plugin get <Git储存库地址>`即可自动获取源码并安装插件,程序会根据仓库中的`requirements.txt`文件自动安装依赖库
|
||||
|
||||
例如安装`hello_plugin`插件
|
||||
```
|
||||
!plugin get https://github.com/RockChinQ/hello_plugin
|
||||
```
|
||||
|
||||
安装完成后重启程序或使用管理员账号私聊机器人发送`!reload`进行热重载加载插件
|
||||
|
||||
### 手动安装
|
||||
|
||||
将获取到的插件程序放置到`plugins`目录下,具体使用方式请查看各插件文档或咨询其开发者。
|
||||
|
||||
## 管理
|
||||
|
||||
### !plugin 命令
|
||||
|
||||
```
|
||||
!plugin 列出所有已安装的插件
|
||||
!plugin get <储存库地址> 从Git储存库安装插件(需要管理员权限)
|
||||
!plugin update all 更新所有插件(需要管理员权限,仅支持从储存库安装的插件)
|
||||
!plugin update <插件名> 更新指定插件
|
||||
!plugin del <插件名> 删除插件(需要管理员权限)
|
||||
!plugin on <插件名> 启用插件(需要管理员权限)
|
||||
!plugin off <插件名> 禁用插件(需要管理员权限)
|
||||
|
||||
!func 列出所有内容函数
|
||||
```
|
||||
|
||||
### 控制插件执行顺序
|
||||
|
||||
可以通过修改`plugins/settings.json`中`order`字段中每个插件名称的前后顺序,以更改插件**初始化**和**事件执行**顺序
|
||||
|
||||
### 启用或关闭插件
|
||||
|
||||
无需卸载即可管理插件的开关
|
||||
编辑`plugins`目录下的`switch.json`文件,将相应的插件的`enabled`字段设置为`true/false(开/关)`,之后重启程序或执行热重载即可控制插件开关
|
||||
|
||||
### 控制全局内容函数开关
|
||||
|
||||
内容函数是基于[GPT的Function Calling能力](https://platform.openai.com/docs/guides/gpt/function-calling)实现的,这是一种嵌入对话中,由GPT自动调用的函数。
|
||||
每个插件可以自行注册内容函数,您可以在`plugins`目录下的`settings.json`中设置`functions`下的`enabled`为`true`或`false`控制这些内容函数的启用或禁用。
|
||||
|
||||
# > 说白了就是ChatGPT官方插件那种东西
|
||||
|
||||
内容函数是基于[GPT的Function Calling能力](https://platform.openai.com/docs/guides/gpt/function-calling)实现的,这是一种嵌入对话中,由GPT自动调用的函数。
|
||||
|
||||
例如我们为GPT提供一个函数`access_the_web`,并提供其详细的描述以及其参数的描述,那么当我们在与GPT对话时涉及类似以下内容时:
|
||||
|
||||
```
|
||||
Q: 请搜索一下github上有那些QQ机器人项目?
|
||||
Q: 请为我搜索一些不错的云服务商网站?
|
||||
Q:阅读并总结这篇文章:https://zhuanlan.zhihu.com/p/607570830
|
||||
Q:搜一下清远今天天气如何
|
||||
```
|
||||
|
||||
GPT将会回复一个对`access_the_web`的函数调用请求,QChatGPT将自动处理执行该调用,并返回结果给GPT使其生成新的回复。
|
||||
|
||||
当然,函数调用功能不止局限于网络访问,还可以实现图片处理、科学计算、行程规划等需要调用函数的功能,理论上我们可以通过内容函数实现与`ChatGPT Plugins`相同的功能。
|
||||
|
||||
- 您需要使用`v2.5.0`以上的版本才能加载包含内容函数的插件
|
||||
- 您需要同时在`config.py`中的`completion_api_params`中设置`model`为支持函数调用的模型,推荐使用`gpt-3.5-turbo-16k`
|
||||
- 使用此功能可能会造成难以预期的账号余额消耗,请关注
|
||||
- [逆向库插件](https://github.com/RockChinQ/revLibs)现在也支持函数调用了..您可以在完全免费的情况下使用GPT-3.5进行函数调用,若您在主程序配置了内容函数并启用,逆向ChatGPT会自动使用这些函数
|
||||
|
||||
### ?QChatGPT有什么类型的插件?区别是什么?
|
||||
|
||||
QChatGPT具有`行为插件`和`内容函数`两种扩展方式,行为插件是完整的插件结构,是由运行期间的事件驱动的,内容函数被包含于一个完整的插件体中,由GPT接口驱动。
|
||||
|
||||
> 还是不理解?可以尝试根据插件开发页的步骤自行编写插件
|
||||
|
||||
## QChatGPT的一些不错的内容函数插件
|
||||
|
||||
- [WebwlkrPlugin](https://github.com/RockChinQ/WebwlkrPlugin) - 让机器人能联网!!
|
||||
Reference in New Issue
Block a user