jarvis-ai-assistant 0.3.30__py3-none-any.whl → 0.7.6__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.
- jarvis/__init__.py +1 -1
- jarvis/jarvis_agent/__init__.py +458 -152
- jarvis/jarvis_agent/agent_manager.py +17 -13
- jarvis/jarvis_agent/builtin_input_handler.py +2 -6
- jarvis/jarvis_agent/config_editor.py +2 -7
- jarvis/jarvis_agent/event_bus.py +82 -12
- jarvis/jarvis_agent/file_context_handler.py +329 -0
- jarvis/jarvis_agent/file_methodology_manager.py +3 -4
- jarvis/jarvis_agent/jarvis.py +628 -55
- jarvis/jarvis_agent/language_extractors/__init__.py +57 -0
- jarvis/jarvis_agent/language_extractors/c_extractor.py +21 -0
- jarvis/jarvis_agent/language_extractors/cpp_extractor.py +21 -0
- jarvis/jarvis_agent/language_extractors/go_extractor.py +21 -0
- jarvis/jarvis_agent/language_extractors/java_extractor.py +84 -0
- jarvis/jarvis_agent/language_extractors/javascript_extractor.py +79 -0
- jarvis/jarvis_agent/language_extractors/python_extractor.py +21 -0
- jarvis/jarvis_agent/language_extractors/rust_extractor.py +21 -0
- jarvis/jarvis_agent/language_extractors/typescript_extractor.py +84 -0
- jarvis/jarvis_agent/language_support_info.py +486 -0
- jarvis/jarvis_agent/main.py +34 -10
- jarvis/jarvis_agent/memory_manager.py +7 -16
- jarvis/jarvis_agent/methodology_share_manager.py +10 -16
- jarvis/jarvis_agent/prompt_manager.py +1 -1
- jarvis/jarvis_agent/prompts.py +193 -171
- jarvis/jarvis_agent/protocols.py +8 -12
- jarvis/jarvis_agent/run_loop.py +105 -9
- jarvis/jarvis_agent/session_manager.py +2 -3
- jarvis/jarvis_agent/share_manager.py +20 -22
- jarvis/jarvis_agent/shell_input_handler.py +1 -2
- jarvis/jarvis_agent/stdio_redirect.py +295 -0
- jarvis/jarvis_agent/task_analyzer.py +31 -6
- jarvis/jarvis_agent/task_manager.py +11 -27
- jarvis/jarvis_agent/tool_executor.py +2 -3
- jarvis/jarvis_agent/tool_share_manager.py +12 -24
- jarvis/jarvis_agent/utils.py +5 -1
- jarvis/jarvis_agent/web_bridge.py +189 -0
- jarvis/jarvis_agent/web_output_sink.py +53 -0
- jarvis/jarvis_agent/web_server.py +786 -0
- jarvis/jarvis_c2rust/__init__.py +26 -0
- jarvis/jarvis_c2rust/cli.py +575 -0
- jarvis/jarvis_c2rust/collector.py +250 -0
- jarvis/jarvis_c2rust/constants.py +26 -0
- jarvis/jarvis_c2rust/library_replacer.py +1254 -0
- jarvis/jarvis_c2rust/llm_module_agent.py +1272 -0
- jarvis/jarvis_c2rust/loaders.py +207 -0
- jarvis/jarvis_c2rust/models.py +28 -0
- jarvis/jarvis_c2rust/optimizer.py +2157 -0
- jarvis/jarvis_c2rust/scanner.py +1681 -0
- jarvis/jarvis_c2rust/transpiler.py +2983 -0
- jarvis/jarvis_c2rust/utils.py +385 -0
- jarvis/jarvis_code_agent/build_validation_config.py +132 -0
- jarvis/jarvis_code_agent/code_agent.py +1371 -220
- jarvis/jarvis_code_agent/code_analyzer/__init__.py +65 -0
- jarvis/jarvis_code_agent/code_analyzer/base_language.py +74 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/__init__.py +44 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/base.py +106 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/cmake.py +74 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/detector.py +125 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/fallback.py +72 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/go.py +70 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/java_gradle.py +53 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/java_maven.py +47 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/makefile.py +61 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/nodejs.py +110 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/python.py +154 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/rust.py +110 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/validator.py +153 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator.py +43 -0
- jarvis/jarvis_code_agent/code_analyzer/context_manager.py +648 -0
- jarvis/jarvis_code_agent/code_analyzer/context_recommender.py +18 -0
- jarvis/jarvis_code_agent/code_analyzer/dependency_analyzer.py +132 -0
- jarvis/jarvis_code_agent/code_analyzer/file_ignore.py +330 -0
- jarvis/jarvis_code_agent/code_analyzer/impact_analyzer.py +781 -0
- jarvis/jarvis_code_agent/code_analyzer/language_registry.py +185 -0
- jarvis/jarvis_code_agent/code_analyzer/language_support.py +110 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/__init__.py +49 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/c_cpp_language.py +299 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/go_language.py +215 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/java_language.py +212 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/javascript_language.py +254 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/python_language.py +269 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/rust_language.py +281 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/typescript_language.py +280 -0
- jarvis/jarvis_code_agent/code_analyzer/llm_context_recommender.py +605 -0
- jarvis/jarvis_code_agent/code_analyzer/structured_code.py +556 -0
- jarvis/jarvis_code_agent/code_analyzer/symbol_extractor.py +252 -0
- jarvis/jarvis_code_agent/code_analyzer/tree_sitter_extractor.py +58 -0
- jarvis/jarvis_code_agent/lint.py +501 -8
- jarvis/jarvis_code_agent/utils.py +141 -0
- jarvis/jarvis_code_analysis/code_review.py +493 -584
- jarvis/jarvis_data/config_schema.json +128 -12
- jarvis/jarvis_git_squash/main.py +4 -5
- jarvis/jarvis_git_utils/git_commiter.py +82 -75
- jarvis/jarvis_mcp/sse_mcp_client.py +22 -29
- jarvis/jarvis_mcp/stdio_mcp_client.py +12 -13
- jarvis/jarvis_mcp/streamable_mcp_client.py +15 -14
- jarvis/jarvis_memory_organizer/memory_organizer.py +55 -74
- jarvis/jarvis_methodology/main.py +32 -48
- jarvis/jarvis_multi_agent/__init__.py +287 -55
- jarvis/jarvis_multi_agent/main.py +36 -4
- jarvis/jarvis_platform/base.py +524 -202
- jarvis/jarvis_platform/human.py +7 -8
- jarvis/jarvis_platform/kimi.py +30 -36
- jarvis/jarvis_platform/openai.py +88 -25
- jarvis/jarvis_platform/registry.py +26 -10
- jarvis/jarvis_platform/tongyi.py +24 -25
- jarvis/jarvis_platform/yuanbao.py +32 -43
- jarvis/jarvis_platform_manager/main.py +66 -77
- jarvis/jarvis_platform_manager/service.py +8 -13
- jarvis/jarvis_rag/cli.py +53 -55
- jarvis/jarvis_rag/embedding_manager.py +13 -18
- jarvis/jarvis_rag/llm_interface.py +8 -9
- jarvis/jarvis_rag/query_rewriter.py +10 -21
- jarvis/jarvis_rag/rag_pipeline.py +24 -27
- jarvis/jarvis_rag/reranker.py +4 -5
- jarvis/jarvis_rag/retriever.py +28 -30
- jarvis/jarvis_sec/__init__.py +305 -0
- jarvis/jarvis_sec/agents.py +143 -0
- jarvis/jarvis_sec/analysis.py +276 -0
- jarvis/jarvis_sec/checkers/__init__.py +32 -0
- jarvis/jarvis_sec/checkers/c_checker.py +2680 -0
- jarvis/jarvis_sec/checkers/rust_checker.py +1108 -0
- jarvis/jarvis_sec/cli.py +139 -0
- jarvis/jarvis_sec/clustering.py +1439 -0
- jarvis/jarvis_sec/file_manager.py +427 -0
- jarvis/jarvis_sec/parsers.py +73 -0
- jarvis/jarvis_sec/prompts.py +268 -0
- jarvis/jarvis_sec/report.py +336 -0
- jarvis/jarvis_sec/review.py +453 -0
- jarvis/jarvis_sec/status.py +264 -0
- jarvis/jarvis_sec/types.py +20 -0
- jarvis/jarvis_sec/utils.py +499 -0
- jarvis/jarvis_sec/verification.py +848 -0
- jarvis/jarvis_sec/workflow.py +226 -0
- jarvis/jarvis_smart_shell/main.py +38 -87
- jarvis/jarvis_stats/cli.py +2 -2
- jarvis/jarvis_stats/stats.py +8 -8
- jarvis/jarvis_stats/storage.py +15 -21
- jarvis/jarvis_stats/visualizer.py +1 -1
- jarvis/jarvis_tools/clear_memory.py +3 -20
- jarvis/jarvis_tools/cli/main.py +21 -23
- jarvis/jarvis_tools/edit_file.py +1019 -132
- jarvis/jarvis_tools/execute_script.py +83 -25
- jarvis/jarvis_tools/file_analyzer.py +6 -9
- jarvis/jarvis_tools/generate_new_tool.py +14 -21
- jarvis/jarvis_tools/lsp_client.py +1552 -0
- jarvis/jarvis_tools/methodology.py +2 -3
- jarvis/jarvis_tools/read_code.py +1736 -35
- jarvis/jarvis_tools/read_symbols.py +140 -0
- jarvis/jarvis_tools/read_webpage.py +12 -13
- jarvis/jarvis_tools/registry.py +427 -200
- jarvis/jarvis_tools/retrieve_memory.py +20 -19
- jarvis/jarvis_tools/rewrite_file.py +72 -158
- jarvis/jarvis_tools/save_memory.py +3 -15
- jarvis/jarvis_tools/search_web.py +18 -18
- jarvis/jarvis_tools/sub_agent.py +36 -43
- jarvis/jarvis_tools/sub_code_agent.py +25 -26
- jarvis/jarvis_tools/virtual_tty.py +55 -33
- jarvis/jarvis_utils/clipboard.py +7 -10
- jarvis/jarvis_utils/config.py +232 -45
- jarvis/jarvis_utils/embedding.py +8 -5
- jarvis/jarvis_utils/fzf.py +8 -8
- jarvis/jarvis_utils/git_utils.py +225 -36
- jarvis/jarvis_utils/globals.py +3 -3
- jarvis/jarvis_utils/http.py +1 -1
- jarvis/jarvis_utils/input.py +99 -48
- jarvis/jarvis_utils/jsonnet_compat.py +465 -0
- jarvis/jarvis_utils/methodology.py +52 -48
- jarvis/jarvis_utils/utils.py +819 -491
- jarvis_ai_assistant-0.7.6.dist-info/METADATA +600 -0
- jarvis_ai_assistant-0.7.6.dist-info/RECORD +218 -0
- {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/entry_points.txt +4 -0
- jarvis/jarvis_agent/config.py +0 -92
- jarvis/jarvis_agent/edit_file_handler.py +0 -296
- jarvis/jarvis_platform/ai8.py +0 -332
- jarvis/jarvis_tools/ask_user.py +0 -54
- jarvis_ai_assistant-0.3.30.dist-info/METADATA +0 -381
- jarvis_ai_assistant-0.3.30.dist-info/RECORD +0 -137
- {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/licenses/LICENSE +0 -0
- {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/top_level.txt +0 -0
jarvis/jarvis_platform/tongyi.py
CHANGED
|
@@ -7,7 +7,6 @@ from typing import Any, Dict, Generator, List, Tuple
|
|
|
7
7
|
|
|
8
8
|
from jarvis.jarvis_platform.base import BasePlatform
|
|
9
9
|
from jarvis.jarvis_utils import http
|
|
10
|
-
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
11
10
|
from jarvis.jarvis_utils.tag import ot, ct
|
|
12
11
|
from jarvis.jarvis_utils.utils import while_success
|
|
13
12
|
|
|
@@ -161,7 +160,6 @@ class TongyiPlatform(BasePlatform):
|
|
|
161
160
|
# 使用新的stream_post接口发送消息请求,获取流式响应
|
|
162
161
|
response_stream = while_success(
|
|
163
162
|
lambda: http.stream_post(url, headers=headers, json=payload),
|
|
164
|
-
sleep_time=5,
|
|
165
163
|
)
|
|
166
164
|
|
|
167
165
|
msg_id = ""
|
|
@@ -224,7 +222,7 @@ class TongyiPlatform(BasePlatform):
|
|
|
224
222
|
yield tmp_content[len(text_content) :]
|
|
225
223
|
text_content = tmp_content
|
|
226
224
|
|
|
227
|
-
except
|
|
225
|
+
except Exception:
|
|
228
226
|
continue
|
|
229
227
|
|
|
230
228
|
self.msg_id = msg_id
|
|
@@ -247,8 +245,7 @@ class TongyiPlatform(BasePlatform):
|
|
|
247
245
|
|
|
248
246
|
try:
|
|
249
247
|
response = while_success(
|
|
250
|
-
lambda: http.post(url, headers=headers, json=payload)
|
|
251
|
-
)
|
|
248
|
+
lambda: http.post(url, headers=headers, json=payload) )
|
|
252
249
|
if response.status_code != 200:
|
|
253
250
|
raise Exception(f"HTTP {response.status_code}: {response.text}")
|
|
254
251
|
|
|
@@ -282,7 +279,8 @@ class TongyiPlatform(BasePlatform):
|
|
|
282
279
|
if not os.path.exists(file_path):
|
|
283
280
|
# 先输出已收集的日志与错误后返回
|
|
284
281
|
log_lines.append(f"文件不存在: {file_path}")
|
|
285
|
-
|
|
282
|
+
joined_logs = '\n'.join(log_lines)
|
|
283
|
+
print(f"❌ {joined_logs}")
|
|
286
284
|
return False
|
|
287
285
|
|
|
288
286
|
# Get file name and content type
|
|
@@ -312,7 +310,8 @@ class TongyiPlatform(BasePlatform):
|
|
|
312
310
|
|
|
313
311
|
if response.status_code != 200:
|
|
314
312
|
log_lines.append(f"上传失败 {file_name}: HTTP {response.status_code}")
|
|
315
|
-
|
|
313
|
+
joined_logs = '\n'.join(log_lines)
|
|
314
|
+
print(f"❌ {joined_logs}")
|
|
316
315
|
return False
|
|
317
316
|
|
|
318
317
|
# Determine file type based on extension
|
|
@@ -345,13 +344,15 @@ class TongyiPlatform(BasePlatform):
|
|
|
345
344
|
response = http.post(url, headers=headers, json=payload)
|
|
346
345
|
if response.status_code != 200:
|
|
347
346
|
log_lines.append(f"获取下载链接失败: HTTP {response.status_code}")
|
|
348
|
-
|
|
347
|
+
joined_logs = '\n'.join(log_lines)
|
|
348
|
+
print(f"❌ {joined_logs}")
|
|
349
349
|
return False
|
|
350
350
|
|
|
351
351
|
result = response.json()
|
|
352
352
|
if not result.get("success"):
|
|
353
353
|
log_lines.append(f"获取下载链接失败: {result.get('errorMsg')}")
|
|
354
|
-
|
|
354
|
+
joined_logs = '\n'.join(log_lines)
|
|
355
|
+
print(f"❌ {joined_logs}")
|
|
355
356
|
return False
|
|
356
357
|
|
|
357
358
|
# Add files to chat
|
|
@@ -391,17 +392,19 @@ class TongyiPlatform(BasePlatform):
|
|
|
391
392
|
file_info.update(add_result.get("data", {}))
|
|
392
393
|
|
|
393
394
|
log_lines.append(f"文件 {file_name} 上传成功")
|
|
394
|
-
|
|
395
|
+
joined_logs = '\n'.join(log_lines)
|
|
396
|
+
print(f"ℹ️ {joined_logs}")
|
|
395
397
|
time.sleep(1) # 短暂暂停以便用户看到成功状态
|
|
396
398
|
|
|
397
399
|
except Exception as e:
|
|
398
400
|
log_lines.append(f"上传文件 {file_name} 时出错: {str(e)}")
|
|
399
|
-
|
|
401
|
+
joined_logs = '\n'.join(log_lines)
|
|
402
|
+
print(f"❌ {joined_logs}")
|
|
400
403
|
return False
|
|
401
404
|
return True
|
|
402
405
|
|
|
403
406
|
except Exception as e:
|
|
404
|
-
|
|
407
|
+
print(f"❌ Error uploading files: {str(e)}")
|
|
405
408
|
return False
|
|
406
409
|
|
|
407
410
|
def _get_content_type(self, file_path: str) -> str:
|
|
@@ -466,13 +469,9 @@ class TongyiPlatform(BasePlatform):
|
|
|
466
469
|
|
|
467
470
|
try:
|
|
468
471
|
response = while_success(
|
|
469
|
-
lambda: http.post(url, headers=headers, json=payload)
|
|
470
|
-
)
|
|
472
|
+
lambda: http.post(url, headers=headers, json=payload) )
|
|
471
473
|
if response.status_code != 200:
|
|
472
|
-
|
|
473
|
-
f"Failed to delete chat: HTTP {response.status_code}",
|
|
474
|
-
OutputType.ERROR,
|
|
475
|
-
)
|
|
474
|
+
print(f"❌ Failed to delete chat: HTTP {response.status_code}")
|
|
476
475
|
return False
|
|
477
476
|
self.request_id = ""
|
|
478
477
|
self.session_id = ""
|
|
@@ -480,13 +479,13 @@ class TongyiPlatform(BasePlatform):
|
|
|
480
479
|
self.first_chat = True # Reset first_chat flag
|
|
481
480
|
return True
|
|
482
481
|
except Exception as e:
|
|
483
|
-
|
|
482
|
+
print(f"❌ Error deleting chat: {str(e)}")
|
|
484
483
|
return False
|
|
485
484
|
|
|
486
485
|
def save(self, file_path: str) -> bool:
|
|
487
486
|
"""Save chat session to a file."""
|
|
488
487
|
if not self.session_id:
|
|
489
|
-
|
|
488
|
+
print("⚠️ 没有活动的会话可供保存")
|
|
490
489
|
return False
|
|
491
490
|
|
|
492
491
|
state = {
|
|
@@ -503,10 +502,10 @@ class TongyiPlatform(BasePlatform):
|
|
|
503
502
|
with open(file_path, "w", encoding="utf-8") as f:
|
|
504
503
|
json.dump(state, f, ensure_ascii=False, indent=4)
|
|
505
504
|
self._saved = True
|
|
506
|
-
|
|
505
|
+
print(f"✅ 会话已成功保存到 {file_path}")
|
|
507
506
|
return True
|
|
508
507
|
except Exception as e:
|
|
509
|
-
|
|
508
|
+
print(f"❌ 保存会话失败: {str(e)}")
|
|
510
509
|
return False
|
|
511
510
|
|
|
512
511
|
def restore(self, file_path: str) -> bool:
|
|
@@ -524,13 +523,13 @@ class TongyiPlatform(BasePlatform):
|
|
|
524
523
|
self.first_chat = state.get("first_chat", True)
|
|
525
524
|
self._saved = True
|
|
526
525
|
|
|
527
|
-
|
|
526
|
+
print(f"✅ 从 {file_path} 成功恢复会话")
|
|
528
527
|
return True
|
|
529
528
|
except FileNotFoundError:
|
|
530
|
-
|
|
529
|
+
print(f"❌ 会话文件未找到: {file_path}")
|
|
531
530
|
return False
|
|
532
531
|
except Exception as e:
|
|
533
|
-
|
|
532
|
+
print(f"❌ 恢复会话失败: {str(e)}")
|
|
534
533
|
return False
|
|
535
534
|
|
|
536
535
|
def set_system_prompt(self, message: str):
|
|
@@ -11,7 +11,6 @@ from PIL import Image # type: ignore
|
|
|
11
11
|
|
|
12
12
|
from jarvis.jarvis_platform.base import BasePlatform
|
|
13
13
|
from jarvis.jarvis_utils import http
|
|
14
|
-
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
15
14
|
from jarvis.jarvis_utils.tag import ot, ct
|
|
16
15
|
from jarvis.jarvis_utils.utils import while_success
|
|
17
16
|
|
|
@@ -59,7 +58,7 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
59
58
|
if model_name in model_mapping:
|
|
60
59
|
self.model_name = model_name
|
|
61
60
|
else:
|
|
62
|
-
|
|
61
|
+
print(f"❌ 错误:不支持的模型: {model_name}")
|
|
63
62
|
|
|
64
63
|
def _get_base_headers(self):
|
|
65
64
|
"""获取API请求的基础头部信息"""
|
|
@@ -77,7 +76,7 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
77
76
|
"Referer": f"https://yuanbao.tencent.com/chat/{self.agent_id}",
|
|
78
77
|
"X-Source": "web",
|
|
79
78
|
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
80
|
-
|
|
79
|
+
|
|
81
80
|
"Sec-Fetch-Site": "same-origin",
|
|
82
81
|
"Sec-Fetch-Mode": "cors",
|
|
83
82
|
"Sec-Fetch-Dest": "empty",
|
|
@@ -96,7 +95,6 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
96
95
|
try:
|
|
97
96
|
response = while_success(
|
|
98
97
|
lambda: http.post(url, headers=headers, data=payload),
|
|
99
|
-
sleep_time=5,
|
|
100
98
|
)
|
|
101
99
|
response_json = response.json()
|
|
102
100
|
|
|
@@ -104,12 +102,10 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
104
102
|
self.conversation_id = response_json["id"]
|
|
105
103
|
return True
|
|
106
104
|
else:
|
|
107
|
-
|
|
108
|
-
f"错误:创建会话失败,响应: {response_json}", OutputType.ERROR
|
|
109
|
-
)
|
|
105
|
+
print(f"❌ 错误:创建会话失败,响应: {response_json}")
|
|
110
106
|
return False
|
|
111
107
|
except Exception as e:
|
|
112
|
-
|
|
108
|
+
print(f"❌ 错误:创建会话失败:{e}")
|
|
113
109
|
return False
|
|
114
110
|
|
|
115
111
|
def support_upload_files(self) -> bool:
|
|
@@ -126,7 +122,7 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
126
122
|
用于聊天消息的文件元数据字典列表
|
|
127
123
|
"""
|
|
128
124
|
if not self.cookies:
|
|
129
|
-
|
|
125
|
+
print("❌ 未设置YUANBAO_COOKIES,无法上传文件")
|
|
130
126
|
return False
|
|
131
127
|
|
|
132
128
|
uploaded_files = []
|
|
@@ -196,7 +192,8 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
196
192
|
upload_info = self._generate_upload_info(file_name)
|
|
197
193
|
if not upload_info:
|
|
198
194
|
log_lines.append(f"无法获取文件 {file_name} 的上传信息")
|
|
199
|
-
|
|
195
|
+
joined_logs = '\n'.join(log_lines)
|
|
196
|
+
print(f"❌ {joined_logs}")
|
|
200
197
|
return False
|
|
201
198
|
|
|
202
199
|
# 3. Upload the file to COS
|
|
@@ -204,7 +201,8 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
204
201
|
upload_success = self._upload_file_to_cos(file_path, upload_info)
|
|
205
202
|
if not upload_success:
|
|
206
203
|
log_lines.append(f"上传文件 {file_name} 失败")
|
|
207
|
-
|
|
204
|
+
joined_logs = '\n'.join(log_lines)
|
|
205
|
+
print(f"❌ {joined_logs}")
|
|
208
206
|
return False
|
|
209
207
|
|
|
210
208
|
# 4. Create file metadata for chat
|
|
@@ -230,12 +228,14 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
230
228
|
|
|
231
229
|
uploaded_files.append(file_metadata)
|
|
232
230
|
log_lines.append(f"文件 {file_name} 上传成功")
|
|
233
|
-
|
|
231
|
+
joined_logs = '\n'.join(log_lines)
|
|
232
|
+
print(f"ℹ️ {joined_logs}")
|
|
234
233
|
time.sleep(3) # 上传成功后等待3秒
|
|
235
234
|
|
|
236
235
|
except Exception as e:
|
|
237
236
|
log_lines.append(f"上传文件 {file_path} 时出错: {str(e)}")
|
|
238
|
-
|
|
237
|
+
joined_logs = '\n'.join(log_lines)
|
|
238
|
+
print(f"❌ {joined_logs}")
|
|
239
239
|
return False
|
|
240
240
|
|
|
241
241
|
self.multimedia = uploaded_files
|
|
@@ -259,23 +259,19 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
259
259
|
try:
|
|
260
260
|
response = while_success(
|
|
261
261
|
lambda: http.post(url, headers=headers, json=payload),
|
|
262
|
-
sleep_time=5,
|
|
263
262
|
)
|
|
264
263
|
|
|
265
264
|
if response.status_code != 200:
|
|
266
|
-
|
|
267
|
-
f"获取上传信息失败,状态码: {response.status_code}",
|
|
268
|
-
OutputType.ERROR,
|
|
269
|
-
)
|
|
265
|
+
print(f"❌ 获取上传信息失败,状态码: {response.status_code}")
|
|
270
266
|
if hasattr(response, "text"):
|
|
271
|
-
|
|
267
|
+
print(f"❌ 响应: {response.text}")
|
|
272
268
|
return {}
|
|
273
269
|
|
|
274
270
|
upload_info = response.json()
|
|
275
271
|
return upload_info
|
|
276
272
|
|
|
277
273
|
except Exception as e:
|
|
278
|
-
|
|
274
|
+
print(f"❌ 获取上传信息时出错: {str(e)}")
|
|
279
275
|
return {}
|
|
280
276
|
|
|
281
277
|
def _upload_file_to_cos(self, file_path: str, upload_info: Dict) -> bool:
|
|
@@ -306,7 +302,7 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
306
302
|
with open(file_path, "rb") as file:
|
|
307
303
|
file_content = file.read()
|
|
308
304
|
|
|
309
|
-
|
|
305
|
+
print(f"ℹ️ 上传文件大小: {len(file_content)}")
|
|
310
306
|
|
|
311
307
|
# Prepare headers for PUT request
|
|
312
308
|
host = f"{upload_info['bucketName']}.{upload_info.get('accelerateDomain', 'cos.accelerate.myqcloud.com')}"
|
|
@@ -338,18 +334,15 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
338
334
|
response = http.put(url, headers=headers, data=file_content)
|
|
339
335
|
|
|
340
336
|
if response.status_code not in [200, 204]:
|
|
341
|
-
|
|
342
|
-
f"文件上传到COS失败,状态码: {response.status_code}",
|
|
343
|
-
OutputType.ERROR,
|
|
344
|
-
)
|
|
337
|
+
print(f"❌ 文件上传到COS失败,状态码: {response.status_code}")
|
|
345
338
|
if hasattr(response, "text"):
|
|
346
|
-
|
|
339
|
+
print(f"❌ 响应: {response.text}")
|
|
347
340
|
return False
|
|
348
341
|
|
|
349
342
|
return True
|
|
350
343
|
|
|
351
344
|
except Exception as e:
|
|
352
|
-
|
|
345
|
+
print(f"❌ 上传文件到COS时出错: {str(e)}")
|
|
353
346
|
return False
|
|
354
347
|
|
|
355
348
|
def _generate_cos_signature(
|
|
@@ -411,7 +404,7 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
411
404
|
return signature
|
|
412
405
|
|
|
413
406
|
except Exception as e:
|
|
414
|
-
|
|
407
|
+
print(f"❌ 生成签名时出错: {str(e)}")
|
|
415
408
|
raise e
|
|
416
409
|
|
|
417
410
|
def chat(self, message: str) -> Generator[str, None, None]:
|
|
@@ -475,7 +468,6 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
475
468
|
# 使用新的stream_post接口发送消息请求,获取流式响应
|
|
476
469
|
response_stream = while_success(
|
|
477
470
|
lambda: http.stream_post(url, headers=headers, json=payload),
|
|
478
|
-
sleep_time=5,
|
|
479
471
|
)
|
|
480
472
|
|
|
481
473
|
in_thinking = False
|
|
@@ -515,14 +507,14 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
515
507
|
if think_content:
|
|
516
508
|
yield think_content
|
|
517
509
|
|
|
518
|
-
except
|
|
510
|
+
except Exception:
|
|
519
511
|
pass
|
|
520
512
|
else:
|
|
521
513
|
try:
|
|
522
514
|
data = json.loads(line)
|
|
523
515
|
if "msg" in data:
|
|
524
516
|
yield data["msg"]
|
|
525
|
-
except
|
|
517
|
+
except Exception:
|
|
526
518
|
pass
|
|
527
519
|
|
|
528
520
|
self.first_chat = False
|
|
@@ -551,7 +543,6 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
551
543
|
try:
|
|
552
544
|
response = while_success(
|
|
553
545
|
lambda: http.post(url, headers=headers, json=payload),
|
|
554
|
-
sleep_time=5,
|
|
555
546
|
)
|
|
556
547
|
|
|
557
548
|
if response.status_code == 200:
|
|
@@ -559,20 +550,18 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
559
550
|
self.first_chat = True
|
|
560
551
|
return True
|
|
561
552
|
else:
|
|
562
|
-
|
|
563
|
-
f"删除会话失败: HTTP {response.status_code}", OutputType.WARNING
|
|
564
|
-
)
|
|
553
|
+
print(f"⚠️ 删除会话失败: HTTP {response.status_code}")
|
|
565
554
|
if hasattr(response, "text"):
|
|
566
|
-
|
|
555
|
+
print(f"⚠️ 响应: {response.text}")
|
|
567
556
|
return False
|
|
568
557
|
except Exception as e:
|
|
569
|
-
|
|
558
|
+
print(f"❌ 删除会话时发生错误: {str(e)}")
|
|
570
559
|
return False
|
|
571
560
|
|
|
572
561
|
def save(self, file_path: str) -> bool:
|
|
573
562
|
"""Save chat session to a file."""
|
|
574
563
|
if not self.conversation_id:
|
|
575
|
-
|
|
564
|
+
print("⚠️ 没有活动的会话可供保存")
|
|
576
565
|
return False
|
|
577
566
|
|
|
578
567
|
state = {
|
|
@@ -587,10 +576,10 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
587
576
|
with open(file_path, "w", encoding="utf-8") as f:
|
|
588
577
|
json.dump(state, f, ensure_ascii=False, indent=4)
|
|
589
578
|
self._saved = True
|
|
590
|
-
|
|
579
|
+
print(f"✅ 会话已成功保存到 {file_path}")
|
|
591
580
|
return True
|
|
592
581
|
except Exception as e:
|
|
593
|
-
|
|
582
|
+
print(f"❌ 保存会话失败: {str(e)}")
|
|
594
583
|
return False
|
|
595
584
|
|
|
596
585
|
def restore(self, file_path: str) -> bool:
|
|
@@ -606,13 +595,13 @@ class YuanbaoPlatform(BasePlatform):
|
|
|
606
595
|
self.multimedia = state.get("multimedia", [])
|
|
607
596
|
self._saved = True
|
|
608
597
|
|
|
609
|
-
|
|
598
|
+
print(f"✅ 从 {file_path} 成功恢复会话")
|
|
610
599
|
return True
|
|
611
600
|
except FileNotFoundError:
|
|
612
|
-
|
|
601
|
+
print(f"❌ 会话文件未找到: {file_path}")
|
|
613
602
|
return False
|
|
614
603
|
except Exception as e:
|
|
615
|
-
|
|
604
|
+
print(f"❌ 恢复会话失败: {str(e)}")
|
|
616
605
|
return False
|
|
617
606
|
|
|
618
607
|
def name(self) -> str:
|