entari-plugin-hyw 4.0.0rc4__py3-none-any.whl → 4.0.0rc6__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.

Potentially problematic release.


This version of entari-plugin-hyw might be problematic. Click here for more details.

Files changed (30) hide show
  1. entari_plugin_hyw/__init__.py +216 -75
  2. entari_plugin_hyw/assets/card-dist/index.html +70 -79
  3. entari_plugin_hyw/browser/__init__.py +10 -0
  4. entari_plugin_hyw/browser/engines/base.py +13 -0
  5. entari_plugin_hyw/browser/engines/bing.py +95 -0
  6. entari_plugin_hyw/browser/engines/duckduckgo.py +137 -0
  7. entari_plugin_hyw/browser/engines/google.py +155 -0
  8. entari_plugin_hyw/browser/landing.html +172 -0
  9. entari_plugin_hyw/browser/manager.py +153 -0
  10. entari_plugin_hyw/browser/service.py +304 -0
  11. entari_plugin_hyw/card-ui/src/App.vue +526 -182
  12. entari_plugin_hyw/card-ui/src/components/MarkdownContent.vue +7 -11
  13. entari_plugin_hyw/card-ui/src/components/StageCard.vue +33 -30
  14. entari_plugin_hyw/card-ui/src/types.ts +9 -0
  15. entari_plugin_hyw/definitions.py +155 -0
  16. entari_plugin_hyw/history.py +111 -33
  17. entari_plugin_hyw/misc.py +34 -0
  18. entari_plugin_hyw/modular_pipeline.py +384 -0
  19. entari_plugin_hyw/render_vue.py +326 -239
  20. entari_plugin_hyw/search.py +95 -708
  21. entari_plugin_hyw/stage_base.py +92 -0
  22. entari_plugin_hyw/stage_instruct.py +345 -0
  23. entari_plugin_hyw/stage_instruct_deepsearch.py +104 -0
  24. entari_plugin_hyw/stage_summary.py +164 -0
  25. {entari_plugin_hyw-4.0.0rc4.dist-info → entari_plugin_hyw-4.0.0rc6.dist-info}/METADATA +4 -4
  26. {entari_plugin_hyw-4.0.0rc4.dist-info → entari_plugin_hyw-4.0.0rc6.dist-info}/RECORD +28 -16
  27. entari_plugin_hyw/pipeline.py +0 -1219
  28. entari_plugin_hyw/prompts.py +0 -47
  29. {entari_plugin_hyw-4.0.0rc4.dist-info → entari_plugin_hyw-4.0.0rc6.dist-info}/WHEEL +0 -0
  30. {entari_plugin_hyw-4.0.0rc4.dist-info → entari_plugin_hyw-4.0.0rc6.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,164 @@
1
+ """
2
+ Summary Stage
3
+
4
+ Generates final response based on gathered information.
5
+ Different output formats for different modes.
6
+ """
7
+
8
+ import time
9
+ import re
10
+ from typing import Any, Dict, List, Optional
11
+
12
+ from loguru import logger
13
+ from openai import AsyncOpenAI
14
+
15
+ from .stage_base import BaseStage, StageContext, StageResult
16
+ from .definitions import SUMMARY_REPORT_SP
17
+
18
+
19
+ class SummaryStage(BaseStage):
20
+ """
21
+ Summary Stage: Generate final response.
22
+ """
23
+
24
+ @property
25
+ def name(self) -> str:
26
+ return "Summary"
27
+
28
+ async def execute(
29
+ self,
30
+ context: StageContext,
31
+ images: List[str] = None
32
+ ) -> StageResult:
33
+ """Generate summary."""
34
+ start_time = time.time()
35
+
36
+ # Format context from web results
37
+ web_content = self._format_web_content(context)
38
+ full_context = f"{context.agent_context}\n\n{web_content}"
39
+
40
+ # Select prompt
41
+ language = getattr(self.config, "language", "Simplified Chinese")
42
+
43
+ system_prompt = SUMMARY_REPORT_SP.format(
44
+ language=language
45
+ )
46
+
47
+ # Build Context Message
48
+ context_message = f"## Web Search & Page Content\n\n```context\n{full_context}\n```"
49
+
50
+ # Build user content
51
+ user_text = context.user_input or "..."
52
+ if images:
53
+ user_content: List[Dict[str, Any]] = [{"type": "text", "text": user_text}]
54
+ for img_b64 in images:
55
+ url = f"data:image/jpeg;base64,{img_b64}" if not img_b64.startswith("data:") else img_b64
56
+ user_content.append({"type": "image_url", "image_url": {"url": url}})
57
+ else:
58
+ user_content = user_text
59
+
60
+ messages = [
61
+ {"role": "system", "content": system_prompt},
62
+ {"role": "user", "content": context_message},
63
+ {"role": "user", "content": user_content}
64
+ ]
65
+
66
+ # Get model config
67
+ model_cfg = self.config.get_model_config("main")
68
+
69
+ client = self._client_for(
70
+ api_key=model_cfg.get("api_key"),
71
+ base_url=model_cfg.get("base_url")
72
+ )
73
+
74
+ model = model_cfg.get("model_name") or self.config.model_name
75
+
76
+ try:
77
+ response = await client.chat.completions.create(
78
+ model=model,
79
+ messages=messages,
80
+ temperature=self.config.temperature,
81
+ extra_body=getattr(self.config, "summary_extra_body", None),
82
+ )
83
+ except Exception as e:
84
+ logger.error(f"SummaryStage LLM error: {e}")
85
+ return StageResult(
86
+ success=False,
87
+ error=str(e),
88
+ data={"content": f"Error generating summary: {e}"}
89
+ )
90
+
91
+ usage = {"input_tokens": 0, "output_tokens": 0}
92
+ if hasattr(response, "usage") and response.usage:
93
+ usage["input_tokens"] = getattr(response.usage, "prompt_tokens", 0) or 0
94
+ usage["output_tokens"] = getattr(response.usage, "completion_tokens", 0) or 0
95
+
96
+ content = (response.choices[0].message.content or "").strip()
97
+
98
+ return StageResult(
99
+ success=True,
100
+ data={"content": content},
101
+ usage=usage,
102
+ trace={
103
+ "model": model,
104
+ "provider": model_cfg.get("model_provider") or "Unknown",
105
+ "usage": usage,
106
+ "system_prompt": system_prompt,
107
+ "output": content,
108
+ "time": time.time() - start_time,
109
+ "images_count": len(images) if images else 0,
110
+ }
111
+ )
112
+
113
+ def _strip_links(self, text: str) -> str:
114
+ """Strip markdown links [text](url) -> text and remove bare URLs."""
115
+ # Replace [text](url) with text
116
+ text = re.sub(r'\[([^\]]+)\]\([^\)]+\)', r'\1', text)
117
+ # Remove bare URLs (http/https) roughly, trying to preserve surrounding text if possible?
118
+ # A simple pattern for http/s
119
+ text = re.sub(r'https?://\S+', '', text)
120
+ return text
121
+
122
+ def _format_web_content(self, context: StageContext) -> str:
123
+ """Format web results for summary prompt."""
124
+ if not context.web_results:
125
+ return ""
126
+
127
+ # Sort results: pages first, then raw searches, then snippets
128
+ def get_priority(item_type):
129
+ if item_type == "page": return 0
130
+ if item_type == "search_raw_page": return 1
131
+ return 2 # search (snippets)
132
+
133
+ sorted_results = sorted(
134
+ context.web_results,
135
+ key=lambda x: get_priority(x.get("_type"))
136
+ )
137
+
138
+ lines = []
139
+ seen_urls = set()
140
+
141
+ for res in sorted_results:
142
+ type_ = res.get("_type")
143
+ idx = res.get("_id")
144
+ title = (res.get("title", "") or "").strip()
145
+ url = res.get("url", "")
146
+
147
+ # Deduplicate items by URL (keep higher priority item only)
148
+ if url:
149
+ if url in seen_urls:
150
+ continue
151
+ seen_urls.add(url)
152
+
153
+ # url = res.get("url", "") # Removed as requested
154
+
155
+ if type_ == "page":
156
+ content = (res.get("content", "") or "").strip()
157
+ content = self._strip_links(content)
158
+ lines.append(f"[{idx}] Title: {title}\nContent:\n{content}\n")
159
+ elif type_ == "search":
160
+ snippet = (res.get("content", "") or "").strip()
161
+ snippet = self._strip_links(snippet)
162
+ lines.append(f"[{idx}] Title: {title}\nSnippet: {snippet}\n")
163
+
164
+ return "\n".join(lines)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: entari_plugin_hyw
3
- Version: 4.0.0rc4
3
+ Version: 4.0.0rc6
4
4
  Summary: Use large language models to interpret chat messages
5
5
  Author-email: kumoSleeping <zjr2992@outlook.com>
6
6
  License: MIT
@@ -20,9 +20,9 @@ Requires-Dist: arclet-entari[full]>=0.16.5
20
20
  Requires-Dist: openai
21
21
  Requires-Dist: httpx
22
22
  Requires-Dist: markdown>=3.10
23
- Requires-Dist: crawl4ai>=0.7.8
24
- Requires-Dist: jinja2>=3.0
25
- Requires-Dist: ddgs>=9.10.0
23
+ Requires-Dist: DrissionPage>=4.1.1.2
24
+ Requires-Dist: trafilatura>=1.6.0
25
+ Requires-Dist: json-repair>=0.55.0
26
26
  Provides-Extra: dev
27
27
  Requires-Dist: entari-plugin-server>=0.5.0; extra == "dev"
28
28
  Requires-Dist: satori-python-adapter-onebot11>=0.2.5; extra == "dev"
@@ -1,12 +1,16 @@
1
- entari_plugin_hyw/__init__.py,sha256=XRjnYDWX-dfMi33yD1CcfejHcQyySXTrQVlo95dVfis,17118
2
- entari_plugin_hyw/history.py,sha256=zYtON0FgkA_AcXerLV335OzpIP30eAxDEp7NHCFFXis,7016
1
+ entari_plugin_hyw/__init__.py,sha256=t-TAqOaghlzVtoSuMfQoiqdA8wrfB7Riofqp3EpGQPU,21844
2
+ entari_plugin_hyw/definitions.py,sha256=sRgNkmzD-XDSbRM2nVQP14WGpMoFrzr9C-cc6xmShDA,6570
3
+ entari_plugin_hyw/history.py,sha256=6d1e8DPfv4XQyM9hMjrx08_WKrxqVSJEvSIGRX4JOB0,11085
3
4
  entari_plugin_hyw/image_cache.py,sha256=t8pr1kgH2ngK9IhrBAhzUqhBWERNztUywMzgCFZEtQk,9899
4
- entari_plugin_hyw/misc.py,sha256=b0KPCUrf1GuCY0Mx29Sn5sREg1fxR1OyYEl4O4Omsys,4553
5
- entari_plugin_hyw/pipeline.py,sha256=CFp8D9OAJ3nfDsJwKNHb42ZLHYoUL5k9wykrcWC_Tno,52501
6
- entari_plugin_hyw/prompts.py,sha256=BqX8MNdBG7M6_oRAe1jCiSCgcbRchFAoWpgF9WB3-0o,2348
7
- entari_plugin_hyw/render_vue.py,sha256=cdIsvuGIC-01Nmc9vgYnGQIY5CGh_ZdqphAhFP4h0Qo,12426
8
- entari_plugin_hyw/search.py,sha256=bN958sSXYIz7fMmH_ZoS1777c1wXatV05-rvfEq_YHQ,30383
9
- entari_plugin_hyw/assets/card-dist/index.html,sha256=B5U91hlLEVK_zPNmMoB5daj475ncdRKbVxR35Xgb-Ns,2016492
5
+ entari_plugin_hyw/misc.py,sha256=ZGDXeXbSugG4tRrBfUDVd94i2SCaPOmaGtVmPz8mqtY,5413
6
+ entari_plugin_hyw/modular_pipeline.py,sha256=-p2Z4oUij-G4sCdf2SeHNm89NlVTYHuU91vUIz9R-IM,16867
7
+ entari_plugin_hyw/render_vue.py,sha256=4i5xTZCb9amPgSWo6f7Ev279ZOk-D8Kfmxe2HdcA_vI,14737
8
+ entari_plugin_hyw/search.py,sha256=2Rnc6iYIzPEFH7NtSR0Pi0eXFH-EqIia7Kh3txWmD8U,5262
9
+ entari_plugin_hyw/stage_base.py,sha256=wNotYPl8LElk-1Yf8NB2OvFeGSV2UGW9uEmlY4QmxzA,2752
10
+ entari_plugin_hyw/stage_instruct.py,sha256=2vMLfA7lVRqaPdf9szBfsN7sTAALmkNUsMyUL7tjmGA,14620
11
+ entari_plugin_hyw/stage_instruct_deepsearch.py,sha256=_I_xZ-M1xovM4I7NL5eyc21Wg9xdFKnJDQVQActTjUI,3969
12
+ entari_plugin_hyw/stage_summary.py,sha256=1g1tL7alHbDdp6Mrq2HrXD8k65VMOL-zdyo3bWAS5RQ,5736
13
+ entari_plugin_hyw/assets/card-dist/index.html,sha256=s_RU1rCFowRwFMTuIiUsyGp25WfsIyk-XNWyD9jYqVc,2204580
10
14
  entari_plugin_hyw/assets/card-dist/vite.svg,sha256=SnSK_UQ5GLsWWRyDTEAdrjPoeGGrXbrQgRw6O0qSFPs,1497
11
15
  entari_plugin_hyw/assets/card-dist/logos/anthropic.svg,sha256=ASsy1ypo3osNc3n-B0R81tk_dIFsVgg7qQORrd5T2kA,558
12
16
  entari_plugin_hyw/assets/card-dist/logos/cerebras.svg,sha256=bpmiiYTODwc06knTmPj3GQ7NNtosMog5lkggvB_Z-7M,44166
@@ -44,6 +48,14 @@ entari_plugin_hyw/assets/icon/qwen.png,sha256=eqLbnIPbjh2_PsODU_mmqjeD82xXj8fV_k
44
48
  entari_plugin_hyw/assets/icon/xai.png,sha256=uSulvvDVqoA4RUOW0ZAkdvBVM2rpyGJRZIbn5dEFspw,362
45
49
  entari_plugin_hyw/assets/icon/xiaomi.png,sha256=WHxlDFGU5FCjb-ure3ngdGG18-efYZUUfqA3_lqCUN0,4084
46
50
  entari_plugin_hyw/assets/icon/zai.png,sha256=K-gnabdsjMLInppHA1Op7Nyt33iegrx1x-yNlvCZ0Tc,2351
51
+ entari_plugin_hyw/browser/__init__.py,sha256=Cht-i5MowfAdmfW3kiY4sV7oXKDb-DmhZ-_eKwDl6r0,321
52
+ entari_plugin_hyw/browser/landing.html,sha256=wgqldumdylz69T83pvOkrigT1Mdb9GY0_KU0ceLGwdY,4642
53
+ entari_plugin_hyw/browser/manager.py,sha256=9VuTyXBr1QBcTV8Nj2vSrozstMmNxAytXESUQ6vxLrM,5234
54
+ entari_plugin_hyw/browser/service.py,sha256=8PihWOdyJcBV1_2lp3PRmmcgXYFN3uryqs5rE9E5a9M,13647
55
+ entari_plugin_hyw/browser/engines/base.py,sha256=q5y4SM1G6xS7-6TQ-nZz9iTWw3XonjJn01fWzoTxr6c,414
56
+ entari_plugin_hyw/browser/engines/bing.py,sha256=rIWcvjzvm700xji_OBl6COUAtwXg87DcXQ97DlTzleA,3838
57
+ entari_plugin_hyw/browser/engines/duckduckgo.py,sha256=jlCIXR1mpJ0LjSbuHMYNGMYjHiQ9Lw_x-A8242Zajgo,5154
58
+ entari_plugin_hyw/browser/engines/google.py,sha256=vCtyOxr63F40hDMW70sS1CyoMsqc0HzyESYrK_qcZLg,6091
47
59
  entari_plugin_hyw/card-ui/.gitignore,sha256=_nGOe6uxTzy60tl_CIibnOUhXtP-DkOyuM-_s7m4ROg,253
48
60
  entari_plugin_hyw/card-ui/README.md,sha256=fN9IawCcxEcJ8LM-RfKiAH835fRqyY_iqrRsgSkxiSk,442
49
61
  entari_plugin_hyw/card-ui/index.html,sha256=Hd7vk8v8PtATbfiEWLYoKDpUT0dlyozW_K5gR_cObfo,328
@@ -72,17 +84,17 @@ entari_plugin_hyw/card-ui/public/logos/qwen.png,sha256=eqLbnIPbjh2_PsODU_mmqjeD8
72
84
  entari_plugin_hyw/card-ui/public/logos/xai.png,sha256=uSulvvDVqoA4RUOW0ZAkdvBVM2rpyGJRZIbn5dEFspw,362
73
85
  entari_plugin_hyw/card-ui/public/logos/xiaomi.png,sha256=WHxlDFGU5FCjb-ure3ngdGG18-efYZUUfqA3_lqCUN0,4084
74
86
  entari_plugin_hyw/card-ui/public/logos/zai.png,sha256=K-gnabdsjMLInppHA1Op7Nyt33iegrx1x-yNlvCZ0Tc,2351
75
- entari_plugin_hyw/card-ui/src/App.vue,sha256=fwnw_SFFXK383w0BGAjopzPv7vAWForOLJa2K0tX03o,17821
87
+ entari_plugin_hyw/card-ui/src/App.vue,sha256=ofRlf3hTSqDg1l8jgnFwzWg1dBzQVVg5MLOaMW01z68,28858
76
88
  entari_plugin_hyw/card-ui/src/main.ts,sha256=rm653lPnK5fuTIj-iNLpgr8GAmayuCoKop7IWfo0IBk,111
77
89
  entari_plugin_hyw/card-ui/src/style.css,sha256=Qm0sv9em6k4VI_j5PI0_E_ng6u20eFpf2lN44H19zzc,671
78
90
  entari_plugin_hyw/card-ui/src/test_regex.js,sha256=cWmclm6LRKYfjeN1RT5HECdltmo1HvS2BwGCYY_4l14,3040
79
- entari_plugin_hyw/card-ui/src/types.ts,sha256=jzI8MXDKxz7WRZmGVb-bToO8BEFW2AOp8iek1n4VuQY,1246
91
+ entari_plugin_hyw/card-ui/src/types.ts,sha256=2HkcsR1ej2y3yR7pvUA_y8XXP_1_NhLVAIKez3OIb3g,1583
80
92
  entari_plugin_hyw/card-ui/src/assets/vue.svg,sha256=VTLbNPHFKEGIG6uK7KbD6NCSvSGmiaZfTY-M-AQe750,496
81
93
  entari_plugin_hyw/card-ui/src/components/HelloWorld.vue,sha256=yvBIzJua9BfikUOR1I7GYytlnBbgB6xyposxslAoRLU,856
82
- entari_plugin_hyw/card-ui/src/components/MarkdownContent.vue,sha256=JO1sKThQB42bVl5382BkxpDEyRpAK7oGcmdj1LY5P64,13190
94
+ entari_plugin_hyw/card-ui/src/components/MarkdownContent.vue,sha256=SV95Vuj99tQN2yrU9GqiyhiemWAW8omhYnS8AsH1YIU,13325
83
95
  entari_plugin_hyw/card-ui/src/components/SectionCard.vue,sha256=owcDNx2JYVmF2J5SYCroR2gvg_cPApQsNunjK1WJpVI,1433
84
- entari_plugin_hyw/card-ui/src/components/StageCard.vue,sha256=cC0TeJ4AhtN3sJEXenVpl2Eq5901GKC59qpDUNH2SZE,10964
85
- entari_plugin_hyw-4.0.0rc4.dist-info/METADATA,sha256=0Ytj2E6tpljuG281p44mEEusfc3V-ZUB1V5rvEswwos,3746
86
- entari_plugin_hyw-4.0.0rc4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
87
- entari_plugin_hyw-4.0.0rc4.dist-info/top_level.txt,sha256=TIDsn6XPs6KA5e3ezsE65JoXsy03ejDdrB41I4SPjmo,18
88
- entari_plugin_hyw-4.0.0rc4.dist-info/RECORD,,
96
+ entari_plugin_hyw/card-ui/src/components/StageCard.vue,sha256=MgpOaBlPR--LJoRenN37i72BV8qVgzDdurpoKCvzKyk,11133
97
+ entari_plugin_hyw-4.0.0rc6.dist-info/METADATA,sha256=ODqjgpaG9PeWasK1FlsQ5E39DxvyyC7nVy4WMy_HcUk,3766
98
+ entari_plugin_hyw-4.0.0rc6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
99
+ entari_plugin_hyw-4.0.0rc6.dist-info/top_level.txt,sha256=TIDsn6XPs6KA5e3ezsE65JoXsy03ejDdrB41I4SPjmo,18
100
+ entari_plugin_hyw-4.0.0rc6.dist-info/RECORD,,