jarvis-ai-assistant 0.1.111__py3-none-any.whl → 0.1.112__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 jarvis-ai-assistant might be problematic. Click here for more details.

Files changed (46) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/agent.py +40 -34
  3. jarvis/jarvis_code_agent/code_agent.py +23 -5
  4. jarvis/jarvis_code_agent/file_select.py +16 -16
  5. jarvis/jarvis_code_agent/patch.py +17 -11
  6. jarvis/jarvis_code_agent/relevant_files.py +33 -40
  7. jarvis/jarvis_codebase/main.py +57 -48
  8. jarvis/jarvis_lsp/cpp.py +1 -1
  9. jarvis/jarvis_lsp/go.py +1 -1
  10. jarvis/jarvis_lsp/python.py +0 -2
  11. jarvis/jarvis_lsp/registry.py +13 -13
  12. jarvis/jarvis_lsp/rust.py +1 -1
  13. jarvis/jarvis_platform/ai8.py +14 -14
  14. jarvis/jarvis_platform/base.py +1 -1
  15. jarvis/jarvis_platform/kimi.py +17 -17
  16. jarvis/jarvis_platform/ollama.py +14 -14
  17. jarvis/jarvis_platform/openai.py +8 -8
  18. jarvis/jarvis_platform/oyi.py +19 -19
  19. jarvis/jarvis_platform/registry.py +6 -6
  20. jarvis/jarvis_platform_manager/main.py +17 -17
  21. jarvis/jarvis_rag/main.py +25 -25
  22. jarvis/jarvis_smart_shell/main.py +6 -6
  23. jarvis/jarvis_tools/ask_codebase.py +3 -3
  24. jarvis/jarvis_tools/ask_user.py +2 -2
  25. jarvis/jarvis_tools/create_code_agent.py +8 -8
  26. jarvis/jarvis_tools/create_sub_agent.py +2 -2
  27. jarvis/jarvis_tools/execute_shell.py +2 -2
  28. jarvis/jarvis_tools/file_operation.py +1 -1
  29. jarvis/jarvis_tools/git_commiter.py +4 -4
  30. jarvis/jarvis_tools/methodology.py +3 -3
  31. jarvis/jarvis_tools/rag.py +3 -3
  32. jarvis/jarvis_tools/read_code.py +1 -1
  33. jarvis/jarvis_tools/read_webpage.py +19 -6
  34. jarvis/jarvis_tools/registry.py +11 -11
  35. jarvis/jarvis_tools/search.py +88 -27
  36. jarvis/jarvis_tools/select_code_files.py +1 -1
  37. jarvis/jarvis_tools/tool_generator.py +182 -0
  38. jarvis/utils.py +18 -20
  39. jarvis_ai_assistant-0.1.112.dist-info/METADATA +460 -0
  40. jarvis_ai_assistant-0.1.112.dist-info/RECORD +64 -0
  41. jarvis_ai_assistant-0.1.111.dist-info/METADATA +0 -461
  42. jarvis_ai_assistant-0.1.111.dist-info/RECORD +0 -63
  43. {jarvis_ai_assistant-0.1.111.dist-info → jarvis_ai_assistant-0.1.112.dist-info}/LICENSE +0 -0
  44. {jarvis_ai_assistant-0.1.111.dist-info → jarvis_ai_assistant-0.1.112.dist-info}/WHEEL +0 -0
  45. {jarvis_ai_assistant-0.1.111.dist-info → jarvis_ai_assistant-0.1.112.dist-info}/entry_points.txt +0 -0
  46. {jarvis_ai_assistant-0.1.111.dist-info → jarvis_ai_assistant-0.1.112.dist-info}/top_level.txt +0 -0
@@ -26,24 +26,24 @@ class KimiModel(BasePlatform):
26
26
  self.api_key = os.getenv("KIMI_API_KEY")
27
27
  if not self.api_key:
28
28
  message = (
29
- "Need to set KIMI_API_KEY to use Jarvis. Please follow the steps below:\n"
30
- "1. Get Kimi API Key:\n"
31
- " • Visit Kimi AI platform: https://kimi.moonshot.cn\n"
32
- " • Login to your account\n"
33
- " • Open browser developer tools (F12 or right-click -> Inspect)\n"
34
- " • Switch to the Network tab\n"
35
- " • Send any message\n"
36
- " • Find the Authorization header in the request\n"
37
- " • Copy the token value (remove the 'Bearer ' prefix)\n"
38
- "2. Set environment variable:\n"
39
- " • Method 1: Create or edit ~/.jarvis/env file:\n"
29
+ "需要设置 KIMI_API_KEY 才能使用 Jarvis。请按照以下步骤操作:\n"
30
+ "1. 获取 Kimi API Key:\n"
31
+ " • 访问 Kimi AI 平台: https://kimi.moonshot.cn\n"
32
+ " • 登录您的账户\n"
33
+ " • 打开浏览器开发者工具 (F12 或右键 -> 检查)\n"
34
+ " • 切换到网络标签\n"
35
+ " • 发送任意消息\n"
36
+ " • 在请求中找到 Authorization 头\n"
37
+ " • 复制 token 值(去掉 'Bearer ' 前缀)\n"
38
+ "2. 设置环境变量:\n"
39
+ " • 方法 1: 创建或编辑 ~/.jarvis/env 文件:\n"
40
40
  " echo 'KIMI_API_KEY=your_key_here' > ~/.jarvis/env\n"
41
- " • Method 2: Set environment variable directly:\n"
41
+ " • 方法 2: 直接设置环境变量:\n"
42
42
  " export KIMI_API_KEY=your_key_here\n"
43
- "After setting, run Jarvis again."
43
+ "设置后,重新运行 Jarvis"
44
44
  )
45
45
  PrettyOutput.print(message, OutputType.INFO)
46
- PrettyOutput.print("KIMI_API_KEY is not set", OutputType.WARNING)
46
+ PrettyOutput.print("KIMI_API_KEY 未设置", OutputType.WARNING)
47
47
  self.auth_header = f"Bearer {self.api_key}"
48
48
  self.chat_id = ""
49
49
  self.uploaded_files = [] # 存储已上传文件的信息
@@ -75,7 +75,7 @@ class KimiModel(BasePlatform):
75
75
  self.chat_id = response.json()["id"]
76
76
  return True
77
77
  except Exception as e:
78
- PrettyOutput.print(f"Error: Failed to create chat: {e}", OutputType.ERROR)
78
+ PrettyOutput.print(f"错误:创建会话失败:{e}", OutputType.ERROR)
79
79
  return False
80
80
 
81
81
  def _get_presigned_url(self, filename: str, action: str) -> Dict:
@@ -105,7 +105,7 @@ class KimiModel(BasePlatform):
105
105
  response = while_success(lambda: requests.put(presigned_url, data=content), sleep_time=5)
106
106
  return response.status_code == 200
107
107
  except Exception as e:
108
- PrettyOutput.print(f"Error: Failed to upload file: {e}", OutputType.ERROR)
108
+ PrettyOutput.print(f"错误:上传文件失败:{e}", OutputType.ERROR)
109
109
  return False
110
110
 
111
111
  def _get_file_info(self, file_data: Dict, name: str, file_type: str) -> Dict:
@@ -202,7 +202,7 @@ class KimiModel(BasePlatform):
202
202
  else:
203
203
  uploaded_files.append(file_info)
204
204
  else:
205
- PrettyOutput.print(f"Error: 文件上传失败: {file_path}", OutputType.ERROR)
205
+ PrettyOutput.print(f"错误:文件上传失败: {file_path}", OutputType.ERROR)
206
206
 
207
207
  except Exception as e:
208
208
  PrettyOutput.print(f"✗ 处理文件出错 {file_path}: {str(e)}", OutputType.ERROR)
@@ -26,21 +26,21 @@ class OllamaPlatform(BasePlatform):
26
26
 
27
27
  if not available_models:
28
28
  message = (
29
- "Need to download Ollama model first to use:\n"
30
- "1. Install Ollama: https://ollama.ai\n"
31
- "2. Download model:\n"
29
+ "需要先下载 Ollama 模型才能使用:\n"
30
+ "1. 安装 Ollama: https://ollama.ai\n"
31
+ "2. 下载模型:\n"
32
32
  f" ollama pull {self.model_name}"
33
33
  )
34
34
  PrettyOutput.print(message, OutputType.INFO)
35
- PrettyOutput.print("Ollama has no available models", OutputType.WARNING)
35
+ PrettyOutput.print("Ollama 没有可用的模型", OutputType.WARNING)
36
36
 
37
37
  except requests.exceptions.ConnectionError:
38
38
  message = (
39
- "Ollama service is not started or cannot be connected\n"
40
- "Please ensure that you have:\n"
41
- "1. Installed Ollama: https://ollama.ai\n"
42
- "2. Started Ollama service\n"
43
- "3. Service address configured correctly (default: http://localhost:11434)"
39
+ "Ollama 服务未启动或无法连接\n"
40
+ "请确保您已:\n"
41
+ "1. 安装 Ollama: https://ollama.ai\n"
42
+ "2. 启动 Ollama 服务\n"
43
+ "3. 正确配置服务地址 (默认: http://localhost:11434)"
44
44
  )
45
45
  PrettyOutput.print(message, OutputType.WARNING)
46
46
 
@@ -108,12 +108,12 @@ class OllamaPlatform(BasePlatform):
108
108
  return full_response
109
109
 
110
110
  except Exception as e:
111
- PrettyOutput.print(f"Chat failed: {str(e)}", OutputType.ERROR)
111
+ PrettyOutput.print(f"对话失败: {str(e)}", OutputType.ERROR)
112
112
  raise Exception(f"Chat failed: {str(e)}")
113
113
 
114
114
  def upload_files(self, file_list: List[str]) -> List[Dict]:
115
115
  """Upload files (Ollama does not support file upload)"""
116
- PrettyOutput.print("Ollama does not support file upload", output_type=OutputType.WARNING)
116
+ PrettyOutput.print("Ollama 不支持文件上传", output_type=OutputType.WARNING)
117
117
  return []
118
118
 
119
119
  def reset(self):
@@ -142,10 +142,10 @@ if __name__ == "__main__":
142
142
  ollama = OllamaPlatform()
143
143
  while True:
144
144
  try:
145
- message = get_single_line_input("Input question (Ctrl+C to exit)")
145
+ message = get_single_line_input("输入问题 (Ctrl+C 退出)")
146
146
  ollama.chat_until_success(message)
147
147
  except KeyboardInterrupt:
148
- print("Goodbye!")
148
+ print("再见!")
149
149
  break
150
150
  except Exception as e:
151
- PrettyOutput.print(f"Program exited with an exception: {str(e)}", OutputType.ERROR)
151
+ PrettyOutput.print(f"程序异常退出: {str(e)}", OutputType.ERROR)
@@ -20,21 +20,21 @@ class OpenAIModel(BasePlatform):
20
20
  self.api_key = os.getenv("OPENAI_API_KEY")
21
21
  if not self.api_key:
22
22
  message = (
23
- "Need to set the following environment variables to use OpenAI model:\n"
24
- " • OPENAI_API_KEY: API key\n"
25
- " • OPENAI_API_BASE: (optional) API base address, default using https://api.openai.com/v1\n"
26
- "You can set them in the following ways:\n"
27
- "1. Create or edit ~/.jarvis/env file:\n"
23
+ "需要设置以下环境变量才能使用 OpenAI 模型:\n"
24
+ " • OPENAI_API_KEY: API 密钥\n"
25
+ " • OPENAI_API_BASE: (可选) API 基础地址, 默认使用 https://api.openai.com/v1\n"
26
+ "您可以通过以下方式设置它们:\n"
27
+ "1. 创建或编辑 ~/.jarvis/env 文件:\n"
28
28
  " OPENAI_API_KEY=your_api_key\n"
29
29
  " OPENAI_API_BASE=your_api_base\n"
30
30
  " OPENAI_MODEL_NAME=your_model_name\n"
31
- "2. Or set the environment variables directly:\n"
31
+ "2. 直接设置环境变量:\n"
32
32
  " export OPENAI_API_KEY=your_api_key\n"
33
33
  " export OPENAI_API_BASE=your_api_base\n"
34
34
  " export OPENAI_MODEL_NAME=your_model_name"
35
35
  )
36
36
  PrettyOutput.print(message, OutputType.INFO)
37
- PrettyOutput.print("OPENAI_API_KEY is not set", OutputType.WARNING)
37
+ PrettyOutput.print("OPENAI_API_KEY 未设置", OutputType.WARNING)
38
38
 
39
39
  self.base_url = os.getenv("OPENAI_API_BASE", "https://api.openai.com/v1")
40
40
  self.model_name = os.getenv("JARVIS_MODEL") or "gpt-4o"
@@ -92,7 +92,7 @@ class OpenAIModel(BasePlatform):
92
92
  return full_response
93
93
 
94
94
  except Exception as e:
95
- PrettyOutput.print(f"Chat failed: {str(e)}", OutputType.ERROR)
95
+ PrettyOutput.print(f"对话失败:{str(e)}", OutputType.ERROR)
96
96
  raise Exception(f"Chat failed: {str(e)}")
97
97
 
98
98
  def name(self) -> str:
@@ -29,11 +29,11 @@ class OyiModel(BasePlatform):
29
29
 
30
30
  self.token = os.getenv("OYI_API_KEY")
31
31
  if not self.token:
32
- PrettyOutput.print("OYI_API_KEY is not set", OutputType.WARNING)
32
+ PrettyOutput.print("OYI_API_KEY 未设置", OutputType.WARNING)
33
33
 
34
34
  self.model_name = os.getenv("JARVIS_MODEL") or "deepseek-chat"
35
35
  if self.model_name not in [m.split()[0] for m in self.get_available_models()]:
36
- PrettyOutput.print(f"Warning: The selected model {self.model_name} is not in the available list", OutputType.WARNING)
36
+ PrettyOutput.print(f"警告: 选择的模型 {self.model_name} 不在可用列表中", OutputType.WARNING)
37
37
 
38
38
 
39
39
  def set_model_name(self, model_name: str):
@@ -83,14 +83,14 @@ class OyiModel(BasePlatform):
83
83
  self.conversation = data
84
84
  return True
85
85
  else:
86
- PrettyOutput.print(f"Create conversation failed: {data['message']}", OutputType.ERROR)
86
+ PrettyOutput.print(f"创建会话失败: {data['message']}", OutputType.ERROR)
87
87
  return False
88
88
  else:
89
- PrettyOutput.print(f"Create conversation failed: {response.status_code}", OutputType.ERROR)
89
+ PrettyOutput.print(f"创建会话失败: {response.status_code}", OutputType.ERROR)
90
90
  return False
91
91
 
92
92
  except Exception as e:
93
- PrettyOutput.print(f"Create conversation failed: {str(e)}", OutputType.ERROR)
93
+ PrettyOutput.print(f"创建会话失败: {str(e)}", OutputType.ERROR)
94
94
  return False
95
95
 
96
96
  def set_system_message(self, message: str):
@@ -156,13 +156,13 @@ class OyiModel(BasePlatform):
156
156
  )
157
157
 
158
158
  if response.status_code != 200:
159
- error_msg = f"Chat request failed: {response.status_code}"
159
+ error_msg = f"聊天请求失败: {response.status_code}"
160
160
  PrettyOutput.print(error_msg, OutputType.ERROR)
161
161
  raise Exception(error_msg)
162
162
 
163
163
  data = response.json()
164
164
  if data['code'] != 200 or data['type'] != 'success':
165
- error_msg = f"Chat failed: {data.get('message', 'Unknown error')}"
165
+ error_msg = f"聊天失败: {data.get('message', '未知错误')}"
166
166
  PrettyOutput.print(error_msg, OutputType.ERROR)
167
167
  raise Exception(error_msg)
168
168
 
@@ -195,11 +195,11 @@ class OyiModel(BasePlatform):
195
195
  self.messages.append({"role": "assistant", "content": full_response})
196
196
  return full_response
197
197
  else:
198
- error_msg = f"Get response failed: {response.status_code}"
198
+ error_msg = f"获取响应失败: {response.status_code}"
199
199
  PrettyOutput.print(error_msg, OutputType.ERROR)
200
200
  raise Exception(error_msg)
201
201
  except Exception as e:
202
- PrettyOutput.print(f"Chat failed: {str(e)}", OutputType.ERROR)
202
+ PrettyOutput.print(f"聊天失败: {str(e)}", OutputType.ERROR)
203
203
  raise e
204
204
 
205
205
  def name(self) -> str:
@@ -240,16 +240,16 @@ class OyiModel(BasePlatform):
240
240
  self.reset()
241
241
  return True
242
242
  else:
243
- error_msg = f"Delete conversation failed: {data.get('message', 'Unknown error')}"
243
+ error_msg = f"删除会话失败: {data.get('message', '未知错误')}"
244
244
  PrettyOutput.print(error_msg, OutputType.ERROR)
245
245
  return False
246
246
  else:
247
- error_msg = f"Delete conversation request failed: {response.status_code}"
247
+ error_msg = f"删除会话请求失败: {response.status_code}"
248
248
  PrettyOutput.print(error_msg, OutputType.ERROR)
249
249
  return False
250
250
 
251
251
  except Exception as e:
252
- PrettyOutput.print(f"Delete conversation failed: {str(e)}", OutputType.ERROR)
252
+ PrettyOutput.print(f"删除会话失败: {str(e)}", OutputType.ERROR)
253
253
  return False
254
254
 
255
255
  def upload_files(self, file_list: List[str]) -> List[Dict]:
@@ -265,7 +265,7 @@ class OyiModel(BasePlatform):
265
265
  # 检查当前模型是否支持文件上传
266
266
  model_info = self.models.get(self.model_name)
267
267
  if not model_info or not model_info.get('uploadFile', False):
268
- PrettyOutput.print(f"The current model {self.model_name} does not support file upload", OutputType.WARNING)
268
+ PrettyOutput.print(f"当前模型 {self.model_name} 不支持文件上传", OutputType.WARNING)
269
269
  return []
270
270
 
271
271
  headers = {
@@ -281,7 +281,7 @@ class OyiModel(BasePlatform):
281
281
  # 检查文件类型
282
282
  file_type = mimetypes.guess_type(file_path)[0]
283
283
  if not file_type or not file_type.startswith(('image/', 'text/', 'application/')):
284
- PrettyOutput.print(f"The file type {file_type} is not supported", OutputType.ERROR)
284
+ PrettyOutput.print(f"文件类型 {file_type} 不支持", OutputType.ERROR)
285
285
  continue
286
286
 
287
287
  with open(file_path, 'rb') as f:
@@ -300,15 +300,15 @@ class OyiModel(BasePlatform):
300
300
  if data.get('code') == 200:
301
301
  self.files.append(data)
302
302
  else:
303
- PrettyOutput.print(f"File upload failed: {data.get('message')}", OutputType.ERROR)
303
+ PrettyOutput.print(f"文件上传失败: {data.get('message')}", OutputType.ERROR)
304
304
  return []
305
305
  else:
306
- PrettyOutput.print(f"File upload failed: {response.status_code}", OutputType.ERROR)
306
+ PrettyOutput.print(f"文件上传失败: {response.status_code}", OutputType.ERROR)
307
307
  return []
308
308
 
309
309
  return self.files
310
310
  except Exception as e:
311
- PrettyOutput.print(f"File upload failed: {str(e)}", OutputType.ERROR)
311
+ PrettyOutput.print(f"文件上传失败: {str(e)}", OutputType.ERROR)
312
312
  return []
313
313
 
314
314
  def get_available_models(self) -> List[str]:
@@ -335,7 +335,7 @@ class OyiModel(BasePlatform):
335
335
  )
336
336
 
337
337
  if response.status_code != 200:
338
- PrettyOutput.print(f"Get model list failed: {response.status_code}", OutputType.ERROR)
338
+ PrettyOutput.print(f"获取模型列表失败: {response.status_code}", OutputType.ERROR)
339
339
  return []
340
340
 
341
341
  data = response.json()
@@ -379,5 +379,5 @@ class OyiModel(BasePlatform):
379
379
  return sorted(models)
380
380
 
381
381
  except Exception as e:
382
- PrettyOutput.print(f"Get model list failed: {str(e)}", OutputType.WARNING)
382
+ PrettyOutput.print(f"获取模型列表失败: {str(e)}", OutputType.WARNING)
383
383
  return []
@@ -36,7 +36,7 @@ class PlatformRegistry:
36
36
 
37
37
  pass
38
38
  except Exception as e:
39
- PrettyOutput.print(f"Create platform directory failed: {str(e)}", OutputType.ERROR)
39
+ PrettyOutput.print(f"创建平台目录失败: {str(e)}", OutputType.ERROR)
40
40
  return ""
41
41
  return user_platform_dir
42
42
 
@@ -71,7 +71,7 @@ class PlatformRegistry:
71
71
 
72
72
  if missing_methods:
73
73
  PrettyOutput.print(
74
- f"Platform {platform_class.__name__} is missing necessary methods: {', '.join(missing_methods)}",
74
+ f"平台 {platform_class.__name__} 缺少必要的方法: {', '.join(missing_methods)}",
75
75
  OutputType.ERROR
76
76
  )
77
77
  return False
@@ -92,7 +92,7 @@ class PlatformRegistry:
92
92
 
93
93
  # 确保目录存在
94
94
  if not os.path.exists(directory):
95
- PrettyOutput.print(f"Platform directory does not exist: {directory}", OutputType.ERROR)
95
+ PrettyOutput.print(f"平台目录不存在: {directory}", OutputType.ERROR)
96
96
  return platforms
97
97
 
98
98
  # 获取目录的包名
@@ -128,7 +128,7 @@ class PlatformRegistry:
128
128
  platforms[obj.platform_name] = obj # type: ignore
129
129
  break
130
130
  except Exception as e:
131
- PrettyOutput.print(f"Load platform {module_name} failed: {str(e)}", OutputType.ERROR)
131
+ PrettyOutput.print(f"加载平台 {module_name} 失败: {str(e)}", OutputType.ERROR)
132
132
 
133
133
  return platforms
134
134
 
@@ -201,7 +201,7 @@ class PlatformRegistry:
201
201
  BasePlatform: Platform instance
202
202
  """
203
203
  if name not in self.platforms:
204
- PrettyOutput.print(f"Platform not found: {name}", OutputType.ERROR)
204
+ PrettyOutput.print(f"未找到平台: {name}", OutputType.ERROR)
205
205
  return None
206
206
 
207
207
  try:
@@ -209,7 +209,7 @@ class PlatformRegistry:
209
209
  platform = self.platforms[name]()
210
210
  return platform
211
211
  except Exception as e:
212
- PrettyOutput.print(f"Create platform failed: {str(e)}", OutputType.ERROR)
212
+ PrettyOutput.print(f"创建平台失败: {str(e)}", OutputType.ERROR)
213
213
  return None
214
214
 
215
215
  def get_available_platforms(self) -> List[str]:
@@ -31,10 +31,10 @@ def list_platforms():
31
31
  output += f" • {model_name}\n"
32
32
  PrettyOutput.print(output, OutputType.SUCCESS, lang="markdown")
33
33
  else:
34
- PrettyOutput.print(" • No available model information", OutputType.WARNING)
34
+ PrettyOutput.print(" • 没有可用的模型信息", OutputType.WARNING)
35
35
 
36
36
  except Exception as e:
37
- PrettyOutput.print(f"Failed to get model list for {platform_name}: {str(e)}", OutputType.WARNING)
37
+ PrettyOutput.print(f"获取 {platform_name} 的模型列表失败: {str(e)}", OutputType.WARNING)
38
38
 
39
39
  def chat_with_model(platform_name: str, model_name: str):
40
40
  """Chat with specified platform and model"""
@@ -43,13 +43,13 @@ def chat_with_model(platform_name: str, model_name: str):
43
43
  # Create platform instance
44
44
  platform = registry.create_platform(platform_name)
45
45
  if not platform:
46
- PrettyOutput.print(f"Failed to create platform {platform_name}", OutputType.ERROR)
46
+ PrettyOutput.print(f"创建平台 {platform_name} 失败", OutputType.ERROR)
47
47
  return
48
48
 
49
49
  try:
50
50
  # Set model
51
51
  platform.set_model_name(model_name)
52
- PrettyOutput.print(f"Connected to {platform_name} platform {model_name} model", OutputType.SUCCESS)
52
+ PrettyOutput.print(f"连接到 {platform_name} 平台 {model_name} 模型", OutputType.SUCCESS)
53
53
 
54
54
  # Start conversation loop
55
55
  while True:
@@ -58,7 +58,7 @@ def chat_with_model(platform_name: str, model_name: str):
58
58
 
59
59
  # Check if input is cancelled
60
60
  if user_input.strip() == "/bye":
61
- PrettyOutput.print("Bye!", OutputType.SUCCESS)
61
+ PrettyOutput.print("再见!", OutputType.SUCCESS)
62
62
  break
63
63
 
64
64
  # Check if input is empty
@@ -70,22 +70,22 @@ def chat_with_model(platform_name: str, model_name: str):
70
70
  try:
71
71
  platform.delete_chat()
72
72
  platform.set_model_name(model_name) # Reinitialize session
73
- PrettyOutput.print("Session cleared", OutputType.SUCCESS)
73
+ PrettyOutput.print("会话已清除", OutputType.SUCCESS)
74
74
  except Exception as e:
75
- PrettyOutput.print(f"Failed to clear session: {str(e)}", OutputType.ERROR)
75
+ PrettyOutput.print(f"清除会话失败: {str(e)}", OutputType.ERROR)
76
76
  continue
77
77
 
78
78
  try:
79
79
  # Send to model and get reply
80
80
  response = platform.chat_until_success(user_input)
81
81
  if not response:
82
- PrettyOutput.print("No valid reply", OutputType.WARNING)
82
+ PrettyOutput.print("没有有效的回复", OutputType.WARNING)
83
83
 
84
84
  except Exception as e:
85
- PrettyOutput.print(f"Failed to chat: {str(e)}", OutputType.ERROR)
85
+ PrettyOutput.print(f"聊天失败: {str(e)}", OutputType.ERROR)
86
86
 
87
87
  except Exception as e:
88
- PrettyOutput.print(f"Failed to initialize conversation: {str(e)}", OutputType.ERROR)
88
+ PrettyOutput.print(f"初始化会话失败: {str(e)}", OutputType.ERROR)
89
89
  finally:
90
90
  # Clean up resources
91
91
  try:
@@ -100,7 +100,7 @@ def info_command(args):
100
100
  def chat_command(args):
101
101
  """Process chat subcommand"""
102
102
  if not args.platform or not args.model:
103
- PrettyOutput.print("Please specify platform and model. Use 'jarvis info' to view available platforms and models.", OutputType.ERROR)
103
+ PrettyOutput.print("请指定平台和模型。使用 'jarvis info' 查看可用平台和模型。", OutputType.ERROR)
104
104
  return
105
105
  chat_with_model(args.platform, args.model)
106
106
 
@@ -110,16 +110,16 @@ def main():
110
110
 
111
111
  init_env()
112
112
 
113
- parser = argparse.ArgumentParser(description='Jarvis AI Platform')
114
- subparsers = parser.add_subparsers(dest='command', help='Available subcommands')
113
+ parser = argparse.ArgumentParser(description='Jarvis AI 平台')
114
+ subparsers = parser.add_subparsers(dest='command', help='可用子命令')
115
115
 
116
116
  # info subcommand
117
- info_parser = subparsers.add_parser('info', help='Display supported platforms and models information')
117
+ info_parser = subparsers.add_parser('info', help='显示支持的平台和模型信息')
118
118
 
119
119
  # chat subcommand
120
- chat_parser = subparsers.add_parser('chat', help='Chat with specified platform and model')
121
- chat_parser.add_argument('--platform', '-p', help='Specify the platform to use')
122
- chat_parser.add_argument('--model', '-m', help='Specify the model to use')
120
+ chat_parser = subparsers.add_parser('chat', help='与指定平台和模型聊天')
121
+ chat_parser.add_argument('--platform', '-p', help='指定要使用的平台')
122
+ chat_parser.add_argument('--model', '-m', help='指定要使用的模型')
123
123
 
124
124
  args = parser.parse_args()
125
125
 
jarvis/jarvis_rag/main.py CHANGED
@@ -154,9 +154,9 @@ class RAGTool:
154
154
  try:
155
155
  self.embedding_model = load_embedding_model()
156
156
  self.vector_dim = self.embedding_model.get_sentence_embedding_dimension()
157
- PrettyOutput.print("Model loaded", output_type=OutputType.SUCCESS)
157
+ PrettyOutput.print("模型加载完成", output_type=OutputType.SUCCESS)
158
158
  except Exception as e:
159
- PrettyOutput.print(f"Failed to load model: {str(e)}", output_type=OutputType.ERROR)
159
+ PrettyOutput.print(f"加载模型失败: {str(e)}", output_type=OutputType.ERROR)
160
160
  raise
161
161
 
162
162
  # 修改缓存相关初始化
@@ -218,7 +218,7 @@ class RAGTool:
218
218
  file_cache = pickle.load(f)
219
219
  self.documents.extend(file_cache["documents"])
220
220
  except Exception as e:
221
- PrettyOutput.print(f"Failed to load cache for {file_path}: {str(e)}",
221
+ PrettyOutput.print(f"加载缓存失败,文件路径:{file_path}: {str(e)}",
222
222
  output_type=OutputType.WARNING)
223
223
 
224
224
  # 重建向量索引
@@ -238,11 +238,11 @@ class RAGTool:
238
238
  vectors = np.vstack(vectors)
239
239
  self._build_index(vectors)
240
240
 
241
- PrettyOutput.print(f"Loaded {len(self.documents)} document fragments",
241
+ PrettyOutput.print(f"加载 {len(self.documents)} 个文档片段",
242
242
  output_type=OutputType.INFO)
243
243
 
244
244
  except Exception as e:
245
- PrettyOutput.print(f"Failed to load cache index: {str(e)}",
245
+ PrettyOutput.print(f"加载缓存索引失败: {str(e)}",
246
246
  output_type=OutputType.WARNING)
247
247
  self.documents = []
248
248
  self.index = None
@@ -276,7 +276,7 @@ class RAGTool:
276
276
  pickle.dump(index_data, f)
277
277
 
278
278
  except Exception as e:
279
- PrettyOutput.print(f"Failed to save cache: {str(e)}", output_type=OutputType.ERROR)
279
+ PrettyOutput.print(f"保存缓存失败: {str(e)}", output_type=OutputType.ERROR)
280
280
 
281
281
  def _build_index(self, vectors: np.ndarray):
282
282
  """Build FAISS index"""
@@ -382,7 +382,7 @@ class RAGTool:
382
382
 
383
383
  return get_embedding_batch(self.embedding_model, texts)
384
384
  except Exception as e:
385
- PrettyOutput.print(f"Batch processing failed: {str(e)}", OutputType.ERROR)
385
+ PrettyOutput.print(f"批量处理失败: {str(e)}", OutputType.ERROR)
386
386
  return np.zeros((0, self.vector_dim), dtype=np.float32) # type: ignore
387
387
 
388
388
  def _process_file(self, file_path: str) -> List[Document]:
@@ -436,7 +436,7 @@ class RAGTool:
436
436
  return documents
437
437
 
438
438
  except Exception as e:
439
- PrettyOutput.print(f"Failed to process file {file_path}: {str(e)}",
439
+ PrettyOutput.print(f"处理文件失败: {file_path}: {str(e)}",
440
440
  output_type=OutputType.ERROR)
441
441
  return []
442
442
 
@@ -517,7 +517,7 @@ class RAGTool:
517
517
  new_vectors.append(file_vectors)
518
518
 
519
519
  except Exception as e:
520
- PrettyOutput.print(f"Failed to process {file_path}: {str(e)}", OutputType.ERROR)
520
+ PrettyOutput.print(f"处理文件失败: {file_path}: {str(e)}", OutputType.ERROR)
521
521
 
522
522
  pbar.update(1)
523
523
 
@@ -542,9 +542,9 @@ class RAGTool:
542
542
  self._build_index(final_vectors)
543
543
 
544
544
  PrettyOutput.print(
545
- f"Indexed {len(self.documents)} documents "
546
- f"(New/Modified: {len(new_documents)}, "
547
- f"Unchanged: {len(unchanged_documents)})",
545
+ f"索引 {len(self.documents)} 个文档 "
546
+ f"(新/修改: {len(new_documents)}, "
547
+ f"不变: {len(unchanged_documents)})",
548
548
  OutputType.SUCCESS
549
549
  )
550
550
 
@@ -566,13 +566,13 @@ class RAGTool:
566
566
  return np.vstack(unchanged_vectors) if unchanged_vectors else None
567
567
 
568
568
  except Exception as e:
569
- PrettyOutput.print(f"Failed to get unchanged vectors: {str(e)}", OutputType.ERROR)
569
+ PrettyOutput.print(f"获取不变向量失败: {str(e)}", OutputType.ERROR)
570
570
  return None
571
571
 
572
572
  def search(self, query: str, top_k: int = 30) -> List[Tuple[Document, float]]:
573
573
  """Search documents with context window"""
574
574
  if not self.index:
575
- PrettyOutput.print("Index not built, building...", output_type=OutputType.INFO)
575
+ PrettyOutput.print("索引未构建,正在构建...", output_type=OutputType.INFO)
576
576
  self.build_index(self.root_dir)
577
577
 
578
578
  # Get query vector
@@ -670,7 +670,7 @@ Relevant documents (ordered by relevance):
670
670
  prompt += "3. Reference the documents in the answer.\n"
671
671
  if current_count + get_context_token_count(doc_content) > available_count:
672
672
  PrettyOutput.print(
673
- "Due to context length limit, some fragments were omitted",
673
+ "由于上下文长度限制,部分内容被省略",
674
674
  output_type=OutputType.WARNING
675
675
  )
676
676
  break
@@ -687,7 +687,7 @@ Relevant documents (ordered by relevance):
687
687
  return response
688
688
 
689
689
  except Exception as e:
690
- PrettyOutput.print(f"Failed to answer: {str(e)}", OutputType.ERROR)
690
+ PrettyOutput.print(f"回答失败:{str(e)}", OutputType.ERROR)
691
691
  return None
692
692
 
693
693
  def is_index_built(self) -> bool:
@@ -724,7 +724,7 @@ def main():
724
724
  args.dir = current_dir
725
725
 
726
726
  if args.dir and args.build:
727
- PrettyOutput.print(f"Processing directory: {args.dir}", output_type=OutputType.INFO)
727
+ PrettyOutput.print(f"正在处理目录: {args.dir}", output_type=OutputType.INFO)
728
728
  rag.build_index(args.dir)
729
729
  return 0
730
730
 
@@ -733,13 +733,13 @@ def main():
733
733
  if args.search:
734
734
  results = rag.query(args.search)
735
735
  if not results:
736
- PrettyOutput.print("No related content found", output_type=OutputType.WARNING)
736
+ PrettyOutput.print("未找到相关内容", output_type=OutputType.WARNING)
737
737
  return 1
738
738
 
739
739
  for doc in results:
740
- output = f"""File: {doc.metadata['file_path']}\n"""
741
- output += f"""Fragment {doc.metadata['chunk_index'] + 1}/{doc.metadata['total_chunks']}\n"""
742
- output += f"""Content:\n{doc.content}\n"""
740
+ output = f"""文件: {doc.metadata['file_path']}\n"""
741
+ output += f"""片段 {doc.metadata['chunk_index'] + 1}/{doc.metadata['total_chunks']}\n"""
742
+ output += f"""内容:\n{doc.content}\n"""
743
743
  PrettyOutput.print(output, output_type=OutputType.INFO, lang="markdown")
744
744
  return 0
745
745
 
@@ -747,19 +747,19 @@ def main():
747
747
  # Call ask method
748
748
  response = rag.ask(args.ask)
749
749
  if not response:
750
- PrettyOutput.print("Failed to get answer", output_type=OutputType.WARNING)
750
+ PrettyOutput.print("获取答案失败", output_type=OutputType.WARNING)
751
751
  return 1
752
752
 
753
753
  # Display answer
754
- output = f"""Answer:\n{response}"""
754
+ output = f"""答案:\n{response}"""
755
755
  PrettyOutput.print(output, output_type=OutputType.INFO)
756
756
  return 0
757
757
 
758
- PrettyOutput.print("Please specify operation parameters. Use -h to view help.", output_type=OutputType.WARNING)
758
+ PrettyOutput.print("请指定操作参数。使用 -h 查看帮助。", output_type=OutputType.WARNING)
759
759
  return 1
760
760
 
761
761
  except Exception as e:
762
- PrettyOutput.print(f"Failed to execute: {str(e)}", output_type=OutputType.ERROR)
762
+ PrettyOutput.print(f"执行失败: {str(e)}", output_type=OutputType.ERROR)
763
763
  return 1
764
764
 
765
765
  if __name__ == "__main__":