chatgpt-mirai-qq-bot-web-search 0.1.1__py3-none-any.whl → 0.1.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: chatgpt-mirai-qq-bot-web-search
3
- Version: 0.1.1
3
+ Version: 0.1.2
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=PrzhpRF8sNgqQohDWxZLvtSdjpg1wUQqHQ6osk5S_lw,3438
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.2.dist-info/LICENSE,sha256=ILBn-G3jdarm2w8oOrLmXeJNU3czuJvVhDLBASWdhM8,34522
6
+ chatgpt_mirai_qq_bot_web_search-0.1.2.dist-info/METADATA,sha256=XYlA28-QArWVBBWfwcH0Um223uO-tJuzfFhHnS5wBTE,1902
7
+ chatgpt_mirai_qq_bot_web_search-0.1.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
8
+ chatgpt_mirai_qq_bot_web_search-0.1.2.dist-info/entry_points.txt,sha256=o3kRDSdSmSdnCKlK6qS57aN0WpI4ab-Nxub2NwUrjf0,64
9
+ chatgpt_mirai_qq_bot_web_search-0.1.2.dist-info/top_level.txt,sha256=PoNm8MJYw_y8RTMaNlY0ePLoNHxVUAE2IHDuL5fFubI,11
10
+ chatgpt_mirai_qq_bot_web_search-0.1.2.dist-info/RECORD,,
web_search/__init__.py CHANGED
@@ -9,16 +9,20 @@ 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 os
17
+ import os
15
18
  class WebSearchPlugin(Plugin):
16
- def __init__(self, block_registry: BlockRegistry = Inject()):
19
+ def __init__(self, block_registry: BlockRegistry , container: DependencyContainer):
17
20
  super().__init__()
18
21
  self.web_search_config = WebSearchConfig()
19
22
  self.searcher = None
20
23
  self.block_registry = block_registry
21
-
24
+ self.workflow_registry = container.resolve(WorkflowRegistry)
25
+ self.container=container
22
26
  def on_load(self):
23
27
  logger.info("WebSearchPlugin loading")
24
28
 
@@ -31,7 +35,23 @@ class WebSearchPlugin(Plugin):
31
35
  self.block_registry.register("append_systemPrompt", "internal", AppendSystemPromptBlock)
32
36
  except Exception as e:
33
37
  logger.warning(f"WebSearchPlugin failed: {e}")
38
+ # 获取当前文件的绝对路径
39
+ current_file = os.path.abspath(__file__)
40
+
41
+ # 获取当前文件所在目录
42
+ current_dir = os.path.dirname(current_file)
43
+
44
+ # 获取上级目录
45
+ parent_dir = os.path.dirname(current_dir)
34
46
 
47
+ # 构建 example 目录的路径
48
+ example_dir = os.path.join(parent_dir, 'example')
49
+ # 获取 example 目录下所有的 yaml 文件
50
+ yaml_files = [f for f in os.listdir(example_dir) if f.endswith('.yaml') or f.endswith('.yml')]
51
+
52
+ for yaml in yaml_files:
53
+ logger.info(os.path.join(example_dir, yaml))
54
+ self.workflow_registry.register("search", os.path.splitext(yaml)[0], WorkflowBuilder.load_from_yaml(os.path.join(example_dir, yaml), self.container))
35
55
  @dataclass
36
56
  class WebSearchEvent:
37
57
  """Web搜索事件"""
@@ -61,48 +81,6 @@ class WebSearchPlugin(Plugin):
61
81
 
62
82
  logger.info("WebSearchPlugin stopped")
63
83
 
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
84
  async def _initialize_searcher(self):
107
85
  """初始化搜索器"""
108
86
  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,,