jarvis-ai-assistant 0.1.164__py3-none-any.whl → 0.1.166__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 (96) hide show
  1. jarvis/__init__.py +2 -1
  2. jarvis/jarvis_agent/__init__.py +13 -1
  3. jarvis/jarvis_agent/builtin_input_handler.py +1 -0
  4. jarvis/jarvis_agent/file_input_handler.py +1 -0
  5. jarvis/jarvis_agent/jarvis.py +1 -0
  6. jarvis/jarvis_agent/main.py +1 -0
  7. jarvis/jarvis_agent/output_handler.py +1 -0
  8. jarvis/jarvis_agent/shell_input_handler.py +1 -0
  9. jarvis/jarvis_code_agent/code_agent.py +5 -26
  10. jarvis/jarvis_code_analysis/checklists/__init__.py +1 -0
  11. jarvis/jarvis_code_analysis/checklists/c_cpp.py +1 -0
  12. jarvis/jarvis_code_analysis/checklists/csharp.py +1 -0
  13. jarvis/jarvis_code_analysis/checklists/data_format.py +1 -0
  14. jarvis/jarvis_code_analysis/checklists/devops.py +1 -0
  15. jarvis/jarvis_code_analysis/checklists/docs.py +1 -0
  16. jarvis/jarvis_code_analysis/checklists/go.py +1 -0
  17. jarvis/jarvis_code_analysis/checklists/infrastructure.py +1 -0
  18. jarvis/jarvis_code_analysis/checklists/java.py +1 -0
  19. jarvis/jarvis_code_analysis/checklists/javascript.py +1 -0
  20. jarvis/jarvis_code_analysis/checklists/kotlin.py +1 -0
  21. jarvis/jarvis_code_analysis/checklists/loader.py +1 -0
  22. jarvis/jarvis_code_analysis/checklists/php.py +1 -0
  23. jarvis/jarvis_code_analysis/checklists/python.py +1 -0
  24. jarvis/jarvis_code_analysis/checklists/ruby.py +1 -0
  25. jarvis/jarvis_code_analysis/checklists/rust.py +1 -0
  26. jarvis/jarvis_code_analysis/checklists/shell.py +1 -0
  27. jarvis/jarvis_code_analysis/checklists/sql.py +1 -0
  28. jarvis/jarvis_code_analysis/checklists/swift.py +1 -0
  29. jarvis/jarvis_code_analysis/checklists/web.py +1 -0
  30. jarvis/jarvis_code_analysis/code_review.py +1 -0
  31. jarvis/jarvis_data/huggingface.tar.gz +0 -0
  32. jarvis/jarvis_dev/main.py +1 -0
  33. jarvis/jarvis_git_details/main.py +1 -0
  34. jarvis/jarvis_git_squash/main.py +1 -0
  35. jarvis/jarvis_git_utils/git_commiter.py +55 -30
  36. jarvis/jarvis_lsp/base.py +1 -0
  37. jarvis/jarvis_lsp/cpp.py +1 -0
  38. jarvis/jarvis_lsp/go.py +1 -0
  39. jarvis/jarvis_lsp/python.py +1 -0
  40. jarvis/jarvis_lsp/registry.py +1 -0
  41. jarvis/jarvis_lsp/rust.py +1 -0
  42. jarvis/jarvis_mcp/__init__.py +1 -0
  43. jarvis/jarvis_mcp/sse_mcp_client.py +1 -0
  44. jarvis/jarvis_mcp/stdio_mcp_client.py +1 -0
  45. jarvis/jarvis_methodology/main.py +1 -0
  46. jarvis/jarvis_multi_agent/__init__.py +1 -0
  47. jarvis/jarvis_multi_agent/main.py +1 -0
  48. jarvis/jarvis_platform/__init__.py +1 -0
  49. jarvis/jarvis_platform/base.py +1 -0
  50. jarvis/jarvis_platform/human.py +1 -0
  51. jarvis/jarvis_platform/kimi.py +1 -0
  52. jarvis/jarvis_platform/openai.py +117 -0
  53. jarvis/jarvis_platform/registry.py +1 -0
  54. jarvis/jarvis_platform/yuanbao.py +3 -1
  55. jarvis/jarvis_platform_manager/main.py +1 -0
  56. jarvis/jarvis_smart_shell/main.py +1 -0
  57. jarvis/jarvis_tools/ask_codebase.py +1 -0
  58. jarvis/jarvis_tools/ask_user.py +1 -0
  59. jarvis/jarvis_tools/base.py +1 -0
  60. jarvis/jarvis_tools/chdir.py +1 -0
  61. jarvis/jarvis_tools/code_plan.py +1 -0
  62. jarvis/jarvis_tools/create_code_agent.py +1 -0
  63. jarvis/jarvis_tools/create_sub_agent.py +1 -0
  64. jarvis/jarvis_tools/edit_file.py +202 -130
  65. jarvis/jarvis_tools/execute_script.py +1 -0
  66. jarvis/jarvis_tools/file_analyzer.py +1 -0
  67. jarvis/jarvis_tools/file_operation.py +1 -0
  68. jarvis/jarvis_tools/find_methodology.py +6 -1
  69. jarvis/jarvis_tools/generate_new_tool.py +288 -0
  70. jarvis/jarvis_tools/lsp_get_diagnostics.py +1 -0
  71. jarvis/jarvis_tools/methodology.py +1 -0
  72. jarvis/jarvis_tools/read_code.py +1 -0
  73. jarvis/jarvis_tools/read_webpage.py +1 -0
  74. jarvis/jarvis_tools/registry.py +1 -0
  75. jarvis/jarvis_tools/rewrite_file.py +1 -0
  76. jarvis/jarvis_tools/search_web.py +1 -0
  77. jarvis/jarvis_tools/virtual_tty.py +1 -0
  78. jarvis/jarvis_utils/__init__.py +1 -0
  79. jarvis/jarvis_utils/builtin_replace_map.py +1 -0
  80. jarvis/jarvis_utils/config.py +1 -0
  81. jarvis/jarvis_utils/embedding.py +1 -0
  82. jarvis/jarvis_utils/file_processors.py +1 -0
  83. jarvis/jarvis_utils/git_utils.py +1 -0
  84. jarvis/jarvis_utils/globals.py +1 -0
  85. jarvis/jarvis_utils/input.py +1 -0
  86. jarvis/jarvis_utils/methodology.py +12 -5
  87. jarvis/jarvis_utils/output.py +1 -0
  88. jarvis/jarvis_utils/tag.py +1 -0
  89. jarvis/jarvis_utils/utils.py +19 -1
  90. {jarvis_ai_assistant-0.1.164.dist-info → jarvis_ai_assistant-0.1.166.dist-info}/METADATA +42 -44
  91. jarvis_ai_assistant-0.1.166.dist-info/RECORD +101 -0
  92. jarvis_ai_assistant-0.1.164.dist-info/RECORD +0 -98
  93. {jarvis_ai_assistant-0.1.164.dist-info → jarvis_ai_assistant-0.1.166.dist-info}/WHEEL +0 -0
  94. {jarvis_ai_assistant-0.1.164.dist-info → jarvis_ai_assistant-0.1.166.dist-info}/entry_points.txt +0 -0
  95. {jarvis_ai_assistant-0.1.164.dist-info → jarvis_ai_assistant-0.1.166.dist-info}/licenses/LICENSE +0 -0
  96. {jarvis_ai_assistant-0.1.164.dist-info → jarvis_ai_assistant-0.1.166.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,288 @@
1
+ # -*- coding: utf-8 -*-
2
+ import re
3
+ from pathlib import Path
4
+ from typing import Dict, Any, Tuple
5
+
6
+ from jarvis.jarvis_utils.config import get_data_dir
7
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
8
+
9
+ class generate_new_tool:
10
+ name = "generate_new_tool"
11
+ description = """
12
+ 生成并注册新的Jarvis工具。该工具会在用户数据目录下创建新的工具文件,
13
+ 并自动注册到当前的工具注册表中。适用场景:1. 需要创建新的自定义工具;
14
+ 2. 扩展Jarvis功能;3. 自动化重复性操作;4. 封装特定领域的功能。
15
+
16
+ 使用示例:
17
+
18
+ ```
19
+ # 创建一个将文本转换为大写/小写的工具
20
+ name: generate_new_tool
21
+ arguments:
22
+ tool_name: text_transformer
23
+ tool_code: |
24
+ # -*- coding: utf-8 -*-
25
+ from typing import Dict, Any
26
+
27
+ class text_transformer:
28
+ name = "text_transformer"
29
+ description = \"\"\"
30
+ 文本转换工具,可以将输入的文本转换为大写、小写或首字母大写格式。
31
+ 适用场景:1. 格式化文本; 2. 处理标题; 3. 标准化输出
32
+ \"\"\"
33
+
34
+ parameters = {
35
+ "type": "object",
36
+ "properties": {
37
+ "text": {
38
+ "type": "string",
39
+ "description": "需要转换格式的文本"
40
+ },
41
+ "transform_type": {
42
+ "type": "string",
43
+ "description": "转换类型,可选值为 upper(大写)、lower(小写)或 title(首字母大写)",
44
+ "enum": ["upper", "lower", "title"]
45
+ }
46
+ },
47
+ "required": ["text", "transform_type"]
48
+ }
49
+
50
+ @staticmethod
51
+ def check() -> bool:
52
+ return True
53
+
54
+ def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
55
+ try:
56
+ text = args["text"]
57
+ transform_type = args["transform_type"]
58
+
59
+ if transform_type == "upper":
60
+ result = text.upper()
61
+ elif transform_type == "lower":
62
+ result = text.lower()
63
+ elif transform_type == "title":
64
+ result = text.title()
65
+ else:
66
+ return {
67
+ "success": False,
68
+ "stdout": "",
69
+ "stderr": f"不支持的转换类型: {transform_type}"
70
+ }
71
+
72
+ return {
73
+ "success": True,
74
+ "stdout": result,
75
+ "stderr": ""
76
+ }
77
+
78
+ except Exception as e:
79
+ return {
80
+ "success": False,
81
+ "stdout": "",
82
+ "stderr": f"转换失败: {str(e)}"
83
+ }
84
+ ```
85
+
86
+ 创建完成后可以立即使用:
87
+
88
+ ```
89
+ name: text_transformer
90
+ arguments:
91
+ text: hello world
92
+ transform_type: upper
93
+ ```
94
+ """
95
+
96
+ parameters = {
97
+ "type": "object",
98
+ "properties": {
99
+ "tool_name": {
100
+ "type": "string",
101
+ "description": "新工具的名称,将用作文件名和工具类名"
102
+ },
103
+ "tool_code": {
104
+ "type": "string",
105
+ "description": "工具的完整Python代码,包含类定义、名称、描述、参数和execute方法"
106
+ }
107
+ },
108
+ "required": ["tool_name", "tool_code"]
109
+ }
110
+
111
+ @staticmethod
112
+ def check() -> bool:
113
+ """检查工具是否可用"""
114
+ # 检查数据目录是否存在
115
+ data_dir = get_data_dir()
116
+ tools_dir = Path(data_dir) / "tools"
117
+
118
+ # 如果tools目录不存在,尝试创建
119
+ if not tools_dir.exists():
120
+ try:
121
+ tools_dir.mkdir(parents=True, exist_ok=True)
122
+ return True
123
+ except Exception as e:
124
+ PrettyOutput.print(f"无法创建工具目录 {tools_dir}: {e}", OutputType.ERROR)
125
+ return False
126
+
127
+ return True
128
+
129
+ def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
130
+ """
131
+ 生成新工具并注册到当前的工具注册表中
132
+
133
+ 参数:
134
+ args: 包含工具名称和工具代码的字典
135
+
136
+ 返回:
137
+ Dict: 包含生成结果的字典
138
+ """
139
+ try:
140
+ # 从参数中获取工具信息
141
+ tool_name = args["tool_name"]
142
+ tool_code = args["tool_code"]
143
+ agent = args.get("agent", None)
144
+
145
+ # 验证工具名称
146
+ if not tool_name.isidentifier():
147
+ return {
148
+ "success": False,
149
+ "stdout": "",
150
+ "stderr": f"工具名称 '{tool_name}' 不是有效的Python标识符"
151
+ }
152
+
153
+ # 准备工具目录
154
+ tools_dir = Path(get_data_dir()) / "tools"
155
+ tools_dir.mkdir(parents=True, exist_ok=True)
156
+
157
+ # 生成工具文件路径
158
+ tool_file_path = tools_dir / f"{tool_name}.py"
159
+
160
+ # 检查是否已存在同名工具
161
+ if tool_file_path.exists():
162
+ return {
163
+ "success": False,
164
+ "stdout": "",
165
+ "stderr": f"工具 '{tool_name}' 已经存在于 {tool_file_path}"
166
+ }
167
+
168
+ # 验证并处理工具代码
169
+ processed_code, error_msg = self._validate_and_process_code(tool_name, tool_code)
170
+ if error_msg:
171
+ return {
172
+ "success": False,
173
+ "stdout": "",
174
+ "stderr": error_msg
175
+ }
176
+
177
+ # 写入工具文件
178
+ with open(tool_file_path, "w", encoding="utf-8") as f:
179
+ f.write(processed_code)
180
+
181
+ # 注册新工具到当前的工具注册表
182
+ success_message = f"工具 '{tool_name}' 已成功生成在 {tool_file_path}"
183
+
184
+ if agent:
185
+ tool_registry = agent.get_tool_registry()
186
+ if tool_registry:
187
+ # 尝试加载并注册新工具
188
+ if tool_registry.register_tool_by_file(str(tool_file_path)):
189
+ success_message += f"\n已成功注册到当前会话的工具注册表中"
190
+ else:
191
+ success_message += f"\n注册到当前会话失败,可能需要重新启动Jarvis"
192
+
193
+ return {
194
+ "success": True,
195
+ "stdout": success_message,
196
+ "stderr": ""
197
+ }
198
+
199
+ except Exception as e:
200
+ # 如果发生异常,返回失败响应,包含错误信息
201
+ return {
202
+ "success": False,
203
+ "stdout": "",
204
+ "stderr": f"生成工具失败: {str(e)}"
205
+ }
206
+
207
+ def _validate_and_process_code(self, tool_name: str, tool_code: str) -> Tuple[str, str]:
208
+ """
209
+ 验证并处理工具代码
210
+
211
+ 参数:
212
+ tool_name: 工具名称
213
+ tool_code: 工具代码
214
+
215
+ 返回:
216
+ Tuple[str, str]: (处理后的代码, 错误信息)
217
+ """
218
+ # 检查工具代码中是否包含类定义
219
+ if f"class {tool_name}" not in tool_code:
220
+ # 尝试找到任何类定义
221
+ class_match = re.search(r"class\s+(\w+)", tool_code)
222
+ if class_match:
223
+ old_class_name = class_match.group(1)
224
+ # 替换类名为工具名
225
+ tool_code = tool_code.replace(f"class {old_class_name}", f"class {tool_name}")
226
+ tool_code = tool_code.replace(f'name = "{old_class_name}"', f'name = "{tool_name}"')
227
+ else:
228
+ # 没有找到类定义,返回错误
229
+ return "", f"工具代码中缺少类定义 'class {tool_name}'"
230
+
231
+ # 检查工具代码中是否包含必要的属性和方法
232
+ missing_components = []
233
+
234
+ if f'name = "{tool_name}"' not in tool_code and f"name = '{tool_name}'" not in tool_code:
235
+ # 尝试查找任何name属性并修复
236
+ name_match = re.search(r'name\s*=\s*["\'](\w+)["\']', tool_code)
237
+ if name_match:
238
+ old_name = name_match.group(1)
239
+ tool_code = re.sub(r'name\s*=\s*["\'](\w+)["\']', f'name = "{tool_name}"', tool_code)
240
+ else:
241
+ missing_components.append(f"name = \"{tool_name}\"")
242
+
243
+ if "description = " not in tool_code:
244
+ missing_components.append("description 属性")
245
+
246
+ if "parameters = " not in tool_code:
247
+ missing_components.append("parameters 属性")
248
+
249
+ if "def execute(self, args:" not in tool_code:
250
+ missing_components.append("execute 方法")
251
+
252
+ if "def check(" not in tool_code:
253
+ # 添加默认的check方法
254
+ class_match = re.search(r"class\s+(\w+).*?:", tool_code, re.DOTALL)
255
+ if class_match:
256
+ indent = " " # 默认缩进
257
+ # 找到类定义后的第一个属性
258
+ first_attr_match = re.search(r"class\s+(\w+).*?:(.*?)(\w+\s*=)", tool_code, re.DOTALL)
259
+ if first_attr_match:
260
+ # 获取属性前的缩进
261
+ attr_indent = re.search(r"\n([ \t]*)\w+\s*=", first_attr_match.group(2))
262
+ if attr_indent:
263
+ indent = attr_indent.group(1)
264
+
265
+ check_method = f"\n{indent}@staticmethod\n{indent}def check() -> bool:\n{indent} \"\"\"检查工具是否可用\"\"\"\n{indent} return True\n"
266
+
267
+ # 在类定义后插入check方法
268
+ pattern = r"(class\s+(\w+).*?:.*?)(\n\s*\w+\s*=|\n\s*@|\n\s*def)"
269
+ replacement = r"\1" + check_method + r"\3"
270
+ tool_code = re.sub(pattern, replacement, tool_code, 1, re.DOTALL)
271
+
272
+ # 如果缺少必要组件,返回错误信息
273
+ if missing_components:
274
+ return "", f"工具代码中缺少以下必要组件: {', '.join(missing_components)}"
275
+
276
+ # 确保代码有正确的Python文件头部
277
+ if not tool_code.startswith("# -*- coding:") and not tool_code.startswith("# coding="):
278
+ tool_code = "# -*- coding: utf-8 -*-\n" + tool_code
279
+
280
+ # 确保导入了必要的模块
281
+ if "from typing import Dict, Any" not in tool_code:
282
+ imports_pos = tool_code.find("\n\n")
283
+ if imports_pos > 0:
284
+ tool_code = tool_code[:imports_pos] + "\nfrom typing import Dict, Any" + tool_code[imports_pos:]
285
+ else:
286
+ tool_code = "from typing import Dict, Any\n\n" + tool_code
287
+
288
+ return tool_code, ""
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import os
2
3
  from typing import Dict, Any
3
4
  from jarvis.jarvis_lsp.registry import LSPRegistry
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import os
2
3
  import json
3
4
  import hashlib
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from typing import Dict, Any
2
3
  import os
3
4
 
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from typing import Dict, Any
2
3
  import os
3
4
  from jarvis.jarvis_platform.registry import PlatformRegistry
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import json
2
3
  from pathlib import Path
3
4
  import re
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  文件重写工具类
3
4
 
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import os
2
3
  from typing import Any, Dict
3
4
  from jarvis.jarvis_platform.registry import PlatformRegistry
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from typing import Dict, Any
2
3
  import os
3
4
  import time
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  Jarvis工具模块
3
4
  该模块提供了Jarvis系统中使用的各种实用函数和类。
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """内置替换映射表模块。
2
3
 
3
4
  该模块定义了Jarvis系统内置的默认替换映射表。
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import os
2
3
  from functools import lru_cache
3
4
  import yaml
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import os
2
3
  from transformers import AutoTokenizer
3
4
  from typing import List
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import unicodedata
2
3
 
3
4
  class FileProcessor:
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  Git工具模块
3
4
  该模块提供了与Git仓库交互的工具。
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  全局变量和配置模块
3
4
  该模块管理Jarvis系统的全局状态和配置。
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  输入处理模块
3
4
  该模块提供了处理Jarvis系统中用户输入的实用工具。
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  方法论管理模块
3
4
  该模块提供了加载和搜索方法论的实用工具。
@@ -9,7 +10,7 @@
9
10
  import os
10
11
  import json
11
12
  import tempfile
12
- from typing import Dict, Optional
13
+ from typing import Any, Dict, Optional
13
14
 
14
15
  from jarvis.jarvis_utils.config import get_data_dir
15
16
  from jarvis.jarvis_utils.output import PrettyOutput, OutputType
@@ -91,7 +92,7 @@ def _create_methodology_temp_file(methodologies: Dict[str, str]) -> Optional[str
91
92
  PrettyOutput.print(f"创建方法论临时文件失败: {str(e)}", OutputType.ERROR)
92
93
  return None
93
94
 
94
- def load_methodology(user_input: str) -> str:
95
+ def load_methodology(user_input: str, tool_registery: Optional[Any] = None) -> str:
95
96
  """
96
97
  加载方法论并上传到大模型。
97
98
 
@@ -102,6 +103,9 @@ def load_methodology(user_input: str) -> str:
102
103
  str: 相关的方法论提示,如果未找到方法论则返回空字符串
103
104
  """
104
105
  from yaspin import yaspin # type: ignore
106
+ from jarvis.jarvis_tools.registry import ToolRegistry
107
+
108
+ prompt = tool_registery.prompt() if tool_registery else ""
105
109
 
106
110
  # 获取方法论目录
107
111
  methodology_dir = _get_methodology_directory()
@@ -132,10 +136,13 @@ def load_methodology(user_input: str) -> str:
132
136
  full_content = base_prompt
133
137
  for problem_type, content in methodologies.items():
134
138
  full_content += f"## {problem_type}\n\n{content}\n\n---\n\n"
139
+
140
+ full_content += f"以下是所有可用的工具内容:\n\n"
141
+ full_content += prompt
135
142
 
136
143
  # 添加用户输入和输出要求
137
144
  full_content += f"""
138
- 请根据以上方法论内容,规划/总结出以下用户需求的执行步骤: {user_input}
145
+ 请根据以上方法论和可调用的工具内容,规划/总结出以下用户需求的执行步骤: {user_input}
139
146
 
140
147
  请按以下格式回复:
141
148
  ### 与该任务/需求相关的方法论
@@ -174,7 +181,7 @@ def load_methodology(user_input: str) -> str:
174
181
  if upload_success:
175
182
  # 使用上传的文件生成摘要
176
183
  return platform.chat_until_success(base_prompt + f"""
177
- 请根据已上传的方法论文件内容,规划/总结出以下用户需求的执行步骤: {user_input}
184
+ 请根据已上传的方法论和可调用的工具文件内容,规划/总结出以下用户需求的执行步骤: {user_input}
178
185
 
179
186
  请按以下格式回复:
180
187
  ### 与该任务/需求相关的方法论
@@ -191,7 +198,7 @@ def load_methodology(user_input: str) -> str:
191
198
  elif hasattr(platform, 'chat_big_content'):
192
199
  # 如果上传失败但支持大内容处理,使用chat_big_content
193
200
  return platform.chat_big_content(full_content, base_prompt + f"""
194
- 请根据以上方法论内容,规划/总结出以下用户需求的执行步骤: {user_input}
201
+ 请根据以上方法论和可调用的工具文件内容,规划/总结出以下用户需求的执行步骤: {user_input}
195
202
 
196
203
  请按以下格式回复:
197
204
  ### 与该任务/需求相关的方法论
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  输出格式化模块
3
4
  该模块为Jarvis系统提供了丰富的文本格式化和显示工具。
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  def ot(tag_name: str) -> str:
2
3
  """生成HTML标签开始标记
3
4
 
@@ -1,6 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+ from doctest import script_from_examples
1
3
  import os
2
4
  import time
3
5
  import hashlib
6
+ import tarfile
4
7
  from pathlib import Path
5
8
  from typing import List, Any, Callable
6
9
  from jarvis.jarvis_utils.config import INPUT_WINDOW_REVERSE_SIZE, get_max_input_token_count, get_data_dir
@@ -18,9 +21,24 @@ def init_env() -> None:
18
21
  jarvis_dir = Path(get_data_dir())
19
22
  env_file = jarvis_dir / "env"
20
23
 
24
+ script_dir = Path(os.path.dirname(os.path.dirname(__file__)))
25
+ hf_archive = script_dir / "jarvis_data" / "huggingface.tar.gz"
26
+
21
27
  # 检查jarvis_data目录是否存在
22
28
  if not jarvis_dir.exists():
23
29
  jarvis_dir.mkdir(parents=True)
30
+
31
+ # 检查并解压huggingface模型
32
+ hf_dir = jarvis_dir / "huggingface" / "hub"
33
+ if not hf_dir.exists() and hf_archive.exists():
34
+ try:
35
+ PrettyOutput.print("正在解压HuggingFace模型...", OutputType.INFO)
36
+ with tarfile.open(hf_archive, "r:gz") as tar:
37
+ tar.extractall(path=jarvis_dir)
38
+ PrettyOutput.print("HuggingFace模型解压完成", OutputType.SUCCESS)
39
+ except Exception as e:
40
+ PrettyOutput.print(f"解压HuggingFace模型失败: {e}", OutputType.ERROR)
41
+
24
42
  if env_file.exists():
25
43
  try:
26
44
  with open(env_file, "r", encoding="utf-8", errors="ignore") as f:
@@ -48,7 +66,7 @@ def while_success(func: Callable[[], Any], sleep_time: float = 0.1) -> Any:
48
66
  try:
49
67
  return func()
50
68
  except Exception as e:
51
- PrettyOutput.print(f"执行失败: {str(e)}, 等待 {sleep_time}s...", OutputType.ERROR)
69
+ PrettyOutput.print(f"执行失败: {str(e)}, 等待 {sleep_time}s...", OutputType.WARNING)
52
70
  time.sleep(sleep_time)
53
71
  continue
54
72
  def while_true(func: Callable[[], bool], sleep_time: float = 0.1) -> Any:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jarvis-ai-assistant
3
- Version: 0.1.164
3
+ Version: 0.1.166
4
4
  Summary: Jarvis: An AI assistant that uses tools to interact with the system
5
5
  Home-page: https://github.com/skyfireitdiy/Jarvis
6
6
  Author: skyfire
@@ -55,6 +55,7 @@ Requires-Dist: torch==2.4.1
55
55
  Requires-Dist: python-Levenshtein==0.25.1
56
56
  Requires-Dist: sseclient==0.0.27
57
57
  Requires-Dist: pillow==10.2.0
58
+ Requires-Dist: openai==1.78.1
58
59
  Provides-Extra: dev
59
60
  Requires-Dist: pytest; extra == "dev"
60
61
  Requires-Dist: black; extra == "dev"
@@ -105,11 +106,19 @@ Dynamic: requires-python
105
106
 
106
107
 
107
108
  ## 🚀 快速开始 <a id="quick-start"></a>
109
+ ### 系统要求
110
+ - 目前只能在Linux系统下使用(很多工具依赖Linux系统)
111
+ - Windows没有测试过,但Windows 10以上的用户可以在WSL上使用此工具
112
+
108
113
  ### 安装
109
114
  ```bash
115
+ # 从源码安装(推荐)
110
116
  git clone https://github.com/skyfireitdiy/Jarvis
111
117
  cd Jarvis
112
118
  pip3 install -e .
119
+
120
+ # 或者从PyPI安装(可能更新不及时)
121
+ pip3 install jarvis-ai-assistant
113
122
  ```
114
123
 
115
124
  ### 最小化配置
@@ -148,55 +157,44 @@ Kimi API Key获取方式:
148
157
 
149
158
  删除Bearer前缀,剩下的内容就是Kimi API Key。
150
159
 
151
- 以上配置编写到`~/.jarvis/env`文件中。
152
160
 
153
- ### 基本使用
161
+ #### OpenAI
154
162
  ```bash
155
- # 使用通用代理
156
- jarvis
157
-
158
- # 使用代码代理
159
- jarvis-code-agent
160
- # 或者 jca
161
-
162
- # 使用智能shell的功能
163
- jarvis-smart-shell --help
164
- # 或者 jss
165
-
166
- # 使用平台管理的功能
167
- jarvis-platform-manager --help
168
-
169
- # 使用代码审查的功能
170
- jarvis-code-review --help
171
-
172
- # 使用自动化git commit的功能
173
- jarvis-git-commit --help
174
- # 或者 jgc
175
-
176
- # 使用dev功能(开发中)
177
- jarvis-dev --help
178
-
179
- # 使用git squash的功能
180
- jarvis-git-squash --help
181
-
182
- # 使用多代理的功能
183
- jarvis-multi-agent --help
184
-
185
- # 使用agent的功能
186
- jarvis-agent --help
163
+ JARVIS_PLATFORM=openai
164
+ JARVIS_MODEL=gpt-4o # 默认模型,可选gpt-4-turbo, gpt-3.5-turbo等
165
+ JARVIS_THINKING_PLATFORM=openai
166
+ JARVIS_THINKING_MODEL=gpt-4o
167
+
168
+ OPENAI_API_KEY=<OpenAI API Key>
169
+ OPENAI_API_BASE=https://api.openai.com/v1 # 可选,默认为官方API地址
170
+ OPENAI_MODEL_NAME=gpt-4o # 可选,覆盖JARVIS_MODEL设置
171
+ ```
187
172
 
188
- # 使用工具的功能
189
- jarvis-tool --help
173
+ 配置说明:
174
+ 1. `OPENAI_API_KEY`: 必填。
175
+ 2. `OPENAI_API_BASE`: 可选,用于自定义API端点
190
176
 
191
- # 使用代码库查询功能
192
- jarvis-ask-codebase --help
177
+ 以上配置编写到`~/.jarvis/env`文件中。
193
178
 
194
- # 使用git details的功能
195
- jarvis-git-details --help
179
+ 支持的模型可通过`jarvis-platform-manager --list-models`查看完整列表。
196
180
 
197
- # 使用方法论的功能
198
- jarvis-methodology --help
199
- ```
181
+ ### 基本使用
182
+ | 命令 | 快捷方式 | 功能描述 |
183
+ |------|----------|----------|
184
+ | `jarvis` | - | 使用通用代理 |
185
+ | `jarvis-code-agent` | `jca` | 使用代码代理 |
186
+ | `jarvis-smart-shell` | `jss` | 使用智能shell功能 |
187
+ | `jarvis-platform-manager` | - | 使用平台管理功能 |
188
+ | `jarvis-code-review` | - | 使用代码审查功能 |
189
+ | `jarvis-git-commit` | `jgc` | 使用自动化git commit功能 |
190
+ | `jarvis-dev` | - | 使用dev功能(开发中) |
191
+ | `jarvis-git-squash` | - | 使用git squash功能 |
192
+ | `jarvis-multi-agent` | - | 使用多代理功能 |
193
+ | `jarvis-agent` | - | 使用agent功能 |
194
+ | `jarvis-tool` | - | 使用工具功能 |
195
+ | `jarvis-ask-codebase` | `jac` | 使用代码库查询功能 |
196
+ | `jarvis-git-details` | - | 使用git details功能 |
197
+ | `jarvis-methodology` | - | 使用方法论功能 |
200
198
 
201
199
  ---
202
200