chatgpt-mirai-qq-bot-web-search 0.1.15__py3-none-any.whl → 0.2.1__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.1
2
2
  Name: chatgpt-mirai-qq-bot-web-search
3
- Version: 0.1.15
3
+ Version: 0.2.1
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
@@ -0,0 +1,11 @@
1
+ web_search/__init__.py,sha256=zVZLb5A-im5XETwohgxyE-UCxjSvYl6I2OC3LnEQhdQ,4360
2
+ web_search/blocks.py,sha256=S3RsV9CCTKAsKUNhewg__ejEpJRDz7DTawtH05WRgE8,6732
3
+ web_search/config.py,sha256=DhLiERBJR2V5Boglf7Aq9Rbc4vsvLIh67CrLDIPeqA0,398
4
+ web_search/web_searcher.py,sha256=0zLgMsWCK71gStyWpFjup5WfxHx3tBTf3rGwM7Ae7Zs,13332
5
+ web_search/example/roleplayWithWebSearch.yaml,sha256=C-dGy3z8gcRcmxzurssP-kPRLqMf1TYR-nnNUaJjISE,7468
6
+ chatgpt_mirai_qq_bot_web_search-0.2.1.dist-info/LICENSE,sha256=ILBn-G3jdarm2w8oOrLmXeJNU3czuJvVhDLBASWdhM8,34522
7
+ chatgpt_mirai_qq_bot_web_search-0.2.1.dist-info/METADATA,sha256=Gt59c1F8TCJFClQ0qqdMvrCQ2gpeHHcIVH9cbVli-zw,1738
8
+ chatgpt_mirai_qq_bot_web_search-0.2.1.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
9
+ chatgpt_mirai_qq_bot_web_search-0.2.1.dist-info/entry_points.txt,sha256=o3kRDSdSmSdnCKlK6qS57aN0WpI4ab-Nxub2NwUrjf0,64
10
+ chatgpt_mirai_qq_bot_web_search-0.2.1.dist-info/top_level.txt,sha256=PoNm8MJYw_y8RTMaNlY0ePLoNHxVUAE2IHDuL5fFubI,11
11
+ chatgpt_mirai_qq_bot_web_search-0.2.1.dist-info/RECORD,,
web_search/blocks.py CHANGED
@@ -12,7 +12,6 @@ def get_options_provider(container: DependencyContainer, block: Block) -> List[s
12
12
  class WebSearchBlock(Block):
13
13
  """Web搜索Block"""
14
14
  name = "web_search"
15
-
16
15
  inputs = {
17
16
  "llm_resp": Input(name="llm_resp",label="LLM 响应", data_type=LLMChatResponse, description="搜索关键词")
18
17
  }
@@ -21,7 +20,7 @@ class WebSearchBlock(Block):
21
20
  "results": Output(name="results",label="搜索结果",data_type= str, description="搜索结果")
22
21
  }
23
22
 
24
- def __init__(self, name: str = None, max_results: Optional[int] = None, timeout: Optional[int] = None, fetch_content: Optional[bool] = None
23
+ def __init__(self, name: str = None, max_results: Optional[int] = 3, timeout: Optional[int] = 10, fetch_content: Optional[bool] = True
25
24
  ,engine: Annotated[Optional[str],ParamMeta(label="搜索引擎", description="要使用的搜索引擎", options_provider=get_options_provider),] = "bing", proxy: str = None,):
26
25
  super().__init__(name)
27
26
  self.searcher = None
@@ -54,6 +53,73 @@ class WebSearchBlock(Block):
54
53
  fetch_content = self.fetch_content
55
54
  self._ensure_searcher()
56
55
 
56
+ try:
57
+ # 在新线程中创建事件循环
58
+ try:
59
+ loop = asyncio.get_event_loop()
60
+ except RuntimeError:
61
+ loop = asyncio.new_event_loop()
62
+ asyncio.set_event_loop(loop)
63
+
64
+ results = loop.run_until_complete(
65
+ self.searcher.search(
66
+ query=query,
67
+ max_results=max_results,
68
+ timeout=timeout,
69
+ fetch_content=fetch_content,
70
+ engine=self.engine,
71
+ proxy = self.proxy,
72
+ )
73
+ )
74
+ return {"results": "\n以下是联网搜索的结果:\n-- 搜索结果开始 --"+results+"\n-- 搜索结果结束 --"}
75
+ except Exception as e:
76
+ print(e)
77
+ return {"results": f"搜索失败: {str(e)}"}
78
+ class WebSearchByKeywordBlock(Block):
79
+ """Web搜索Block"""
80
+ name = "web_search_by_keyword"
81
+ description = "网络搜索,通过关键词进行网络搜索"
82
+
83
+ inputs = {
84
+ "keyword": Input(name="keyword",label="搜索关键字", data_type=str, description="搜索关键词")
85
+ }
86
+
87
+ outputs = {
88
+ "results": Output(name="results",label="搜索结果",data_type= str, description="搜索结果")
89
+ }
90
+
91
+ def __init__(self, name: str = None, max_results: Optional[int] = 3, timeout: Optional[int] = 10, fetch_content: Optional[bool] = True
92
+ ,engine: Annotated[Optional[str],ParamMeta(label="搜索引擎", description="要使用的搜索引擎", options_provider=get_options_provider),] = "bing", proxy: str = None,):
93
+ super().__init__(name)
94
+ self.searcher = None
95
+ self.config = WebSearchConfig()
96
+ self.max_results = max_results
97
+ self.timeout = timeout
98
+ self.fetch_content = fetch_content
99
+ self.engine=engine
100
+ self.proxy = proxy
101
+
102
+ def _ensure_searcher(self):
103
+ """同步方式初始化searcher"""
104
+ if not self.searcher:
105
+ try:
106
+ loop = asyncio.get_event_loop()
107
+ except RuntimeError:
108
+ # 如果在新线程中没有事件循环,则创建一个新的
109
+ loop = asyncio.new_event_loop()
110
+ asyncio.set_event_loop(loop)
111
+ self.searcher = loop.run_until_complete(WebSearcher.create())
112
+
113
+ def execute(self, **kwargs) -> Dict[str, Any]:
114
+ query = kwargs["keyword"]
115
+
116
+ if query == "" or query.startswith("无"):
117
+ return {"results": ""}
118
+ max_results = self.max_results
119
+ timeout = self.timeout
120
+ fetch_content = self.fetch_content
121
+ self._ensure_searcher()
122
+
57
123
  try:
58
124
  # 在新线程中创建事件循环
59
125
  try:
@@ -1,11 +0,0 @@
1
- web_search/__init__.py,sha256=zVZLb5A-im5XETwohgxyE-UCxjSvYl6I2OC3LnEQhdQ,4360
2
- web_search/blocks.py,sha256=I0nq2JzWi1whkJCO8aS76qus_V9Z-TSvL1kjd9AZKa4,4093
3
- web_search/config.py,sha256=DhLiERBJR2V5Boglf7Aq9Rbc4vsvLIh67CrLDIPeqA0,398
4
- web_search/web_searcher.py,sha256=0zLgMsWCK71gStyWpFjup5WfxHx3tBTf3rGwM7Ae7Zs,13332
5
- web_search/example/roleplayWithWebSearch.yaml,sha256=C-dGy3z8gcRcmxzurssP-kPRLqMf1TYR-nnNUaJjISE,7468
6
- chatgpt_mirai_qq_bot_web_search-0.1.15.dist-info/LICENSE,sha256=ILBn-G3jdarm2w8oOrLmXeJNU3czuJvVhDLBASWdhM8,34522
7
- chatgpt_mirai_qq_bot_web_search-0.1.15.dist-info/METADATA,sha256=FE3NIJ3yYwk9bgVF55Q4vm8BnmAsqUkubuaOwY64XpU,1739
8
- chatgpt_mirai_qq_bot_web_search-0.1.15.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
9
- chatgpt_mirai_qq_bot_web_search-0.1.15.dist-info/entry_points.txt,sha256=o3kRDSdSmSdnCKlK6qS57aN0WpI4ab-Nxub2NwUrjf0,64
10
- chatgpt_mirai_qq_bot_web_search-0.1.15.dist-info/top_level.txt,sha256=PoNm8MJYw_y8RTMaNlY0ePLoNHxVUAE2IHDuL5fFubI,11
11
- chatgpt_mirai_qq_bot_web_search-0.1.15.dist-info/RECORD,,