lintonxue00
commited on
Commit
•
6d9d8e0
1
Parent(s):
ac86414
Upload 2 files
Browse files- 不知道/回收站/4/ext_forget.py +43 -0
- 不知道/回收站/4/ext_remember.py +44 -0
不知道/回收站/4/ext_forget.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from .Extension import Extension
|
2 |
+
|
3 |
+
|
4 |
+
# 拓展的配置信息,用于ai理解拓展的功能 *必填*
|
5 |
+
ext_config:dict = {
|
6 |
+
"name": "forget", # 拓展名称,用于标识拓展
|
7 |
+
"arguments": {
|
8 |
+
'key': 'str', # 记忆的键
|
9 |
+
'value': 'str', # 记忆的值
|
10 |
+
},
|
11 |
+
"description": "Delete the memory according to the key. (usage in response: /#forget&topic#/)))",
|
12 |
+
# 参考词,用于上下文参考使用,为空则每次都会被参考(消耗token)
|
13 |
+
"refer_word": [],
|
14 |
+
# 每次消息回复中最大调用次数,不填则默认为99
|
15 |
+
"max_call_times_per_msg": 5,
|
16 |
+
# 作者信息
|
17 |
+
"author": "KroMiose",
|
18 |
+
# 版本
|
19 |
+
"version": "0.0.1",
|
20 |
+
# 拓展简介
|
21 |
+
"intro": "主动遗忘模块",
|
22 |
+
}
|
23 |
+
|
24 |
+
class CustomExtension(Extension):
|
25 |
+
async def call(self, arg_dict: dict, ctx_data: dict) -> dict:
|
26 |
+
""" 当拓展被调用时执行的函数 *由拓展自行实现*
|
27 |
+
|
28 |
+
参数:
|
29 |
+
arg_dict: dict, 由ai解析的参数字典 {参数名: 参数值(类型为str)}
|
30 |
+
"""
|
31 |
+
custom_config:dict = self.get_custom_config() # 获取yaml中的配置信息
|
32 |
+
|
33 |
+
# 从arg_dict中获取参数
|
34 |
+
key = arg_dict.get('key', None)
|
35 |
+
if key is None:
|
36 |
+
raise ValueError('记忆的键不能为空')
|
37 |
+
|
38 |
+
return {
|
39 |
+
'memory': {'key': key},
|
40 |
+
}
|
41 |
+
|
42 |
+
def __init__(self, custom_config: dict):
|
43 |
+
super().__init__(ext_config.copy(), custom_config)
|
不知道/回收站/4/ext_remember.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from .Extension import Extension
|
2 |
+
|
3 |
+
|
4 |
+
# 拓展的配置信息,用于ai理解拓展的功能 *必填*
|
5 |
+
ext_config:dict = {
|
6 |
+
"name": "remember", # 拓展名称,用于标识拓展
|
7 |
+
"arguments": {
|
8 |
+
'key': 'str', # 记忆的键
|
9 |
+
'value': 'str', # 记忆的值
|
10 |
+
},
|
11 |
+
"description": "Set the memory according to the key and value. (usage in response: /#remember&topic&we are talking about ...#/)))",
|
12 |
+
# 参考词,用于上下文参考使用,为空则每次都会被参考(消耗token)
|
13 |
+
"refer_word": [],
|
14 |
+
# 每次消息回复中最大调用次数,不填则默认为99
|
15 |
+
"max_call_times_per_msg": 5,
|
16 |
+
# 作者信息
|
17 |
+
"author": "KroMiose",
|
18 |
+
# 版本
|
19 |
+
"version": "0.0.1",
|
20 |
+
# 拓展简介
|
21 |
+
"intro": "主动记忆模块",
|
22 |
+
}
|
23 |
+
|
24 |
+
class CustomExtension(Extension):
|
25 |
+
async def call(self, arg_dict: dict, ctx_data: dict) -> dict:
|
26 |
+
""" 当拓展被调用时执行的函数 *由拓展自行实现*
|
27 |
+
|
28 |
+
参数:
|
29 |
+
arg_dict: dict, 由ai解析的参数字典 {参数名: 参数值(类型为str)}
|
30 |
+
"""
|
31 |
+
custom_config:dict = self.get_custom_config() # 获取yaml中的配置信息
|
32 |
+
|
33 |
+
# 从arg_dict中获取参数
|
34 |
+
key = arg_dict.get('key', None)
|
35 |
+
value = arg_dict.get('value', None)
|
36 |
+
if key is None:
|
37 |
+
raise ValueError('记忆的键不能为空')
|
38 |
+
|
39 |
+
return {
|
40 |
+
'memory': {'key': key, 'value': value},
|
41 |
+
}
|
42 |
+
|
43 |
+
def __init__(self, custom_config: dict):
|
44 |
+
super().__init__(ext_config.copy(), custom_config)
|