chatgpt-mirai-qq-bot-web-search 0.2.10__tar.gz → 0.2.12__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.
Files changed (16) hide show
  1. {chatgpt-mirai-qq-bot-web-search-0.2.10 → chatgpt-mirai-qq-bot-web-search-0.2.12}/PKG-INFO +1 -1
  2. {chatgpt-mirai-qq-bot-web-search-0.2.10 → chatgpt-mirai-qq-bot-web-search-0.2.12}/chatgpt_mirai_qq_bot_web_search.egg-info/PKG-INFO +1 -1
  3. {chatgpt-mirai-qq-bot-web-search-0.2.10 → chatgpt-mirai-qq-bot-web-search-0.2.12}/setup.py +1 -1
  4. {chatgpt-mirai-qq-bot-web-search-0.2.10 → chatgpt-mirai-qq-bot-web-search-0.2.12}/web_search/__init__.py +4 -2
  5. {chatgpt-mirai-qq-bot-web-search-0.2.10 → chatgpt-mirai-qq-bot-web-search-0.2.12}/web_search/web_searcher.py +7 -8
  6. {chatgpt-mirai-qq-bot-web-search-0.2.10 → chatgpt-mirai-qq-bot-web-search-0.2.12}/LICENSE +0 -0
  7. {chatgpt-mirai-qq-bot-web-search-0.2.10 → chatgpt-mirai-qq-bot-web-search-0.2.12}/README.md +0 -0
  8. {chatgpt-mirai-qq-bot-web-search-0.2.10 → chatgpt-mirai-qq-bot-web-search-0.2.12}/chatgpt_mirai_qq_bot_web_search.egg-info/SOURCES.txt +0 -0
  9. {chatgpt-mirai-qq-bot-web-search-0.2.10 → chatgpt-mirai-qq-bot-web-search-0.2.12}/chatgpt_mirai_qq_bot_web_search.egg-info/dependency_links.txt +0 -0
  10. {chatgpt-mirai-qq-bot-web-search-0.2.10 → chatgpt-mirai-qq-bot-web-search-0.2.12}/chatgpt_mirai_qq_bot_web_search.egg-info/entry_points.txt +0 -0
  11. {chatgpt-mirai-qq-bot-web-search-0.2.10 → chatgpt-mirai-qq-bot-web-search-0.2.12}/chatgpt_mirai_qq_bot_web_search.egg-info/requires.txt +0 -0
  12. {chatgpt-mirai-qq-bot-web-search-0.2.10 → chatgpt-mirai-qq-bot-web-search-0.2.12}/chatgpt_mirai_qq_bot_web_search.egg-info/top_level.txt +0 -0
  13. {chatgpt-mirai-qq-bot-web-search-0.2.10 → chatgpt-mirai-qq-bot-web-search-0.2.12}/setup.cfg +0 -0
  14. {chatgpt-mirai-qq-bot-web-search-0.2.10 → chatgpt-mirai-qq-bot-web-search-0.2.12}/web_search/blocks.py +0 -0
  15. {chatgpt-mirai-qq-bot-web-search-0.2.10 → chatgpt-mirai-qq-bot-web-search-0.2.12}/web_search/config.py +0 -0
  16. {chatgpt-mirai-qq-bot-web-search-0.2.10 → chatgpt-mirai-qq-bot-web-search-0.2.12}/web_search/example/roleplayWithWebSearch.yaml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chatgpt-mirai-qq-bot-web-search
3
- Version: 0.2.10
3
+ Version: 0.2.12
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chatgpt-mirai-qq-bot-web-search
3
- Version: 0.2.10
3
+ Version: 0.2.12
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
@@ -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.2.10'
5
+ version = os.environ.get('RELEASE_VERSION', '0.2.12'
6
6
  '').lstrip('v')
7
7
 
8
8
  setup(
@@ -45,7 +45,8 @@ class WebSearchPlugin(Plugin):
45
45
  )
46
46
  stdout, stderr = process.communicate()
47
47
  if process.returncode != 0:
48
- raise RuntimeError(f"Failed to install playwright browsers: {stderr.stderr}")
48
+ logger.error(f"Failed to install playwright browsers: {stderr}")
49
+ raise RuntimeError(f"Failed to install playwright browsers: {stderr}")
49
50
  except Exception as e:
50
51
  logger.info("Installing playwright browsers...")
51
52
  process = subprocess.Popen(
@@ -55,7 +56,8 @@ class WebSearchPlugin(Plugin):
55
56
  )
56
57
  stdout, stderr = process.communicate()
57
58
  if process.returncode != 0:
58
- raise RuntimeError(f"Failed to install playwright browsers: {stderr.stderr}")
59
+ logger.error(f"Failed to install playwright browsers: {stderr}")
60
+ raise RuntimeError(f"Failed to install playwright browsers: {stderr}")
59
61
  # 注册Block
60
62
  try:
61
63
  self.block_registry.register("web_search", "search", WebSearchBlock)
@@ -163,9 +163,9 @@ class WebSearcher:
163
163
  # 创建新标签页获取内容
164
164
  page = await context.new_page()
165
165
  try:
166
- # 修改资源加载策略,允许加载必要的CSS
166
+ # 设置更严格的资源加载策略
167
167
  await page.route("**/*", lambda route: route.abort()
168
- if route.request.resource_type in ['image', 'font', 'media'] # 移除 'stylesheet'
168
+ if route.request.resource_type in ['image', 'stylesheet', 'font', 'media']
169
169
  else route.continue_())
170
170
 
171
171
  # 使用 domcontentloaded 而不是 networkidle
@@ -263,8 +263,6 @@ class WebSearcher:
263
263
 
264
264
  # 使用搜索引擎特定的选择器
265
265
  results = None
266
- # 等待页面稳定
267
- await asyncio.sleep(2) # 添加短暂延迟
268
266
 
269
267
  # 对于Google,让页面有更多时间加载
270
268
  if engine == 'google':
@@ -344,9 +342,10 @@ class WebSearcher:
344
342
  logger.error(f"Search failed - Query: {query} - Error: {e}", exc_info=True)
345
343
  return f"搜索失败: {str(e)}"
346
344
  finally:
347
- if page:
345
+ if context:
348
346
  try:
349
- await page.close()
347
+ logger.debug("context.close")
348
+ await context.close()
350
349
  except Exception as e:
351
350
  logger.error(f"Error closing page: {e}")
352
351
 
@@ -491,8 +490,8 @@ class WebSearcher:
491
490
  logger.error(f"抖音视频搜索失败 - 关键词: {keyword} - 错误: {e}", exc_info=True)
492
491
  return f"搜索失败: {str(e)}"
493
492
  finally:
494
- if page:
493
+ if context:
495
494
  try:
496
- await page.close()
495
+ await context.close()
497
496
  except Exception as e:
498
497
  logger.error(f"关闭页面错误: {e}")