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/ai8.py
DELETED
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from typing import Any, Dict, Generator, List, Tuple
|
|
3
|
-
|
|
4
|
-
from jarvis.jarvis_platform.base import BasePlatform
|
|
5
|
-
import json
|
|
6
|
-
|
|
7
|
-
from jarvis.jarvis_utils import http
|
|
8
|
-
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
9
|
-
from jarvis.jarvis_utils.utils import while_success
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class AI8Model(BasePlatform):
|
|
13
|
-
"""AI8 model implementation"""
|
|
14
|
-
|
|
15
|
-
BASE_URL = "https://ai8.rcouyi.com"
|
|
16
|
-
|
|
17
|
-
def get_model_list(self) -> List[Tuple[str, str]]:
|
|
18
|
-
"""获取模型列表"""
|
|
19
|
-
self.get_available_models()
|
|
20
|
-
return [(name, info["desc"]) for name, info in self.models.items()]
|
|
21
|
-
|
|
22
|
-
def __init__(self):
|
|
23
|
-
"""Initialize model"""
|
|
24
|
-
super().__init__()
|
|
25
|
-
self.system_prompt = ""
|
|
26
|
-
self.conversation = {}
|
|
27
|
-
self.models = {} # 存储模型信息
|
|
28
|
-
|
|
29
|
-
self.token = os.getenv("AI8_API_KEY")
|
|
30
|
-
if not self.token:
|
|
31
|
-
PrettyOutput.print("未设置 AI8_API_KEY", OutputType.WARNING)
|
|
32
|
-
|
|
33
|
-
self.headers = {
|
|
34
|
-
"Authorization": self.token,
|
|
35
|
-
"sec-ch-ua-platform": '"Windows"',
|
|
36
|
-
"sec-ch-ua": '"Not)A;Brand";v="8", "Chromium";v="138", "Google Chrome";v="138"',
|
|
37
|
-
"sec-ch-ua-mobile": "?0",
|
|
38
|
-
"Content-Type": "application/json",
|
|
39
|
-
"Accept": "application/json, text/plain, */*",
|
|
40
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
|
|
41
|
-
"X-APP-VERSION": "2.4.2",
|
|
42
|
-
"Origin": self.BASE_URL,
|
|
43
|
-
"Referer": f"{self.BASE_URL}/chat?_userMenuKey=chat",
|
|
44
|
-
"Sec-Fetch-Site": "same-origin",
|
|
45
|
-
"Sec-Fetch-Mode": "cors",
|
|
46
|
-
"Sec-Fetch-Dest": "empty",
|
|
47
|
-
"Accept-Language": "zh-CN,zh;q=0.9",
|
|
48
|
-
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
49
|
-
"Connection": "keep-alive",
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
self.model_name = os.getenv("JARVIS_MODEL") or "deepseek-chat"
|
|
53
|
-
|
|
54
|
-
def set_model_name(self, model_name: str):
|
|
55
|
-
"""Set model name"""
|
|
56
|
-
|
|
57
|
-
self.model_name = model_name
|
|
58
|
-
|
|
59
|
-
def create_conversation(self) -> bool:
|
|
60
|
-
"""Create a new conversation"""
|
|
61
|
-
try:
|
|
62
|
-
# 1. 创建会话
|
|
63
|
-
response = while_success(
|
|
64
|
-
lambda: http.post(
|
|
65
|
-
f"{self.BASE_URL}/api/chat/session",
|
|
66
|
-
headers=self.headers,
|
|
67
|
-
json={
|
|
68
|
-
"mcp": [],
|
|
69
|
-
"model": self.model_name,
|
|
70
|
-
"plugins": [],
|
|
71
|
-
"rags": [],
|
|
72
|
-
},
|
|
73
|
-
),
|
|
74
|
-
sleep_time=5,
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
data = response.json()
|
|
78
|
-
if data["code"] != 0:
|
|
79
|
-
PrettyOutput.print(
|
|
80
|
-
f"创建会话失败: {data.get('msg', '未知错误')}", OutputType.WARNING
|
|
81
|
-
)
|
|
82
|
-
return False
|
|
83
|
-
|
|
84
|
-
self.conversation = data["data"]
|
|
85
|
-
|
|
86
|
-
# 2. 更新会话设置
|
|
87
|
-
session_data = {
|
|
88
|
-
**self.conversation,
|
|
89
|
-
"model": self.model_name,
|
|
90
|
-
"contextCount": 65536,
|
|
91
|
-
"prompt": self.system_prompt,
|
|
92
|
-
"plugins": [],
|
|
93
|
-
"localPlugins": None,
|
|
94
|
-
"useAppId": 0,
|
|
95
|
-
"temperature": 0,
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
response = while_success(
|
|
99
|
-
lambda: http.put(
|
|
100
|
-
f"{self.BASE_URL}/api/chat/session/{self.conversation['id']}", # type: ignore
|
|
101
|
-
headers=self.headers,
|
|
102
|
-
json=session_data,
|
|
103
|
-
),
|
|
104
|
-
sleep_time=5,
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
data = response.json()
|
|
108
|
-
if data["code"] == 0:
|
|
109
|
-
self.conversation = data["data"]
|
|
110
|
-
return True
|
|
111
|
-
else:
|
|
112
|
-
PrettyOutput.print(
|
|
113
|
-
f"更新会话设置失败: {data.get('msg', '未知错误')}",
|
|
114
|
-
OutputType.WARNING,
|
|
115
|
-
)
|
|
116
|
-
return False
|
|
117
|
-
|
|
118
|
-
except Exception as e:
|
|
119
|
-
PrettyOutput.print(f"创建会话失败: {str(e)}", OutputType.ERROR)
|
|
120
|
-
return False
|
|
121
|
-
|
|
122
|
-
def set_system_prompt(self, message: str):
|
|
123
|
-
"""Set system message"""
|
|
124
|
-
self.system_prompt = message
|
|
125
|
-
|
|
126
|
-
def chat(self, message: str) -> Generator[str, None, None]:
|
|
127
|
-
"""Execute conversation"""
|
|
128
|
-
try:
|
|
129
|
-
# 确保有会话ID
|
|
130
|
-
if not self.conversation:
|
|
131
|
-
if not self.create_conversation():
|
|
132
|
-
raise Exception("Failed to create conversation")
|
|
133
|
-
|
|
134
|
-
payload: Dict[str, Any] = {
|
|
135
|
-
"text": message,
|
|
136
|
-
"sessionId": self.conversation["id"] if self.conversation else None,
|
|
137
|
-
"files": [],
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
# 为流式请求构造专用的请求头,避免 'Accept' 和 'accept' 键冲突
|
|
141
|
-
stream_headers = self.headers.copy()
|
|
142
|
-
stream_headers["Accept"] = "text/event-stream" # 添加流式专用的accept头
|
|
143
|
-
|
|
144
|
-
# 使用stream_post进行流式请求
|
|
145
|
-
response_stream = while_success(
|
|
146
|
-
lambda: http.stream_post(
|
|
147
|
-
f"{self.BASE_URL}/api/chat/completions",
|
|
148
|
-
headers=stream_headers,
|
|
149
|
-
json=payload,
|
|
150
|
-
),
|
|
151
|
-
sleep_time=5,
|
|
152
|
-
)
|
|
153
|
-
|
|
154
|
-
# 处理流式响应
|
|
155
|
-
for line in response_stream:
|
|
156
|
-
if line and line.startswith("data: "):
|
|
157
|
-
try:
|
|
158
|
-
data = json.loads(line[6:])
|
|
159
|
-
if data.get("type") == "string":
|
|
160
|
-
chunk_data = data.get("data", "")
|
|
161
|
-
if chunk_data:
|
|
162
|
-
yield chunk_data
|
|
163
|
-
except json.JSONDecodeError:
|
|
164
|
-
continue
|
|
165
|
-
|
|
166
|
-
return None
|
|
167
|
-
|
|
168
|
-
except Exception as e:
|
|
169
|
-
PrettyOutput.print(f"对话异常: {str(e)}", OutputType.ERROR)
|
|
170
|
-
raise e
|
|
171
|
-
|
|
172
|
-
def name(self) -> str:
|
|
173
|
-
"""Return model name"""
|
|
174
|
-
return self.model_name
|
|
175
|
-
|
|
176
|
-
@classmethod
|
|
177
|
-
def platform_name(cls) -> str:
|
|
178
|
-
"""Return platform name"""
|
|
179
|
-
return "ai8"
|
|
180
|
-
|
|
181
|
-
def delete_chat(self) -> bool:
|
|
182
|
-
"""Delete current chat session"""
|
|
183
|
-
try:
|
|
184
|
-
if not self.conversation:
|
|
185
|
-
return True
|
|
186
|
-
|
|
187
|
-
response = while_success(
|
|
188
|
-
lambda: http.delete(
|
|
189
|
-
f"{self.BASE_URL}/api/chat/session/{self.conversation['id']}", # type: ignore
|
|
190
|
-
headers=self.headers,
|
|
191
|
-
),
|
|
192
|
-
sleep_time=5,
|
|
193
|
-
)
|
|
194
|
-
|
|
195
|
-
data = response.json()
|
|
196
|
-
if data["code"] == 0:
|
|
197
|
-
self.conversation = {}
|
|
198
|
-
return True
|
|
199
|
-
else:
|
|
200
|
-
error_msg = f"删除会话失败: {data.get('msg', '未知错误')}"
|
|
201
|
-
PrettyOutput.print(error_msg, OutputType.WARNING)
|
|
202
|
-
return False
|
|
203
|
-
|
|
204
|
-
except Exception as e:
|
|
205
|
-
PrettyOutput.print(f"删除会话失败: {str(e)}", OutputType.ERROR)
|
|
206
|
-
return False
|
|
207
|
-
|
|
208
|
-
def save(self, file_path: str) -> bool:
|
|
209
|
-
"""Save chat session to a file."""
|
|
210
|
-
if not self.conversation:
|
|
211
|
-
PrettyOutput.print("没有活动的会话可供保存", OutputType.WARNING)
|
|
212
|
-
return False
|
|
213
|
-
|
|
214
|
-
state = {
|
|
215
|
-
"conversation": self.conversation,
|
|
216
|
-
"model_name": self.model_name,
|
|
217
|
-
"system_prompt": self.system_prompt,
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
try:
|
|
221
|
-
with open(file_path, "w", encoding="utf-8") as f:
|
|
222
|
-
json.dump(state, f, ensure_ascii=False, indent=4)
|
|
223
|
-
self._saved = True
|
|
224
|
-
PrettyOutput.print(f"会话已成功保存到 {file_path}", OutputType.SUCCESS)
|
|
225
|
-
return True
|
|
226
|
-
except Exception as e:
|
|
227
|
-
PrettyOutput.print(f"保存会话失败: {str(e)}", OutputType.ERROR)
|
|
228
|
-
return False
|
|
229
|
-
|
|
230
|
-
def restore(self, file_path: str) -> bool:
|
|
231
|
-
"""Restore chat session from a file."""
|
|
232
|
-
try:
|
|
233
|
-
with open(file_path, "r", encoding="utf-8") as f:
|
|
234
|
-
state = json.load(f)
|
|
235
|
-
|
|
236
|
-
self.conversation = state["conversation"]
|
|
237
|
-
self.model_name = state["model_name"]
|
|
238
|
-
self.system_prompt = state.get("system_prompt", "")
|
|
239
|
-
|
|
240
|
-
# A restored session should not be deleted on exit, as it's persistent.
|
|
241
|
-
self._saved = True
|
|
242
|
-
|
|
243
|
-
PrettyOutput.print(f"从 {file_path} 成功恢复会话", OutputType.SUCCESS)
|
|
244
|
-
return True
|
|
245
|
-
except FileNotFoundError:
|
|
246
|
-
PrettyOutput.print(f"会话文件未找到: {file_path}", OutputType.ERROR)
|
|
247
|
-
return False
|
|
248
|
-
except KeyError as e:
|
|
249
|
-
PrettyOutput.print(
|
|
250
|
-
f"恢复失败: 会话文件格式不正确,缺少键 {e}", OutputType.ERROR
|
|
251
|
-
)
|
|
252
|
-
return False
|
|
253
|
-
except Exception as e:
|
|
254
|
-
PrettyOutput.print(f"恢复会话失败: {str(e)}", OutputType.ERROR)
|
|
255
|
-
return False
|
|
256
|
-
|
|
257
|
-
def get_available_models(self) -> List[str]:
|
|
258
|
-
"""Get available model list
|
|
259
|
-
|
|
260
|
-
Returns:
|
|
261
|
-
List[str]: Available model name list
|
|
262
|
-
"""
|
|
263
|
-
try:
|
|
264
|
-
if self.models:
|
|
265
|
-
return list(self.models.keys())
|
|
266
|
-
|
|
267
|
-
response = while_success(
|
|
268
|
-
lambda: http.get(
|
|
269
|
-
f"{self.BASE_URL}/api/chat/tmpl", headers=self.headers
|
|
270
|
-
),
|
|
271
|
-
sleep_time=5,
|
|
272
|
-
)
|
|
273
|
-
|
|
274
|
-
data = response.json()
|
|
275
|
-
if data["code"] != 0:
|
|
276
|
-
PrettyOutput.print(
|
|
277
|
-
f"获取模型列表失败: {data.get('msg', '未知错误')}",
|
|
278
|
-
OutputType.WARNING,
|
|
279
|
-
)
|
|
280
|
-
return []
|
|
281
|
-
|
|
282
|
-
# 保存模型信息
|
|
283
|
-
self.models = {model["value"]: model for model in data["data"]["models"]}
|
|
284
|
-
|
|
285
|
-
for model in self.models.values():
|
|
286
|
-
# 添加标签
|
|
287
|
-
model_str = f"{model['label']}"
|
|
288
|
-
|
|
289
|
-
# 添加特性标记
|
|
290
|
-
features = []
|
|
291
|
-
if model["attr"].get("multimodal"):
|
|
292
|
-
features.append("Multimodal")
|
|
293
|
-
if model["attr"].get("plugin"):
|
|
294
|
-
features.append("Plugin support")
|
|
295
|
-
if model["attr"].get("onlyImg"):
|
|
296
|
-
features.append("Image support")
|
|
297
|
-
if model["attr"].get("tag"):
|
|
298
|
-
features.append(model["attr"]["tag"])
|
|
299
|
-
if model["attr"].get("integral"):
|
|
300
|
-
features.append(model["attr"]["integral"])
|
|
301
|
-
# 添加备注
|
|
302
|
-
if model["attr"].get("note"):
|
|
303
|
-
model_str += f" - {model['attr']['note']}"
|
|
304
|
-
if features:
|
|
305
|
-
model_str += f" [{'|'.join(features)}]"
|
|
306
|
-
|
|
307
|
-
model["desc"] = model_str
|
|
308
|
-
|
|
309
|
-
return list(self.models.keys())
|
|
310
|
-
|
|
311
|
-
except Exception as e:
|
|
312
|
-
PrettyOutput.print(f"获取模型列表失败: {str(e)}", OutputType.ERROR)
|
|
313
|
-
return []
|
|
314
|
-
|
|
315
|
-
def support_upload_files(self) -> bool:
|
|
316
|
-
return False
|
|
317
|
-
|
|
318
|
-
def support_web(self) -> bool:
|
|
319
|
-
return False
|
|
320
|
-
|
|
321
|
-
def upload_files(self, file_list: List[str]) -> bool:
|
|
322
|
-
return False
|
|
323
|
-
|
|
324
|
-
@classmethod
|
|
325
|
-
def get_required_env_keys(cls) -> List[str]:
|
|
326
|
-
"""
|
|
327
|
-
获取AI8平台所需的环境变量键列表
|
|
328
|
-
|
|
329
|
-
返回:
|
|
330
|
-
List[str]: 环境变量键的列表
|
|
331
|
-
"""
|
|
332
|
-
return ["AI8_API_KEY"]
|
jarvis/jarvis_tools/ask_user.py
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# 导入所需的类型注解模块
|
|
3
|
-
from typing import Any, Dict
|
|
4
|
-
|
|
5
|
-
# 导入多行输入工具和输出工具
|
|
6
|
-
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
# 定义AskUserTool类,用于向用户提问
|
|
10
|
-
class AskUserTool:
|
|
11
|
-
name = "ask_user"
|
|
12
|
-
description = """当完成任务所需的信息缺失或关键决策信息不足时,向用户提问。用户可以输入多行文本,以空行结束。使用场景:1. 需要用户提供更多信息以完成任务;2. 需要用户做出关键决策;3. 需要用户确认重要操作;4. 需要用户提供额外信息"""
|
|
13
|
-
# 定义参数结构,指定必须包含的问题字段
|
|
14
|
-
parameters = {
|
|
15
|
-
"type": "object",
|
|
16
|
-
"properties": {
|
|
17
|
-
"question": {"type": "string", "description": "要向用户提出的问题"}
|
|
18
|
-
},
|
|
19
|
-
"required": ["question"],
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
23
|
-
"""执行向用户提问的操作
|
|
24
|
-
|
|
25
|
-
Args:
|
|
26
|
-
args: 一个包含问题的字典
|
|
27
|
-
|
|
28
|
-
Returns:
|
|
29
|
-
Dict: 一个包含用户响应的字典
|
|
30
|
-
"""
|
|
31
|
-
try:
|
|
32
|
-
# 从参数中获取问题
|
|
33
|
-
question = args["question"]
|
|
34
|
-
|
|
35
|
-
# 获取agent对象并重置工具调用计数
|
|
36
|
-
agent = args["agent"]
|
|
37
|
-
agent.set_run_input_handlers_next_turn(True)
|
|
38
|
-
|
|
39
|
-
# 显示问题给用户
|
|
40
|
-
PrettyOutput.print(f"问题: {question}", OutputType.SYSTEM)
|
|
41
|
-
|
|
42
|
-
# 获取用户输入
|
|
43
|
-
user_response = agent.multiline_inputer("请输入您的答案 (输入空行结束)")
|
|
44
|
-
|
|
45
|
-
# 返回成功响应,包含用户输入的内容
|
|
46
|
-
return {"success": True, "stdout": user_response, "stderr": ""}
|
|
47
|
-
|
|
48
|
-
except Exception as e:
|
|
49
|
-
# 如果发生异常,返回失败响应,包含错误信息
|
|
50
|
-
return {
|
|
51
|
-
"success": False,
|
|
52
|
-
"stdout": "",
|
|
53
|
-
"stderr": f"Failed to ask user: {str(e)}",
|
|
54
|
-
}
|