chatgpt-mirai-qq-bot-web-search 0.1.1__py3-none-any.whl → 0.1.3__py3-none-any.whl
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.1.dist-info → chatgpt_mirai_qq_bot_web_search-0.1.3.dist-info}/METADATA +4 -4
- chatgpt_mirai_qq_bot_web_search-0.1.3.dist-info/RECORD +10 -0
- web_search/__init__.py +23 -46
- web_search/blocks.py +5 -5
- chatgpt_mirai_qq_bot_web_search-0.1.1.dist-info/RECORD +0 -10
- {chatgpt_mirai_qq_bot_web_search-0.1.1.dist-info → chatgpt_mirai_qq_bot_web_search-0.1.3.dist-info}/LICENSE +0 -0
- {chatgpt_mirai_qq_bot_web_search-0.1.1.dist-info → chatgpt_mirai_qq_bot_web_search-0.1.3.dist-info}/WHEEL +0 -0
- {chatgpt_mirai_qq_bot_web_search-0.1.1.dist-info → chatgpt_mirai_qq_bot_web_search-0.1.3.dist-info}/entry_points.txt +0 -0
- {chatgpt_mirai_qq_bot_web_search-0.1.1.dist-info → chatgpt_mirai_qq_bot_web_search-0.1.3.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: chatgpt-mirai-qq-bot-web-search
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.3
|
4
4
|
Summary: WebSearch adapter for lss233/chatgpt-mirai-qq-bot
|
5
5
|
Home-page: https://github.com/chuanSir123/web_search
|
6
6
|
Author: chuanSir
|
@@ -40,9 +40,9 @@ pip install chatgpt-mirai-qq-bot-web-search
|
|
40
40
|
|
41
41
|
## 使用
|
42
42
|
|
43
|
-
在 chatgpt-mirai-qq-bot的web_ui中配置
|
44
|
-
|
45
|
-
|
43
|
+
在 chatgpt-mirai-qq-bot的web_ui中配置
|
44
|
+
使用示例请参考 [example/normal.yml](example/normal.yml)
|
45
|
+
工作流请参考 [示例图片](example/workflow.png)
|
46
46
|
|
47
47
|
## 开源协议
|
48
48
|
|
@@ -0,0 +1,10 @@
|
|
1
|
+
web_search/__init__.py,sha256=ei3SAS9emIVcOnsaDa0-AJmys2_LmSnZJt1Qdowtc4M,3471
|
2
|
+
web_search/blocks.py,sha256=bVLn5kg-OMqWQsDrJLvA43AoV_eMEcZ3nrjqponHHX4,3611
|
3
|
+
web_search/config.py,sha256=DhLiERBJR2V5Boglf7Aq9Rbc4vsvLIh67CrLDIPeqA0,398
|
4
|
+
web_search/web_searcher.py,sha256=dmN1R4iyFvaPNpyBjFLWujvQ6_I3oD1GRlRyC03egpo,9707
|
5
|
+
chatgpt_mirai_qq_bot_web_search-0.1.3.dist-info/LICENSE,sha256=ILBn-G3jdarm2w8oOrLmXeJNU3czuJvVhDLBASWdhM8,34522
|
6
|
+
chatgpt_mirai_qq_bot_web_search-0.1.3.dist-info/METADATA,sha256=radm_lXkf-z_A9ZmROTLHEgFbSiE0TN4p1bxj6-bhz8,1902
|
7
|
+
chatgpt_mirai_qq_bot_web_search-0.1.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
8
|
+
chatgpt_mirai_qq_bot_web_search-0.1.3.dist-info/entry_points.txt,sha256=o3kRDSdSmSdnCKlK6qS57aN0WpI4ab-Nxub2NwUrjf0,64
|
9
|
+
chatgpt_mirai_qq_bot_web_search-0.1.3.dist-info/top_level.txt,sha256=PoNm8MJYw_y8RTMaNlY0ePLoNHxVUAE2IHDuL5fFubI,11
|
10
|
+
chatgpt_mirai_qq_bot_web_search-0.1.3.dist-info/RECORD,,
|
web_search/__init__.py
CHANGED
@@ -9,16 +9,21 @@ from framework.workflow.core.block import BlockRegistry
|
|
9
9
|
from .blocks import WebSearchBlock
|
10
10
|
from .blocks import AppendSystemPromptBlock
|
11
11
|
from framework.ioc.inject import Inject
|
12
|
-
|
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
|
13
15
|
logger = get_logger("WebSearch")
|
14
|
-
|
16
|
+
import importlib.resources
|
17
|
+
import os
|
18
|
+
from pathlib import Path
|
15
19
|
class WebSearchPlugin(Plugin):
|
16
|
-
def __init__(self, block_registry: BlockRegistry
|
20
|
+
def __init__(self, block_registry: BlockRegistry , container: DependencyContainer):
|
17
21
|
super().__init__()
|
18
22
|
self.web_search_config = WebSearchConfig()
|
19
23
|
self.searcher = None
|
20
24
|
self.block_registry = block_registry
|
21
|
-
|
25
|
+
self.workflow_registry = container.resolve(WorkflowRegistry)
|
26
|
+
self.container=container
|
22
27
|
def on_load(self):
|
23
28
|
logger.info("WebSearchPlugin loading")
|
24
29
|
|
@@ -31,7 +36,21 @@ class WebSearchPlugin(Plugin):
|
|
31
36
|
self.block_registry.register("append_systemPrompt", "internal", AppendSystemPromptBlock)
|
32
37
|
except Exception as e:
|
33
38
|
logger.warning(f"WebSearchPlugin failed: {e}")
|
39
|
+
# 获取当前文件的绝对路径
|
40
|
+
with importlib.resources.path('your_package_name', '__init__.py') as p:
|
41
|
+
package_path = p.parent
|
42
|
+
example_dir = package_path / 'example'
|
43
|
+
|
44
|
+
# 确保目录存在
|
45
|
+
if not example_dir.exists():
|
46
|
+
raise FileNotFoundError(f"Example directory not found at {example_dir}")
|
34
47
|
|
48
|
+
# 获取所有yaml文件
|
49
|
+
yaml_files = list(example_dir.glob('*.yaml')) + list(example_dir.glob('*.yml'))
|
50
|
+
|
51
|
+
for yaml in yaml_files:
|
52
|
+
logger.info(os.path.join(example_dir, yaml))
|
53
|
+
self.workflow_registry.register("search", os.path.splitext(yaml)[0], WorkflowBuilder.load_from_yaml(os.path.join(example_dir, yaml), self.container))
|
35
54
|
@dataclass
|
36
55
|
class WebSearchEvent:
|
37
56
|
"""Web搜索事件"""
|
@@ -61,48 +80,6 @@ class WebSearchPlugin(Plugin):
|
|
61
80
|
|
62
81
|
logger.info("WebSearchPlugin stopped")
|
63
82
|
|
64
|
-
def get_actions(self) -> List[str]:
|
65
|
-
return ["web_search"]
|
66
|
-
|
67
|
-
def get_action_params(self, action: str) -> Dict[str, Any]:
|
68
|
-
if action == "web_search":
|
69
|
-
return {
|
70
|
-
"query": "搜索关键词"
|
71
|
-
}
|
72
|
-
raise ValueError(f"Unknown action: {action}")
|
73
|
-
|
74
|
-
async def execute(self, action: str, params: Dict[str, Any]) -> Dict[str, Any]:
|
75
|
-
if action == "web_search":
|
76
|
-
return await self._do_search(params)
|
77
|
-
raise ValueError(f"Unknown action: {action}")
|
78
|
-
|
79
|
-
async def _do_search(self, params: Dict[str, Any]) -> Dict[str, Any]:
|
80
|
-
query = params.get("query")
|
81
|
-
if not query:
|
82
|
-
return {
|
83
|
-
"success": False,
|
84
|
-
"message": "搜索关键词为空"
|
85
|
-
}
|
86
|
-
|
87
|
-
try:
|
88
|
-
await self._initialize_searcher()
|
89
|
-
results = await self.searcher.search(
|
90
|
-
query,
|
91
|
-
max_results=self.web_search_config.max_results,
|
92
|
-
timeout=self.web_search_config.timeout,
|
93
|
-
fetch_content=self.web_search_config.fetch_content
|
94
|
-
)
|
95
|
-
return {
|
96
|
-
"success": True,
|
97
|
-
"results": results
|
98
|
-
}
|
99
|
-
except Exception as e:
|
100
|
-
logger.error(f"Search failed: {e}")
|
101
|
-
return {
|
102
|
-
"success": False,
|
103
|
-
"message": f"搜索失败: {str(e)}"
|
104
|
-
}
|
105
|
-
|
106
83
|
async def _initialize_searcher(self):
|
107
84
|
"""初始化搜索器"""
|
108
85
|
if self.searcher is None:
|
web_search/blocks.py
CHANGED
@@ -12,11 +12,11 @@ class WebSearchBlock(Block):
|
|
12
12
|
name = "web_search"
|
13
13
|
|
14
14
|
inputs = {
|
15
|
-
"llm_resp": Input("llm_resp", LLMChatResponse, "搜索关键词")
|
15
|
+
"llm_resp": Input(name="llm_resp",label="LLM 响应", data_type=LLMChatResponse, description="搜索关键词")
|
16
16
|
}
|
17
17
|
|
18
18
|
outputs = {
|
19
|
-
"results": Output("results", str, "搜索结果")
|
19
|
+
"results": Output(name="results",label="搜索结果",data_type= str, description="搜索结果")
|
20
20
|
}
|
21
21
|
|
22
22
|
def __init__(self, name: str = None, max_results: Optional[int] = None, timeout: Optional[int] = None, fetch_content: Optional[bool] = None):
|
@@ -74,12 +74,12 @@ class AppendSystemPromptBlock(Block):
|
|
74
74
|
name = "append_system_prompt"
|
75
75
|
|
76
76
|
inputs = {
|
77
|
-
"results": Input("results", str, "搜索结果"),
|
78
|
-
"messages": Input("messages", List[LLMChatMessage], "消息列表")
|
77
|
+
"results": Input(name="results",label="工具结果", data_type=str, description ="搜索结果"),
|
78
|
+
"messages": Input(name="messages",label="LLM 响应", data_type=List[LLMChatMessage],description = "消息列表")
|
79
79
|
}
|
80
80
|
|
81
81
|
outputs = {
|
82
|
-
"messages": Output("messages", List[LLMChatMessage], "更新后的消息列表")
|
82
|
+
"messages": Output(name="messages", label="拼装后的 llm 响应",data_type=List[LLMChatMessage], description = "更新后的消息列表")
|
83
83
|
}
|
84
84
|
|
85
85
|
def execute(self, **kwargs) -> Dict[str, Any]:
|
@@ -1,10 +0,0 @@
|
|
1
|
-
web_search/__init__.py,sha256=ccgh1E66PTLOIPMPqb70dbEQ7ghkBlW8WOmtip7Vnmc,3741
|
2
|
-
web_search/blocks.py,sha256=uQVOlpuYpWKoAawT9r0MwOWxH2wS5JfQSFpkUjoNEwU,3360
|
3
|
-
web_search/config.py,sha256=DhLiERBJR2V5Boglf7Aq9Rbc4vsvLIh67CrLDIPeqA0,398
|
4
|
-
web_search/web_searcher.py,sha256=dmN1R4iyFvaPNpyBjFLWujvQ6_I3oD1GRlRyC03egpo,9707
|
5
|
-
chatgpt_mirai_qq_bot_web_search-0.1.1.dist-info/LICENSE,sha256=ILBn-G3jdarm2w8oOrLmXeJNU3czuJvVhDLBASWdhM8,34522
|
6
|
-
chatgpt_mirai_qq_bot_web_search-0.1.1.dist-info/METADATA,sha256=JTDtUxDOc5L71KbW3Zfo32TF5tE5XntkBSQ86dKLfVw,1782
|
7
|
-
chatgpt_mirai_qq_bot_web_search-0.1.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
8
|
-
chatgpt_mirai_qq_bot_web_search-0.1.1.dist-info/entry_points.txt,sha256=o3kRDSdSmSdnCKlK6qS57aN0WpI4ab-Nxub2NwUrjf0,64
|
9
|
-
chatgpt_mirai_qq_bot_web_search-0.1.1.dist-info/top_level.txt,sha256=PoNm8MJYw_y8RTMaNlY0ePLoNHxVUAE2IHDuL5fFubI,11
|
10
|
-
chatgpt_mirai_qq_bot_web_search-0.1.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|