jarvis-ai-assistant 0.1.163__py3-none-any.whl → 0.1.165__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 (95) hide show
  1. jarvis/__init__.py +2 -1
  2. jarvis/jarvis_agent/__init__.py +1 -0
  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 +28 -3
  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 +2 -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 +204 -132
  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 +1 -0
  69. jarvis/jarvis_tools/lsp_get_diagnostics.py +1 -0
  70. jarvis/jarvis_tools/methodology.py +1 -0
  71. jarvis/jarvis_tools/read_code.py +1 -0
  72. jarvis/jarvis_tools/read_webpage.py +1 -0
  73. jarvis/jarvis_tools/registry.py +1 -0
  74. jarvis/jarvis_tools/rewrite_file.py +4 -3
  75. jarvis/jarvis_tools/search_web.py +1 -0
  76. jarvis/jarvis_tools/virtual_tty.py +1 -0
  77. jarvis/jarvis_utils/__init__.py +1 -0
  78. jarvis/jarvis_utils/builtin_replace_map.py +1 -0
  79. jarvis/jarvis_utils/config.py +1 -0
  80. jarvis/jarvis_utils/embedding.py +1 -0
  81. jarvis/jarvis_utils/file_processors.py +1 -0
  82. jarvis/jarvis_utils/git_utils.py +1 -0
  83. jarvis/jarvis_utils/globals.py +1 -0
  84. jarvis/jarvis_utils/input.py +1 -0
  85. jarvis/jarvis_utils/methodology.py +1 -0
  86. jarvis/jarvis_utils/output.py +1 -0
  87. jarvis/jarvis_utils/tag.py +1 -0
  88. jarvis/jarvis_utils/utils.py +18 -0
  89. {jarvis_ai_assistant-0.1.163.dist-info → jarvis_ai_assistant-0.1.165.dist-info}/METADATA +12 -2
  90. jarvis_ai_assistant-0.1.165.dist-info/RECORD +100 -0
  91. jarvis_ai_assistant-0.1.163.dist-info/RECORD +0 -98
  92. {jarvis_ai_assistant-0.1.163.dist-info → jarvis_ai_assistant-0.1.165.dist-info}/WHEEL +0 -0
  93. {jarvis_ai_assistant-0.1.163.dist-info → jarvis_ai_assistant-0.1.165.dist-info}/entry_points.txt +0 -0
  94. {jarvis_ai_assistant-0.1.163.dist-info → jarvis_ai_assistant-0.1.165.dist-info}/licenses/LICENSE +0 -0
  95. {jarvis_ai_assistant-0.1.163.dist-info → jarvis_ai_assistant-0.1.165.dist-info}/top_level.txt +0 -0
jarvis/__init__.py CHANGED
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """Jarvis AI Assistant"""
2
3
 
3
- __version__ = "0.1.163"
4
+ __version__ = "0.1.165"
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import datetime
2
3
  import platform
3
4
  from typing import Any, Callable, List, Optional, Tuple, Union
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import re
2
3
  from typing import Any, Tuple
3
4
  from jarvis.jarvis_utils.config import get_replace_map
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
 
2
3
 
3
4
  import os
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import argparse
2
3
  import os
3
4
  import sys
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import argparse
2
3
  import yaml
3
4
  import os
@@ -1,23 +1,48 @@
1
-
2
-
1
+ # -*- coding: utf-8 -*-
3
2
  from abc import ABC, abstractmethod
4
3
  from typing import Any, Tuple
5
4
 
6
5
 
7
-
8
6
  class OutputHandler(ABC):
9
7
  @abstractmethod
10
8
  def handle(self, response: str, agent: Any) -> Tuple[bool, Any]:
9
+ """处理响应数据
10
+
11
+ Args:
12
+ response: 需要处理的响应字符串
13
+ agent: 执行处理的agent实例
14
+
15
+ Returns:
16
+ Tuple[bool, Any]: 返回处理结果元组,第一个元素表示是否处理成功,第二个元素为处理后的数据
17
+ """
11
18
  pass
12
19
 
13
20
  @abstractmethod
14
21
  def can_handle(self, response: str) -> bool:
22
+ """判断是否能处理给定的响应
23
+
24
+ Args:
25
+ response: 需要判断的响应字符串
26
+
27
+ Returns:
28
+ bool: 返回是否能处理该响应
29
+ """
15
30
  pass
16
31
 
17
32
  @abstractmethod
18
33
  def prompt(self) -> str:
34
+ """获取处理器的提示信息
35
+
36
+ Returns:
37
+ str: 返回处理器的提示字符串
38
+ """
19
39
  pass
20
40
 
21
41
  @abstractmethod
22
42
  def name(self) -> str:
43
+ """获取处理器的名称
44
+
45
+ Returns:
46
+ str: 返回处理器的名称字符串
47
+ """
23
48
  pass
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from typing import Any, Tuple
2
3
 
3
4
  from jarvis.jarvis_utils.output import OutputType, PrettyOutput
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """Jarvis代码代理模块。
2
3
 
3
4
  该模块提供CodeAgent类,用于处理代码修改任务。
@@ -86,32 +87,10 @@ class CodeAgent:
86
87
  - 代码阅读:优先使用read_code工具
87
88
  - 仅在命令行工具不足时使用专用工具
88
89
 
89
- ## 代码编辑规范
90
- ### 代码修改工具选择
91
- - 对于所有代码修改任务,优先使用edit_file工具,对于特别简单的修改,可以通过execute_script工具使用shell命令修改
92
- - edit_file通过搜索和替换实现精确的代码编辑,是首选的代码修改方式
93
- - 每个搜索文本在文件中必须唯一匹配,确保修改的准确性
94
- - 为新文件创建时,使用空字符串作为搜索文本,替换文本作为完整内容
95
- - 保持与原代码完全一致的格式和缩进风格
96
-
97
- ### 文件重写工具使用
98
- - rewrite_file工具用于完全重写文件内容或创建新文件
99
- - 当需要替换整个文件内容时,优先使用rewrite_file工具
100
- - 创建新文件时,使用rewrite_file工具提供完整的文件内容
101
- - 保持与原代码相同的格式、缩进和编码风格
102
- - 确保提供格式良好的完整文件内容
103
-
104
- ### 最小补丁原则
105
- - 对于任何代码修改,只提供需要修改的代码部分,不提供完整文件内容
106
- - 严格保持原始代码的缩进、空行和格式风格
107
- - 提供最小必要的上下文,确保修改位置精确
108
- - 每个修改必须包含清晰的修改理由
109
-
110
- ### 格式兼容要求
111
- - 保持与原代码相同的缩进方式(空格或制表符)
112
- - 保持原代码的空行数量和位置
113
- - 不改变原代码的换行风格
114
- - 对新文件可提供完整内容,对现有文件只提供差异部分
90
+ ## 文件编辑工具使用规范
91
+ - 对于部分文件内容修改,使用edit_file工具
92
+ - 对于需要重写整个文件内容,使用rewrite_file工具
93
+ - 对于简单的修改,可以使用execute_script工具执行shell命令完成
115
94
  </code_engineer_guide>
116
95
  """
117
96
  # Dynamically add ask_codebase based on task complexity if really needed
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  Language-specific checklists for code review.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  C/C++ language-specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  C# language-specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  Data format (XML, JSON, YAML) specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  DevOps (Makefile, CI/CD) specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  Documentation (Markdown, reStructuredText) specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  Go language-specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  Infrastructure as Code (Docker, Terraform) specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  Java language-specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  JavaScript/TypeScript language-specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  Kotlin-specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  Utility module for loading language-specific code review checklists.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  PHP language-specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  Python language-specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  Ruby-specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  Rust language-specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  Shell/Bash language-specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  SQL language-specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  Swift language-specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """
2
3
  HTML/CSS specific code review checklist.
3
4
  """
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from typing import Dict, Any, List
2
3
  import subprocess
3
4
  import os
Binary file
jarvis/jarvis_dev/main.py CHANGED
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from jarvis.jarvis_platform.registry import PlatformRegistry
2
3
  from jarvis.jarvis_multi_agent import MultiAgent
3
4
  from jarvis.jarvis_tools.registry import ToolRegistry
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  """Git Commit分析工具模块
2
3
 
3
4
  该模块提供了一个GitCommitAnalyzer类,用于获取和分析指定Git commit的详细信息,
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import sys
2
3
  import argparse
3
4
  from typing import Dict
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import re
2
3
  import shlex
3
4
  import subprocess
@@ -32,6 +33,16 @@ class GitCommitTool:
32
33
  "type": "string",
33
34
  "description": "Git仓库的根目录路径(可选)",
34
35
  "default": "."
36
+ },
37
+ "prefix": {
38
+ "type": "string",
39
+ "description": "提交信息前缀(可选)",
40
+ "default": ""
41
+ },
42
+ "suffix": {
43
+ "type": "string",
44
+ "description": "提交信息后缀(可选)",
45
+ "default": ""
35
46
  }
36
47
  },
37
48
  "required": []
@@ -60,6 +71,8 @@ class GitCommitTool:
60
71
  """Execute automatic commit process with support for multi-line messages and special characters"""
61
72
  try:
62
73
  root_dir = args.get("root_dir", ".")
74
+ prefix = args.get("prefix", "")
75
+ suffix = args.get("suffix", "")
63
76
 
64
77
  # Store current directory
65
78
  original_dir = os.getcwd()
@@ -112,21 +125,21 @@ class GitCommitTool:
112
125
  # 准备提示信息
113
126
  base_prompt = f'''根据代码差异生成提交信息:
114
127
  提交信息应使用{args.get('lang', '中文')}书写
115
- # 必需结构
116
- 必须使用以下格式:
117
- {ot("COMMIT_MESSAGE")}
118
- <类型>(<范围>): <主题>
119
-
120
- [可选] 详细描述变更内容和原因
121
- {ct("COMMIT_MESSAGE")}
122
- # 格式规则
123
- 1. 类型: fix(修复bug), feat(新功能), docs(文档), style(格式), refactor(重构), test(测试), chore(其他)
124
- 2. 范围表示变更的模块或组件 (例如: auth, database, ui)
125
- 3. 主题行不超过72个字符,不以句号结尾,使用祈使语气
126
- 4. 如有详细描述,使用空行分隔主题和详细描述
127
- 5. 详细描述部分应解释"是什么"和"为什么",而非"如何"
128
- 6. 仅输出提交信息,不要输出其他内容
129
- '''
128
+ # 必需结构
129
+ 必须使用以下格式:
130
+ {ot("COMMIT_MESSAGE")}
131
+ <类型>(<范围>): <主题>
132
+
133
+ [可选] 详细描述变更内容和原因
134
+ {ct("COMMIT_MESSAGE")}
135
+ # 格式规则
136
+ 1. 类型: fix(修复bug), feat(新功能), docs(文档), style(格式), refactor(重构), test(测试), chore(其他)
137
+ 2. 范围表示变更的模块或组件 (例如: auth, database, ui)
138
+ 3. 主题行不超过72个字符,不以句号结尾,使用祈使语气
139
+ 4. 如有详细描述,使用空行分隔主题和详细描述
140
+ 5. 详细描述部分应解释"是什么"和"为什么",而非"如何"
141
+ 6. 仅输出提交信息,不要输出其他内容
142
+ '''
130
143
 
131
144
  # 获取模型并尝试上传文件
132
145
  platform = PlatformRegistry().get_normal_platform()
@@ -159,12 +172,12 @@ class GitCommitTool:
159
172
  spinner.text = "正在生成提交消息..."
160
173
  # 使用上传的文件
161
174
  prompt = base_prompt + f'''
162
- # 变更概述
163
- - 变更文件数量: {file_count} 个文件
164
- - 已上传包含完整代码差异的文件
165
-
166
- 请详细分析已上传的代码差异文件,生成符合上述格式的提交信息。
167
- '''
175
+ # 变更概述
176
+ - 变更文件数量: {file_count} 个文件
177
+ - 已上传包含完整代码差异的文件
178
+
179
+ 请详细分析已上传的代码差异文件,生成符合上述格式的提交信息。
180
+ '''
168
181
  commit_message = platform.chat_until_success(prompt)
169
182
  else:
170
183
  # 如果上传失败但内容较大,使用chat_big_content
@@ -174,9 +187,9 @@ class GitCommitTool:
174
187
  else:
175
188
  # 直接在提示中包含差异内容
176
189
  prompt = base_prompt + f'''
177
- # 分析材料
178
- {diff}
179
- '''
190
+ # 分析材料
191
+ {diff}
192
+ '''
180
193
  commit_message = platform.chat_until_success(prompt)
181
194
 
182
195
  while True:
@@ -187,13 +200,18 @@ class GitCommitTool:
187
200
  # 如果成功提取,就跳出循环
188
201
  if extracted_message:
189
202
  commit_message = extracted_message
203
+ # 应用prefix和suffix
204
+ if prefix:
205
+ commit_message = f"{prefix} {commit_message}"
206
+ if suffix:
207
+ commit_message = f"{commit_message}\n{suffix}"
190
208
  break
191
209
  prompt = f"""格式错误,请按照以下格式重新生成提交信息:
192
210
  {ot("COMMIT_MESSAGE")}
193
- <类型>(<范围>): <主题>
194
-
195
- [可选] 详细描述变更内容和原因
196
- {ct("COMMIT_MESSAGE")}
211
+ <类型>(<范围>): <主题>
212
+
213
+ [可选] 详细描述变更内容和原因
214
+ {ct("COMMIT_MESSAGE")}
197
215
  """
198
216
  commit_message = platform.chat_until_success(prompt)
199
217
  spinner.write("✅ 生成提交消息")
@@ -250,9 +268,16 @@ def main():
250
268
  parser = argparse.ArgumentParser(description='Git commit tool')
251
269
  parser.add_argument('--lang', type=str, default='Chinese', help='Language for commit messages')
252
270
  parser.add_argument('--root-dir', type=str, default='.', help='Root directory of the Git repository')
271
+ parser.add_argument('--prefix', type=str, default='', help='Prefix to prepend to commit message (separated by space)')
272
+ parser.add_argument('--suffix', type=str, default='', help='Suffix to append to commit message (separated by newline)')
253
273
  args = parser.parse_args()
254
274
  tool = GitCommitTool()
255
- tool.execute({"lang": args.lang if hasattr(args, 'lang') else 'Chinese', "root_dir": args.root_dir})
275
+ tool.execute({
276
+ "lang": args.lang if hasattr(args, 'lang') else 'Chinese',
277
+ "root_dir": args.root_dir,
278
+ "prefix": args.prefix if hasattr(args, 'prefix') else '',
279
+ "suffix": args.suffix if hasattr(args, 'suffix') else ''
280
+ })
256
281
 
257
282
  if __name__ == "__main__":
258
- sys.exit(main())
283
+ sys.exit(main())
jarvis/jarvis_lsp/base.py CHANGED
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from abc import ABC, abstractmethod
2
3
  from typing import List, Dict, Any, Union
3
4
 
jarvis/jarvis_lsp/cpp.py CHANGED
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import os
2
3
  import shutil
3
4
  import subprocess
jarvis/jarvis_lsp/go.py CHANGED
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import os
2
3
  import shutil
3
4
  import subprocess
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from typing import List, Dict, Any
2
3
  import jedi
3
4
  from jarvis.jarvis_lsp.base import BaseLSP
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import importlib
2
3
  import inspect
3
4
  import os
jarvis/jarvis_lsp/rust.py CHANGED
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import os
2
3
  import shutil
3
4
  import subprocess
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from abc import ABC, abstractmethod
2
3
  from typing import Any, Dict, List
3
4
 
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from typing import Any, Dict, List, Callable
2
3
  import requests
3
4
  import json
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from typing import Any, Dict, List
2
3
  import subprocess
3
4
  import os
@@ -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 re
2
3
  from typing import Any, Dict, List, Tuple
3
4
 
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import yaml
2
3
  from jarvis.jarvis_multi_agent import MultiAgent
3
4
  from jarvis.jarvis_utils.utils import init_env
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from jarvis.jarvis_platform.base import BasePlatform
2
3
 
3
4
  __all__ = ['BasePlatform']
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from abc import ABC, abstractmethod
2
3
  import re
3
4
  from typing import List, Tuple
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from typing import Dict, List, Tuple
2
3
  import random
3
4
  import string
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from typing import Dict, List, Tuple
2
3
  import requests # type: ignore
3
4
  import json
@@ -0,0 +1,117 @@
1
+ # -*- coding: utf-8 -*-
2
+ from typing import Dict, List, Tuple
3
+ import os
4
+ from openai import OpenAI
5
+ from jarvis.jarvis_platform.base import BasePlatform
6
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
7
+
8
+ class OpenAIModel(BasePlatform):
9
+ platform_name = "openai"
10
+
11
+ def __init__(self):
12
+ """
13
+ Initialize OpenAI model
14
+ """
15
+ super().__init__()
16
+ self.system_message = ""
17
+ self.api_key = os.getenv("OPENAI_API_KEY")
18
+ if not self.api_key:
19
+ message = (
20
+ "需要设置以下环境变量才能使用 OpenAI 模型:\n"
21
+ " • OPENAI_API_KEY: API 密钥\n"
22
+ " • OPENAI_API_BASE: (可选) API 基础地址, 默认使用 https://api.openai.com/v1\n"
23
+ "您可以通过以下方式设置它们:\n"
24
+ "1. 创建或编辑 ~/.jarvis/env 文件:\n"
25
+ " OPENAI_API_KEY=your_api_key\n"
26
+ " OPENAI_API_BASE=your_api_base\n"
27
+ " OPENAI_MODEL_NAME=your_model_name\n"
28
+ "2. 直接设置环境变量:\n"
29
+ " export OPENAI_API_KEY=your_api_key\n"
30
+ " export OPENAI_API_BASE=your_api_base\n"
31
+ " export OPENAI_MODEL_NAME=your_model_name"
32
+ )
33
+ PrettyOutput.print(message, OutputType.INFO)
34
+ PrettyOutput.print("OPENAI_API_KEY 未设置", OutputType.WARNING)
35
+
36
+ self.base_url = os.getenv("OPENAI_API_BASE", "https://api.openai.com/v1")
37
+ self.model_name = os.getenv("JARVIS_MODEL") or "gpt-4o"
38
+
39
+
40
+ self.client = OpenAI(
41
+ api_key=self.api_key,
42
+ base_url=self.base_url
43
+ )
44
+ self.messages: List[Dict[str, str]] = []
45
+ self.system_message = ""
46
+
47
+ def upload_files(self, file_list: List[str]) -> bool:
48
+ return False
49
+
50
+ def get_model_list(self) -> List[Tuple[str, str]]:
51
+ """Get model list"""
52
+ try:
53
+ models = self.client.models.list()
54
+ model_list = []
55
+ for model in models:
56
+ model_list.append((model.id, model.id))
57
+ return model_list
58
+ except Exception as e:
59
+ PrettyOutput.print(f"获取模型列表失败:{str(e)}", OutputType.ERROR)
60
+ return []
61
+
62
+ def set_model_name(self, model_name: str):
63
+ """Set model name"""
64
+
65
+ self.model_name = model_name
66
+
67
+ def set_system_message(self, message: str):
68
+ """Set system message"""
69
+ self.system_message = message
70
+ self.messages.append({"role": "system", "content": self.system_message})
71
+
72
+ def chat(self, message: str) -> str:
73
+ """Execute conversation"""
74
+ try:
75
+
76
+ # Add user message to history
77
+ self.messages.append({"role": "user", "content": message})
78
+
79
+ response = self.client.chat.completions.create(
80
+ model=self.model_name, # Use the configured model name
81
+ messages=self.messages, # type: ignore
82
+ stream=True
83
+ ) # type: ignore
84
+
85
+ full_response = ""
86
+
87
+ for chunk in response:
88
+ if chunk.choices and chunk.choices[0].delta.content:
89
+ text = chunk.choices[0].delta.content
90
+ if not self.suppress_output:
91
+ PrettyOutput.print_stream(text)
92
+ full_response += text
93
+
94
+ if not self.suppress_output:
95
+ PrettyOutput.print_stream_end()
96
+
97
+ # Add assistant reply to history
98
+ self.messages.append({"role": "assistant", "content": full_response})
99
+
100
+ return full_response
101
+
102
+ except Exception as e:
103
+ PrettyOutput.print(f"对话失败:{str(e)}", OutputType.ERROR)
104
+ raise Exception(f"Chat failed: {str(e)}")
105
+
106
+ def name(self) -> str:
107
+ """Return model name"""
108
+ return self.model_name
109
+
110
+
111
+ def delete_chat(self)->bool:
112
+ """Delete conversation"""
113
+ if self.system_message:
114
+ self.messages = [{"role": "system", "content": self.system_message}]
115
+ else:
116
+ self.messages = []
117
+ return True
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import importlib
2
3
  import inspect
3
4
  import os