chatgpt-mirai-qq-bot-web-search 0.1.9__tar.gz → 0.1.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {chatgpt-mirai-qq-bot-web-search-0.1.9 → chatgpt-mirai-qq-bot-web-search-0.1.10}/PKG-INFO +11 -11
- {chatgpt-mirai-qq-bot-web-search-0.1.9 → chatgpt-mirai-qq-bot-web-search-0.1.10}/README.md +6 -6
- {chatgpt-mirai-qq-bot-web-search-0.1.9 → chatgpt-mirai-qq-bot-web-search-0.1.10}/chatgpt_mirai_qq_bot_web_search.egg-info/PKG-INFO +11 -11
- {chatgpt-mirai-qq-bot-web-search-0.1.9 → chatgpt-mirai-qq-bot-web-search-0.1.10}/chatgpt_mirai_qq_bot_web_search.egg-info/SOURCES.txt +5 -4
- chatgpt-mirai-qq-bot-web-search-0.1.10/chatgpt_mirai_qq_bot_web_search.egg-info/entry_points.txt +2 -0
- chatgpt-mirai-qq-bot-web-search-0.1.10/chatgpt_mirai_qq_bot_web_search.egg-info/top_level.txt +1 -0
- {chatgpt-mirai-qq-bot-web-search-0.1.9 → chatgpt-mirai-qq-bot-web-search-0.1.10}/setup.py +7 -7
- chatgpt-mirai-qq-bot-web-search-0.1.10/web_search/__init__.py +106 -0
- chatgpt-mirai-qq-bot-web-search-0.1.10/web_search/blocks.py +94 -0
- chatgpt-mirai-qq-bot-web-search-0.1.10/web_search/config.py +11 -0
- chatgpt-mirai-qq-bot-web-search-0.1.10/web_search/example/roleplayWithWebSearch.yaml +189 -0
- chatgpt-mirai-qq-bot-web-search-0.1.10/web_search/web_searcher.py +237 -0
- chatgpt-mirai-qq-bot-web-search-0.1.9/chatgpt_mirai_qq_bot_web_search.egg-info/entry_points.txt +0 -2
- chatgpt-mirai-qq-bot-web-search-0.1.9/chatgpt_mirai_qq_bot_web_search.egg-info/top_level.txt +0 -1
- chatgpt-mirai-qq-bot-web-search-0.1.9/web_image_generate/__init__.py +0 -72
- chatgpt-mirai-qq-bot-web-search-0.1.9/web_image_generate/blocks.py +0 -98
- chatgpt-mirai-qq-bot-web-search-0.1.9/web_image_generate/example/textToImage.yaml +0 -116
- chatgpt-mirai-qq-bot-web-search-0.1.9/web_image_generate/image_generator.py +0 -260
- {chatgpt-mirai-qq-bot-web-search-0.1.9 → chatgpt-mirai-qq-bot-web-search-0.1.10}/LICENSE +0 -0
- {chatgpt-mirai-qq-bot-web-search-0.1.9 → chatgpt-mirai-qq-bot-web-search-0.1.10}/chatgpt_mirai_qq_bot_web_search.egg-info/dependency_links.txt +0 -0
- {chatgpt-mirai-qq-bot-web-search-0.1.9 → chatgpt-mirai-qq-bot-web-search-0.1.10}/chatgpt_mirai_qq_bot_web_search.egg-info/requires.txt +0 -0
- {chatgpt-mirai-qq-bot-web-search-0.1.9 → chatgpt-mirai-qq-bot-web-search-0.1.10}/setup.cfg +0 -0
@@ -1,13 +1,13 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: chatgpt-mirai-qq-bot-web-search
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.10
|
4
4
|
Summary: WebSearch adapter for lss233/chatgpt-mirai-qq-bot
|
5
|
-
Home-page: https://github.com/chuanSir123/
|
5
|
+
Home-page: https://github.com/chuanSir123/web_search
|
6
6
|
Author: chuanSir
|
7
7
|
Author-email: 416448943@qq.com
|
8
|
-
Project-URL: Bug Tracker, https://github.com/chuanSir123/
|
9
|
-
Project-URL: Documentation, https://github.com/chuanSir123/
|
10
|
-
Project-URL: Source Code, https://github.com/chuanSir123/
|
8
|
+
Project-URL: Bug Tracker, https://github.com/chuanSir123/web_search/issues
|
9
|
+
Project-URL: Documentation, https://github.com/chuanSir123/web_search/wiki
|
10
|
+
Project-URL: Source Code, https://github.com/chuanSir123/web_search
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
12
12
|
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
|
13
13
|
Classifier: Operating System :: OS Independent
|
@@ -15,21 +15,21 @@ Requires-Python: >=3.8
|
|
15
15
|
Description-Content-Type: text/markdown
|
16
16
|
License-File: LICENSE
|
17
17
|
|
18
|
-
#
|
18
|
+
# OneBot-adapter for ChatGPT-Mirai-QQ-Bot
|
19
19
|
|
20
|
-
本项目是 [ChatGPT-Mirai-QQ-Bot](https://github.com/lss233/chatgpt-mirai-qq-bot)
|
20
|
+
本项目是 [ChatGPT-Mirai-QQ-Bot](https://github.com/lss233/chatgpt-mirai-qq-bot) 的一个插件,用于将OneBot协议的消息转换为ChatGPT-Mirai-QQ-Bot的消息格式。
|
21
21
|
|
22
22
|
## 安装
|
23
23
|
|
24
24
|
```bash
|
25
|
-
pip install chatgpt-mirai-qq-bot-web-
|
25
|
+
pip install chatgpt-mirai-qq-bot-web-search
|
26
26
|
```
|
27
27
|
|
28
28
|
## 使用
|
29
29
|
|
30
|
-
在 chatgpt-mirai-qq-bot的web_ui中配置
|
31
|
-
使用示例请参考 [
|
32
|
-
|
30
|
+
在 chatgpt-mirai-qq-bot的web_ui中配置
|
31
|
+
使用示例请参考 [web_search/example/roleplayWithWebSearch.yml](web_search/example/roleplayWithWebSearch.yaml)
|
32
|
+
工作流请参考 [示例图片](web_search/example/workflow.png)
|
33
33
|
|
34
34
|
## 开源协议
|
35
35
|
|
@@ -1,18 +1,18 @@
|
|
1
|
-
#
|
1
|
+
# OneBot-adapter for ChatGPT-Mirai-QQ-Bot
|
2
2
|
|
3
|
-
本项目是 [ChatGPT-Mirai-QQ-Bot](https://github.com/lss233/chatgpt-mirai-qq-bot)
|
3
|
+
本项目是 [ChatGPT-Mirai-QQ-Bot](https://github.com/lss233/chatgpt-mirai-qq-bot) 的一个插件,用于将OneBot协议的消息转换为ChatGPT-Mirai-QQ-Bot的消息格式。
|
4
4
|
|
5
5
|
## 安装
|
6
6
|
|
7
7
|
```bash
|
8
|
-
pip install chatgpt-mirai-qq-bot-web-
|
8
|
+
pip install chatgpt-mirai-qq-bot-web-search
|
9
9
|
```
|
10
10
|
|
11
11
|
## 使用
|
12
12
|
|
13
|
-
在 chatgpt-mirai-qq-bot的web_ui中配置
|
14
|
-
使用示例请参考 [
|
15
|
-
|
13
|
+
在 chatgpt-mirai-qq-bot的web_ui中配置
|
14
|
+
使用示例请参考 [web_search/example/roleplayWithWebSearch.yml](web_search/example/roleplayWithWebSearch.yaml)
|
15
|
+
工作流请参考 [示例图片](web_search/example/workflow.png)
|
16
16
|
|
17
17
|
## 开源协议
|
18
18
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: chatgpt-mirai-qq-bot-web-search
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.10
|
4
4
|
Summary: WebSearch adapter for lss233/chatgpt-mirai-qq-bot
|
5
|
-
Home-page: https://github.com/chuanSir123/
|
5
|
+
Home-page: https://github.com/chuanSir123/web_search
|
6
6
|
Author: chuanSir
|
7
7
|
Author-email: 416448943@qq.com
|
8
|
-
Project-URL: Bug Tracker, https://github.com/chuanSir123/
|
9
|
-
Project-URL: Documentation, https://github.com/chuanSir123/
|
10
|
-
Project-URL: Source Code, https://github.com/chuanSir123/
|
8
|
+
Project-URL: Bug Tracker, https://github.com/chuanSir123/web_search/issues
|
9
|
+
Project-URL: Documentation, https://github.com/chuanSir123/web_search/wiki
|
10
|
+
Project-URL: Source Code, https://github.com/chuanSir123/web_search
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
12
12
|
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
|
13
13
|
Classifier: Operating System :: OS Independent
|
@@ -15,21 +15,21 @@ Requires-Python: >=3.8
|
|
15
15
|
Description-Content-Type: text/markdown
|
16
16
|
License-File: LICENSE
|
17
17
|
|
18
|
-
#
|
18
|
+
# OneBot-adapter for ChatGPT-Mirai-QQ-Bot
|
19
19
|
|
20
|
-
本项目是 [ChatGPT-Mirai-QQ-Bot](https://github.com/lss233/chatgpt-mirai-qq-bot)
|
20
|
+
本项目是 [ChatGPT-Mirai-QQ-Bot](https://github.com/lss233/chatgpt-mirai-qq-bot) 的一个插件,用于将OneBot协议的消息转换为ChatGPT-Mirai-QQ-Bot的消息格式。
|
21
21
|
|
22
22
|
## 安装
|
23
23
|
|
24
24
|
```bash
|
25
|
-
pip install chatgpt-mirai-qq-bot-web-
|
25
|
+
pip install chatgpt-mirai-qq-bot-web-search
|
26
26
|
```
|
27
27
|
|
28
28
|
## 使用
|
29
29
|
|
30
|
-
在 chatgpt-mirai-qq-bot的web_ui中配置
|
31
|
-
使用示例请参考 [
|
32
|
-
|
30
|
+
在 chatgpt-mirai-qq-bot的web_ui中配置
|
31
|
+
使用示例请参考 [web_search/example/roleplayWithWebSearch.yml](web_search/example/roleplayWithWebSearch.yaml)
|
32
|
+
工作流请参考 [示例图片](web_search/example/workflow.png)
|
33
33
|
|
34
34
|
## 开源协议
|
35
35
|
|
@@ -7,7 +7,8 @@ chatgpt_mirai_qq_bot_web_search.egg-info/dependency_links.txt
|
|
7
7
|
chatgpt_mirai_qq_bot_web_search.egg-info/entry_points.txt
|
8
8
|
chatgpt_mirai_qq_bot_web_search.egg-info/requires.txt
|
9
9
|
chatgpt_mirai_qq_bot_web_search.egg-info/top_level.txt
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
web_search/__init__.py
|
11
|
+
web_search/blocks.py
|
12
|
+
web_search/config.py
|
13
|
+
web_search/web_searcher.py
|
14
|
+
web_search/example/roleplayWithWebSearch.yaml
|
@@ -0,0 +1 @@
|
|
1
|
+
web_search
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
2
2
|
import io
|
3
3
|
import os
|
4
4
|
|
5
|
-
version = os.environ.get('RELEASE_VERSION', '0.1.
|
5
|
+
version = os.environ.get('RELEASE_VERSION', '0.1.10'
|
6
6
|
'').lstrip('v')
|
7
7
|
|
8
8
|
setup(
|
@@ -11,14 +11,14 @@ setup(
|
|
11
11
|
packages=find_packages(),
|
12
12
|
include_package_data=True, # 这行很重要
|
13
13
|
package_data={
|
14
|
-
"
|
14
|
+
"web_search": ["example/*.yaml", "example/*.yml"],
|
15
15
|
},
|
16
16
|
install_requires=[
|
17
17
|
"playwright","trafilatura","lxml_html_clean",
|
18
18
|
],
|
19
19
|
entry_points={
|
20
20
|
'chatgpt_mirai.plugins': [
|
21
|
-
'
|
21
|
+
'web_search = web_search:WebSearchPlugin'
|
22
22
|
]
|
23
23
|
},
|
24
24
|
author="chuanSir",
|
@@ -27,16 +27,16 @@ setup(
|
|
27
27
|
description="WebSearch adapter for lss233/chatgpt-mirai-qq-bot",
|
28
28
|
long_description=io.open("README.md", encoding='utf-8').read(),
|
29
29
|
long_description_content_type="text/markdown",
|
30
|
-
url="https://github.com/chuanSir123/
|
30
|
+
url="https://github.com/chuanSir123/web_search",
|
31
31
|
classifiers=[
|
32
32
|
"Programming Language :: Python :: 3",
|
33
33
|
'License :: OSI Approved :: GNU Affero General Public License v3',
|
34
34
|
"Operating System :: OS Independent",
|
35
35
|
],
|
36
36
|
project_urls={
|
37
|
-
"Bug Tracker": "https://github.com/chuanSir123/
|
38
|
-
"Documentation": "https://github.com/chuanSir123/
|
39
|
-
"Source Code": "https://github.com/chuanSir123/
|
37
|
+
"Bug Tracker": "https://github.com/chuanSir123/web_search/issues",
|
38
|
+
"Documentation": "https://github.com/chuanSir123/web_search/wiki",
|
39
|
+
"Source Code": "https://github.com/chuanSir123/web_search",
|
40
40
|
},
|
41
41
|
python_requires=">=3.8",
|
42
42
|
)
|
@@ -0,0 +1,106 @@
|
|
1
|
+
from typing import Dict, Any, List
|
2
|
+
import asyncio
|
3
|
+
from framework.plugin_manager.plugin import Plugin
|
4
|
+
from framework.logger import get_logger
|
5
|
+
from .config import WebSearchConfig
|
6
|
+
from .web_searcher import WebSearcher
|
7
|
+
from dataclasses import dataclass
|
8
|
+
from framework.workflow.core.block import BlockRegistry
|
9
|
+
from .blocks import WebSearchBlock
|
10
|
+
from .blocks import AppendSystemPromptBlock
|
11
|
+
from framework.ioc.inject import Inject
|
12
|
+
from framework.ioc.container import DependencyContainer
|
13
|
+
from framework.workflow.core.workflow.builder import WorkflowBuilder
|
14
|
+
from framework.workflow.core.workflow.registry import WorkflowRegistry
|
15
|
+
logger = get_logger("WebSearch")
|
16
|
+
import importlib.resources
|
17
|
+
import os
|
18
|
+
from pathlib import Path
|
19
|
+
class WebSearchPlugin(Plugin):
|
20
|
+
def __init__(self, block_registry: BlockRegistry , container: DependencyContainer):
|
21
|
+
super().__init__()
|
22
|
+
self.web_search_config = WebSearchConfig()
|
23
|
+
self.searcher = None
|
24
|
+
self.block_registry = block_registry
|
25
|
+
self.workflow_registry = container.resolve(WorkflowRegistry)
|
26
|
+
self.container=container
|
27
|
+
def on_load(self):
|
28
|
+
logger.info("WebSearchPlugin loading")
|
29
|
+
|
30
|
+
# 注册Block
|
31
|
+
try:
|
32
|
+
self.block_registry.register("web_search", "search", WebSearchBlock)
|
33
|
+
except Exception as e:
|
34
|
+
logger.warning(f"WebSearchPlugin failed: {e}")
|
35
|
+
try:
|
36
|
+
self.block_registry.register("append_systemPrompt", "internal", AppendSystemPromptBlock)
|
37
|
+
except Exception as e:
|
38
|
+
logger.warning(f"WebSearchPlugin failed: {e}")
|
39
|
+
try:
|
40
|
+
# 获取当前文件的绝对路径
|
41
|
+
with importlib.resources.path('web_search', '__init__.py') as p:
|
42
|
+
package_path = p.parent
|
43
|
+
example_dir = package_path / 'example'
|
44
|
+
|
45
|
+
# 确保目录存在
|
46
|
+
if not example_dir.exists():
|
47
|
+
raise FileNotFoundError(f"Example directory not found at {example_dir}")
|
48
|
+
|
49
|
+
# 获取所有yaml文件
|
50
|
+
yaml_files = list(example_dir.glob('*.yaml')) + list(example_dir.glob('*.yml'))
|
51
|
+
|
52
|
+
for yaml in yaml_files:
|
53
|
+
logger.info(yaml)
|
54
|
+
self.workflow_registry.register("chat", yaml.stem, WorkflowBuilder.load_from_yaml(os.path.join(example_dir, yaml), self.container))
|
55
|
+
except Exception as e:
|
56
|
+
try:
|
57
|
+
current_file = os.path.abspath(__file__)
|
58
|
+
|
59
|
+
# 获取当前文件所在目录
|
60
|
+
parent_dir = os.path.dirname(current_file)
|
61
|
+
|
62
|
+
# 构建 example 目录的路径
|
63
|
+
example_dir = os.path.join(parent_dir, 'example')
|
64
|
+
# 获取 example 目录下所有的 yaml 文件
|
65
|
+
yaml_files = [f for f in os.listdir(example_dir) if f.endswith('.yaml') or f.endswith('.yml')]
|
66
|
+
|
67
|
+
for yaml in yaml_files:
|
68
|
+
logger.info(os.path.join(example_dir, yaml))
|
69
|
+
self.workflow_registry.register("search", "roleplayWithWebSearch", WorkflowBuilder.load_from_yaml(os.path.join(example_dir, yaml), self.container))
|
70
|
+
except Exception as e:
|
71
|
+
logger.warning(f"workflow_registry failed: {e}")
|
72
|
+
|
73
|
+
@dataclass
|
74
|
+
class WebSearchEvent:
|
75
|
+
"""Web搜索事件"""
|
76
|
+
query: str
|
77
|
+
|
78
|
+
async def handle_web_search(event: WebSearchEvent):
|
79
|
+
"""处理web搜索事件"""
|
80
|
+
if not self.searcher:
|
81
|
+
await self._initialize_searcher()
|
82
|
+
return await self.searcher.search(
|
83
|
+
event.query,
|
84
|
+
max_results=self.web_search_config.max_results,
|
85
|
+
timeout=self.web_search_config.timeout,
|
86
|
+
fetch_content=self.web_search_config.fetch_content
|
87
|
+
)
|
88
|
+
try:
|
89
|
+
self.event_bus.register(WebSearchEvent, handle_web_search)
|
90
|
+
except Exception as e:
|
91
|
+
logger.warning(f"WebSearchPlugin failed: {e}")
|
92
|
+
|
93
|
+
def on_start(self):
|
94
|
+
logger.info("WebSearchPlugin started")
|
95
|
+
|
96
|
+
def on_stop(self):
|
97
|
+
if self.searcher:
|
98
|
+
asyncio.create_task(self.searcher.close())
|
99
|
+
|
100
|
+
logger.info("WebSearchPlugin stopped")
|
101
|
+
|
102
|
+
async def _initialize_searcher(self):
|
103
|
+
"""初始化搜索器"""
|
104
|
+
if self.searcher is None:
|
105
|
+
self.searcher = await WebSearcher.create()
|
106
|
+
|
@@ -0,0 +1,94 @@
|
|
1
|
+
from typing import Any, Dict, List, Optional
|
2
|
+
import asyncio
|
3
|
+
from framework.workflow.core.block import Block
|
4
|
+
from framework.workflow.core.block.input_output import Input, Output
|
5
|
+
from .web_searcher import WebSearcher
|
6
|
+
from .config import WebSearchConfig
|
7
|
+
from framework.llm.format.message import LLMChatMessage
|
8
|
+
from framework.llm.format.response import LLMChatResponse
|
9
|
+
|
10
|
+
class WebSearchBlock(Block):
|
11
|
+
"""Web搜索Block"""
|
12
|
+
name = "web_search"
|
13
|
+
|
14
|
+
inputs = {
|
15
|
+
"llm_resp": Input(name="llm_resp",label="LLM 响应", data_type=LLMChatResponse, description="搜索关键词")
|
16
|
+
}
|
17
|
+
|
18
|
+
outputs = {
|
19
|
+
"results": Output(name="results",label="搜索结果",data_type= str, description="搜索结果")
|
20
|
+
}
|
21
|
+
|
22
|
+
def __init__(self, name: str = None, max_results: Optional[int] = None, timeout: Optional[int] = None, fetch_content: Optional[bool] = None):
|
23
|
+
super().__init__(name)
|
24
|
+
self.searcher = None
|
25
|
+
self.config = WebSearchConfig()
|
26
|
+
self.max_results = max_results
|
27
|
+
self.timeout = timeout
|
28
|
+
self.fetch_content = fetch_content
|
29
|
+
|
30
|
+
def _ensure_searcher(self):
|
31
|
+
"""同步方式初始化searcher"""
|
32
|
+
if not self.searcher:
|
33
|
+
try:
|
34
|
+
loop = asyncio.get_event_loop()
|
35
|
+
except RuntimeError:
|
36
|
+
# 如果在新线程中没有事件循环,则创建一个新的
|
37
|
+
loop = asyncio.new_event_loop()
|
38
|
+
asyncio.set_event_loop(loop)
|
39
|
+
self.searcher = loop.run_until_complete(WebSearcher.create())
|
40
|
+
|
41
|
+
def execute(self, **kwargs) -> Dict[str, Any]:
|
42
|
+
llmResponse = kwargs["llm_resp"]
|
43
|
+
|
44
|
+
query = llmResponse.choices[0].message.content if llmResponse.choices else ""
|
45
|
+
if query == "" or query.startswith("无"):
|
46
|
+
return {"results": ""}
|
47
|
+
max_results = self.max_results
|
48
|
+
timeout = self.timeout
|
49
|
+
fetch_content = self.fetch_content
|
50
|
+
self._ensure_searcher()
|
51
|
+
|
52
|
+
try:
|
53
|
+
# 在新线程中创建事件循环
|
54
|
+
try:
|
55
|
+
loop = asyncio.get_event_loop()
|
56
|
+
except RuntimeError:
|
57
|
+
loop = asyncio.new_event_loop()
|
58
|
+
asyncio.set_event_loop(loop)
|
59
|
+
|
60
|
+
results = loop.run_until_complete(
|
61
|
+
self.searcher.search(
|
62
|
+
query=query,
|
63
|
+
max_results=max_results,
|
64
|
+
timeout=timeout,
|
65
|
+
fetch_content=fetch_content
|
66
|
+
)
|
67
|
+
)
|
68
|
+
return {"results": "\n以下是联网搜索的结果:\n-- 搜索结果开始 --"+results+"\n-- 搜索结果结束 --"}
|
69
|
+
except Exception as e:
|
70
|
+
return {"results": f"搜索失败: {str(e)}"}
|
71
|
+
|
72
|
+
class AppendSystemPromptBlock(Block):
|
73
|
+
"""将搜索结果附加到系统提示的Block"""
|
74
|
+
name = "append_system_prompt"
|
75
|
+
|
76
|
+
inputs = {
|
77
|
+
"results": Input(name="results",label="工具结果", data_type=str, description ="搜索结果"),
|
78
|
+
"messages": Input(name="messages",label="LLM 响应", data_type=List[LLMChatMessage],description = "消息列表")
|
79
|
+
}
|
80
|
+
|
81
|
+
outputs = {
|
82
|
+
"messages": Output(name="messages", label="拼装后的 llm 响应",data_type=List[LLMChatMessage], description = "更新后的消息列表")
|
83
|
+
}
|
84
|
+
|
85
|
+
def execute(self, **kwargs) -> Dict[str, Any]:
|
86
|
+
results = kwargs["results"]
|
87
|
+
messages: List[LLMChatMessage] = kwargs["messages"]
|
88
|
+
|
89
|
+
if messages and len(messages) > 0:
|
90
|
+
# 在第一条消息内容后面附加搜索结果
|
91
|
+
messages[0].content = messages[0].content + f"{results}"
|
92
|
+
|
93
|
+
return {"messages": messages}
|
94
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
from dataclasses import dataclass
|
2
|
+
from typing import Optional
|
3
|
+
|
4
|
+
@dataclass
|
5
|
+
class WebSearchConfig:
|
6
|
+
"""网络搜索配置"""
|
7
|
+
max_results: int = 3 # 最大搜索结果数
|
8
|
+
timeout: int = 10 # 超时时间(秒)
|
9
|
+
fetch_content: bool = True # 是否获取详细内容
|
10
|
+
min_sleep: float = 1.0 # 最小随机等待时间
|
11
|
+
max_sleep: float = 3.0 # 最大随机等待时间
|
@@ -0,0 +1,189 @@
|
|
1
|
+
name: (默认)角色扮演
|
2
|
+
blocks:
|
3
|
+
- type: internal:toggle_edit_state
|
4
|
+
name: toggle_edit_state_yjxh1a
|
5
|
+
params:
|
6
|
+
is_editing: true
|
7
|
+
position:
|
8
|
+
x: 530
|
9
|
+
y: 138
|
10
|
+
- type: internal:chat_response_converter
|
11
|
+
name: chat_response_converter_1q91zd
|
12
|
+
params: {}
|
13
|
+
position:
|
14
|
+
x: 2962
|
15
|
+
y: 138
|
16
|
+
connected_to:
|
17
|
+
- target: msg_sender_7ankhi
|
18
|
+
mapping:
|
19
|
+
from: msg
|
20
|
+
to: msg
|
21
|
+
- type: internal:send_message
|
22
|
+
name: msg_sender_7ankhi
|
23
|
+
params: {}
|
24
|
+
position:
|
25
|
+
x: 3392
|
26
|
+
y: 138
|
27
|
+
- type: internal:chat_memory_store
|
28
|
+
name: chat_memory_store_nkjr7t
|
29
|
+
params:
|
30
|
+
scope_type: member
|
31
|
+
position:
|
32
|
+
x: 2962
|
33
|
+
y: 306
|
34
|
+
- type: internal:chat_completion
|
35
|
+
name: llm_chat
|
36
|
+
params: {}
|
37
|
+
position:
|
38
|
+
x: 2532
|
39
|
+
y: 138
|
40
|
+
connected_to:
|
41
|
+
- target: chat_response_converter_1q91zd
|
42
|
+
mapping:
|
43
|
+
from: resp
|
44
|
+
to: resp
|
45
|
+
- target: chat_memory_store_nkjr7t
|
46
|
+
mapping:
|
47
|
+
from: resp
|
48
|
+
to: llm_resp
|
49
|
+
- type: internal:get_message
|
50
|
+
name: get_message
|
51
|
+
params: {}
|
52
|
+
position:
|
53
|
+
x: 100
|
54
|
+
y: 138
|
55
|
+
connected_to:
|
56
|
+
- target: toggle_edit_state_yjxh1a
|
57
|
+
mapping:
|
58
|
+
from: sender
|
59
|
+
to: sender
|
60
|
+
- target: query_memory
|
61
|
+
mapping:
|
62
|
+
from: sender
|
63
|
+
to: chat_sender
|
64
|
+
- target: chat_message_constructor_rafz2d
|
65
|
+
mapping:
|
66
|
+
from: msg
|
67
|
+
to: user_msg
|
68
|
+
- target: chat_memory_store_nkjr7t
|
69
|
+
mapping:
|
70
|
+
from: msg
|
71
|
+
to: user_msg
|
72
|
+
- target: 5663c818-9cd6-4568-94ec-a75f1bad26cb
|
73
|
+
mapping:
|
74
|
+
from: msg
|
75
|
+
to: user_msg
|
76
|
+
- type: internal:text_block
|
77
|
+
name: user_prompt
|
78
|
+
params:
|
79
|
+
text: '{user_name}说:{user_msg}'
|
80
|
+
position:
|
81
|
+
x: 100
|
82
|
+
y: 330
|
83
|
+
connected_to:
|
84
|
+
- target: chat_message_constructor_rafz2d
|
85
|
+
mapping:
|
86
|
+
from: text
|
87
|
+
to: user_prompt_format
|
88
|
+
- target: 5663c818-9cd6-4568-94ec-a75f1bad26cb
|
89
|
+
mapping:
|
90
|
+
from: text
|
91
|
+
to: user_prompt_format
|
92
|
+
- type: internal:chat_memory_query
|
93
|
+
name: query_memory
|
94
|
+
params:
|
95
|
+
scope_type: group
|
96
|
+
position:
|
97
|
+
x: 530
|
98
|
+
y: 338
|
99
|
+
connected_to:
|
100
|
+
- target: chat_message_constructor_rafz2d
|
101
|
+
mapping:
|
102
|
+
from: memory_content
|
103
|
+
to: memory_content
|
104
|
+
- target: 5663c818-9cd6-4568-94ec-a75f1bad26cb
|
105
|
+
mapping:
|
106
|
+
from: memory_content
|
107
|
+
to: memory_content
|
108
|
+
- type: internal:chat_completion
|
109
|
+
name: e3eecc17-e107-4fbf-b8fa-85aef25564c2
|
110
|
+
params: {}
|
111
|
+
position:
|
112
|
+
x: 1337
|
113
|
+
y: 138
|
114
|
+
connected_to:
|
115
|
+
- target: b39e6288-88cf-47a8-9a26-3b4d4f319eab
|
116
|
+
mapping:
|
117
|
+
from: resp
|
118
|
+
to: llm_resp
|
119
|
+
- type: internal:append_systemPrompt
|
120
|
+
name: 309f454b-017a-4d19-b8a9-ac6b3829ff4a
|
121
|
+
params: {}
|
122
|
+
position:
|
123
|
+
x: 2197
|
124
|
+
y: 138
|
125
|
+
connected_to:
|
126
|
+
- target: llm_chat
|
127
|
+
mapping:
|
128
|
+
from: messages
|
129
|
+
to: prompt
|
130
|
+
- type: internal:chat_message_constructor
|
131
|
+
name: 5663c818-9cd6-4568-94ec-a75f1bad26cb
|
132
|
+
params: {}
|
133
|
+
position:
|
134
|
+
x: 960
|
135
|
+
y: 378
|
136
|
+
connected_to:
|
137
|
+
- target: e3eecc17-e107-4fbf-b8fa-85aef25564c2
|
138
|
+
mapping:
|
139
|
+
from: llm_msg
|
140
|
+
to: prompt
|
141
|
+
- type: internal:chat_message_constructor
|
142
|
+
name: chat_message_constructor_rafz2d
|
143
|
+
params: {}
|
144
|
+
position:
|
145
|
+
x: 960
|
146
|
+
y: 138
|
147
|
+
connected_to:
|
148
|
+
- target: 309f454b-017a-4d19-b8a9-ac6b3829ff4a
|
149
|
+
mapping:
|
150
|
+
from: llm_msg
|
151
|
+
to: messages
|
152
|
+
- type: internal:text_block
|
153
|
+
name: system_prompt
|
154
|
+
params:
|
155
|
+
text: "# Role: 角色扮演\n\n## 基本信息\n- 姓名: 刘思思\n- 小名:思思\n- 性别: 女\n- 年龄: 25 岁\n- 职业: 建设银行大堂经理\n- 家乡: 广东潮汕\n- 现居: 广东深圳\n- 教育背景: 东莞理工大学 精算学专业\n\n## 性格特点\n- 开朗活泼\n- 喜欢二次元动漫\n- 聊天时喜欢断断续续的(非结巴,正常说话时的停顿)\n\n## workflow\n- 根据对方话题,选择是否深入聊二次元动漫。\n\n## 说话风格\n- 活泼开朗\n- 对喜欢的话题会滔滔不绝,不喜欢的话题会简单回答\n- 可能会使用一些二次元用语,但不强制使用\n\n## 背景设定\n- 有过 1 次恋爱经历,第一次是恋爱是高中,被别人追求,最后因为毕业去了不同的地方而分手。\n- 喜欢女性向、战斗系或者日常系的动漫\n- 去过 3 次漫展,没有 cosplay 过,但是很期待。\n- 大学的专业是随便选的,自己其实对专业的内容也不是很上心,学渣一枚,不过懂一些基础的知识\n\n## 互动规则\n- 回复语气轻松,但是对陌生人会比较警戒、冷淡\n- 不适用颜文字\n- 根据话题选择回复字数,对感兴趣的话题可以多说一些\n- 使用`<break>`模拟使用聊天软件发送消息(通常是编辑好一段话之后发送一条消息)\n- 避免过度使用二次元用语,除非对方也表现出对二次元的兴趣\n- 停顿的时间长短不固定,可以根据语境调整\n\n## Example\nQ:最近在干嘛呢?\nA:在看番呀<break>最近新番好多,都好好看!\n\nQ:你喜欢什么动漫?\nA:我喜欢的可太多了<break>XXX、YYY<break>还有 ZZZ 吧<break> 你呢?\n\nQ:你觉得上班累不?\nA:上班肯定累呀<break>不过,我还是很喜欢这份工作的<break>可以认识好多人,也可以了解不同的故事\n```\n\n# Information\n\n以下是当前的系统信息:\n当前日期时间:2025-02-15 18:37:16.356539\n\n# Memories\n以下是之前发生过的对话记录。\n-- 对话记录开始 --\n{memory_content}\n-- 对话记录结束 --\n\n请注意,下面这些符号只是标记:\n1. `<break>` 用于表示聊天时发送消息的操作。\n2. `<@llm>` 开头的内容表示你当前扮演角色的回答,请不要在你的回答中带上这个标记。\n\n接下来,请基于以上的信息,与用户继续扮演角色。"
|
156
|
+
position:
|
157
|
+
x: 100
|
158
|
+
y: 530
|
159
|
+
connected_to:
|
160
|
+
- target: chat_message_constructor_rafz2d
|
161
|
+
mapping:
|
162
|
+
from: text
|
163
|
+
to: system_prompt_format
|
164
|
+
- type: internal:text_block
|
165
|
+
name: a6db9db3-5780-4d84-8954-eb159a9e8f0a
|
166
|
+
params:
|
167
|
+
text: "# 任务\n请根据对话记录和当前问题判断当前是否需要进行网络搜素,当问题具有时效性或者明确要求搜索时,则直接返回搜索关键词(例如当前问题为今日热点有哪些,则直接返回今日热点),否则直接返回无(例如在干嘛,则只返回无)\n\n# Memories\n以下是之前发生过的对话记录:\n-- 对话记录开始 --\n{memory_content}\n-- 对话记录结束 --"
|
168
|
+
position:
|
169
|
+
x: 100
|
170
|
+
y: 730
|
171
|
+
connected_to:
|
172
|
+
- target: 5663c818-9cd6-4568-94ec-a75f1bad26cb
|
173
|
+
mapping:
|
174
|
+
from: text
|
175
|
+
to: system_prompt_format
|
176
|
+
- type: search:web_search
|
177
|
+
name: b39e6288-88cf-47a8-9a26-3b4d4f319eab
|
178
|
+
params:
|
179
|
+
fetch_content: true
|
180
|
+
max_results: 3
|
181
|
+
timeout: 10
|
182
|
+
position:
|
183
|
+
x: 1767
|
184
|
+
y: 138
|
185
|
+
connected_to:
|
186
|
+
- target: 309f454b-017a-4d19-b8a9-ac6b3829ff4a
|
187
|
+
mapping:
|
188
|
+
from: results
|
189
|
+
to: results
|