jarvis-ai-assistant 0.1.92__py3-none-any.whl → 0.1.93__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.
- jarvis/__init__.py +1 -1
- jarvis/agent.py +4 -4
- jarvis/jarvis_codebase/main.py +7 -13
- jarvis/jarvis_coder/__init__.py +0 -0
- jarvis/jarvis_coder/git_utils.py +64 -0
- jarvis/jarvis_coder/main.py +630 -0
- jarvis/jarvis_coder/patch_handler.py +493 -0
- jarvis/jarvis_coder/plan_generator.py +75 -0
- jarvis/main.py +1 -1
- jarvis/models/ai8.py +4 -3
- jarvis/models/openai.py +2 -2
- jarvis/models/oyi.py +13 -13
- jarvis/tools/ask_user.py +1 -2
- jarvis/tools/coder.py +69 -0
- jarvis/utils.py +25 -1
- {jarvis_ai_assistant-0.1.92.dist-info → jarvis_ai_assistant-0.1.93.dist-info}/METADATA +1 -1
- {jarvis_ai_assistant-0.1.92.dist-info → jarvis_ai_assistant-0.1.93.dist-info}/RECORD +21 -15
- {jarvis_ai_assistant-0.1.92.dist-info → jarvis_ai_assistant-0.1.93.dist-info}/entry_points.txt +1 -0
- {jarvis_ai_assistant-0.1.92.dist-info → jarvis_ai_assistant-0.1.93.dist-info}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.92.dist-info → jarvis_ai_assistant-0.1.93.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.92.dist-info → jarvis_ai_assistant-0.1.93.dist-info}/top_level.txt +0 -0
jarvis/models/oyi.py
CHANGED
|
@@ -23,7 +23,7 @@ class OyiModel(BasePlatform):
|
|
|
23
23
|
self.messages = []
|
|
24
24
|
self.system_message = ""
|
|
25
25
|
self.conversation = None
|
|
26
|
-
self.
|
|
26
|
+
self.files = []
|
|
27
27
|
self.first_chat = True
|
|
28
28
|
|
|
29
29
|
self.token = os.getenv("OYI_API_KEY")
|
|
@@ -122,7 +122,7 @@ class OyiModel(BasePlatform):
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
payload = {
|
|
125
|
-
"topicId": self.conversation['result']['id'],
|
|
125
|
+
"topicId": self.conversation['result']['id'] if self.conversation else None,
|
|
126
126
|
"messages": self.messages,
|
|
127
127
|
"content": message,
|
|
128
128
|
"contentFiles": []
|
|
@@ -130,8 +130,8 @@ class OyiModel(BasePlatform):
|
|
|
130
130
|
|
|
131
131
|
# 如果有上传的文件,添加到请求中
|
|
132
132
|
if self.first_chat:
|
|
133
|
-
if self.
|
|
134
|
-
for file_data in self.
|
|
133
|
+
if self.files:
|
|
134
|
+
for file_data in self.files:
|
|
135
135
|
file_info = {
|
|
136
136
|
"contentType": 1, # 1 表示图片
|
|
137
137
|
"fileUrl": file_data['result']['url'],
|
|
@@ -140,7 +140,7 @@ class OyiModel(BasePlatform):
|
|
|
140
140
|
}
|
|
141
141
|
payload["contentFiles"].append(file_info)
|
|
142
142
|
# 清空已使用的文件列表
|
|
143
|
-
self.
|
|
143
|
+
self.files = []
|
|
144
144
|
message = self.system_message + "\n" + message
|
|
145
145
|
payload["content"] = message
|
|
146
146
|
self.first_chat = False
|
|
@@ -195,7 +195,7 @@ class OyiModel(BasePlatform):
|
|
|
195
195
|
"""Reset model state"""
|
|
196
196
|
self.messages = []
|
|
197
197
|
self.conversation = None
|
|
198
|
-
self.
|
|
198
|
+
self.files = []
|
|
199
199
|
self.first_chat = True
|
|
200
200
|
|
|
201
201
|
def delete_chat(self) -> bool:
|
|
@@ -251,7 +251,7 @@ class OyiModel(BasePlatform):
|
|
|
251
251
|
model_info = self.models.get(self.model_name)
|
|
252
252
|
if not model_info or not model_info.get('uploadFile', False):
|
|
253
253
|
PrettyOutput.print(f"当前模型 {self.model_name} 不支持文件上传", OutputType.WARNING)
|
|
254
|
-
return
|
|
254
|
+
return []
|
|
255
255
|
|
|
256
256
|
headers = {
|
|
257
257
|
'Authorization': f'Bearer {self.token}',
|
|
@@ -283,18 +283,18 @@ class OyiModel(BasePlatform):
|
|
|
283
283
|
if response.status_code == 200:
|
|
284
284
|
data = response.json()
|
|
285
285
|
if data.get('code') == 200:
|
|
286
|
-
self.
|
|
287
|
-
return data
|
|
286
|
+
self.files.append(data)
|
|
288
287
|
else:
|
|
289
288
|
PrettyOutput.print(f"文件上传失败: {data.get('message')}", OutputType.ERROR)
|
|
290
|
-
return
|
|
289
|
+
return []
|
|
291
290
|
else:
|
|
292
291
|
PrettyOutput.print(f"文件上传失败: {response.status_code}", OutputType.ERROR)
|
|
293
|
-
return
|
|
292
|
+
return []
|
|
294
293
|
|
|
294
|
+
return self.files
|
|
295
295
|
except Exception as e:
|
|
296
296
|
PrettyOutput.print(f"文件上传异常: {str(e)}", OutputType.ERROR)
|
|
297
|
-
return
|
|
297
|
+
return []
|
|
298
298
|
|
|
299
299
|
def get_available_models(self) -> List[str]:
|
|
300
300
|
"""获取可用的模型列表
|
|
@@ -364,5 +364,5 @@ class OyiModel(BasePlatform):
|
|
|
364
364
|
return sorted(models)
|
|
365
365
|
|
|
366
366
|
except Exception as e:
|
|
367
|
-
PrettyOutput.print(f"获取模型列表异常: {str(e)}", OutputType.
|
|
367
|
+
PrettyOutput.print(f"获取模型列表异常: {str(e)}", OutputType.WARNING)
|
|
368
368
|
return []
|
jarvis/tools/ask_user.py
CHANGED
|
@@ -34,8 +34,7 @@ class AskUserTool:
|
|
|
34
34
|
PrettyOutput.print(question, OutputType.SYSTEM)
|
|
35
35
|
|
|
36
36
|
# 获取用户输入
|
|
37
|
-
|
|
38
|
-
user_response = get_multiline_input()
|
|
37
|
+
user_response = get_multiline_input("请输入您的回答(输入空行结束)")
|
|
39
38
|
|
|
40
39
|
if user_response == "__interrupt__":
|
|
41
40
|
return {
|
jarvis/tools/coder.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Dict, Any, Optional
|
|
3
|
+
from jarvis.jarvis_coder.main import JarvisCoder
|
|
4
|
+
from jarvis.utils import PrettyOutput, OutputType
|
|
5
|
+
|
|
6
|
+
class CoderTool:
|
|
7
|
+
"""代码修改工具"""
|
|
8
|
+
|
|
9
|
+
name = "coder"
|
|
10
|
+
description = "分析并修改现有代码,用于实现新功能、修复bug、重构代码等。能理解代码上下文并进行精确的代码编辑。"
|
|
11
|
+
parameters = {
|
|
12
|
+
"feature": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "要实现的功能描述或需要修改的内容,例如:'添加日志功能'、'修复内存泄漏'、'优化性能'等",
|
|
15
|
+
"required": True
|
|
16
|
+
},
|
|
17
|
+
"dir": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"description": "项目根目录,默认为当前目录",
|
|
20
|
+
"required": False
|
|
21
|
+
},
|
|
22
|
+
"language": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"description": "项目的主要编程语言,默认为python",
|
|
25
|
+
"required": False
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
def __init__(self):
|
|
30
|
+
self._coder = None
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _init_coder(self, dir: Optional[str] = None, language: Optional[str] = "python") -> None:
|
|
34
|
+
"""初始化JarvisCoder实例"""
|
|
35
|
+
if not self._coder:
|
|
36
|
+
import os
|
|
37
|
+
work_dir = dir or os.getcwd()
|
|
38
|
+
self._coder = JarvisCoder(work_dir, language)
|
|
39
|
+
|
|
40
|
+
def execute(self, args: Dict) -> Dict[str, Any]:
|
|
41
|
+
"""执行代码修改
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
feature: 要实现的功能描述
|
|
45
|
+
dir: 可选,项目根目录
|
|
46
|
+
language: 可选,编程语言
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
Dict[str, Any]: 执行结果
|
|
50
|
+
"""
|
|
51
|
+
feature = args.get("feature")
|
|
52
|
+
dir = args.get("dir")
|
|
53
|
+
language = args.get("language", "python")
|
|
54
|
+
|
|
55
|
+
try:
|
|
56
|
+
self.current_dir = os.getcwd()
|
|
57
|
+
self._init_coder(dir, language)
|
|
58
|
+
result = self._coder.execute(str(feature)) # type: ignore
|
|
59
|
+
return result
|
|
60
|
+
except Exception as e:
|
|
61
|
+
PrettyOutput.print(f"代码修改失败: {str(e)}", OutputType.ERROR)
|
|
62
|
+
return {
|
|
63
|
+
"success": False,
|
|
64
|
+
"stdout": "",
|
|
65
|
+
"stderr": f"执行失败: {str(e)}",
|
|
66
|
+
"error": e
|
|
67
|
+
}
|
|
68
|
+
finally:
|
|
69
|
+
os.chdir(self.current_dir)
|
jarvis/utils.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from ast import List, Str
|
|
1
2
|
import hashlib
|
|
2
3
|
from pathlib import Path
|
|
3
4
|
import sys
|
|
@@ -17,6 +18,9 @@ import torch
|
|
|
17
18
|
# 初始化colorama
|
|
18
19
|
colorama.init()
|
|
19
20
|
|
|
21
|
+
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"
|
|
22
|
+
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
|
23
|
+
|
|
20
24
|
class OutputType(Enum):
|
|
21
25
|
SYSTEM = "system" # AI助手消息
|
|
22
26
|
CODE = "code" # 代码相关
|
|
@@ -213,7 +217,6 @@ def find_git_root(dir="."):
|
|
|
213
217
|
return ret
|
|
214
218
|
|
|
215
219
|
def load_embedding_model():
|
|
216
|
-
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
|
217
220
|
model_name = "BAAI/bge-large-zh-v1.5"
|
|
218
221
|
PrettyOutput.print(f"正在加载嵌入模型: {model_name}...", OutputType.INFO)
|
|
219
222
|
try:
|
|
@@ -276,6 +279,27 @@ def load_rerank_model():
|
|
|
276
279
|
def get_max_context_length():
|
|
277
280
|
return int(os.getenv('JARVIS_MAX_CONTEXT_LENGTH', '131072')) # 默认128k
|
|
278
281
|
|
|
282
|
+
def is_long_context(files: list) -> bool:
|
|
283
|
+
"""检测文件列表是否属于长上下文(总字符数超过最大上下文长度的80%)"""
|
|
284
|
+
max_length = get_max_context_length()
|
|
285
|
+
threshold = max_length * 0.8
|
|
286
|
+
total_chars = 0
|
|
287
|
+
|
|
288
|
+
for file_path in files:
|
|
289
|
+
try:
|
|
290
|
+
with open(file_path, 'r', encoding='utf-8') as f:
|
|
291
|
+
content = f.read()
|
|
292
|
+
total_chars += len(content)
|
|
293
|
+
|
|
294
|
+
# 提前终止检查如果已经超过阈值
|
|
295
|
+
if total_chars > threshold:
|
|
296
|
+
return True
|
|
297
|
+
except Exception as e:
|
|
298
|
+
PrettyOutput.print(f"无法读取文件 {file_path}: {e}", OutputType.WARNING)
|
|
299
|
+
continue
|
|
300
|
+
|
|
301
|
+
return total_chars > threshold
|
|
302
|
+
|
|
279
303
|
def get_thread_count():
|
|
280
304
|
return int(os.getenv('JARVIS_THREAD_COUNT', '1'))
|
|
281
305
|
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
jarvis/__init__.py,sha256=
|
|
2
|
-
jarvis/agent.py,sha256=
|
|
3
|
-
jarvis/main.py,sha256=
|
|
4
|
-
jarvis/utils.py,sha256=
|
|
1
|
+
jarvis/__init__.py,sha256=f8113pl4O0dw4MOgNk0fK63GV0FVrx2v-G0-w75BjWc,50
|
|
2
|
+
jarvis/agent.py,sha256=vjWR-bIyac7nL3qMUOhastXMdT9PqufwRjT-h_hAnk0,19403
|
|
3
|
+
jarvis/main.py,sha256=kHvlVDmjznWvXugl56M4HRb1Uedkn8lKsMEKr8tNy1Q,5824
|
|
4
|
+
jarvis/utils.py,sha256=gIpS62j9cbKndvXQ7E36RQCaNOgl5bl2PRPcpiZZvew,11292
|
|
5
5
|
jarvis/jarvis_codebase/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
jarvis/jarvis_codebase/main.py,sha256=
|
|
6
|
+
jarvis/jarvis_codebase/main.py,sha256=li3ccKSs4RwQw8EK35RssC3IHDg1PjEji0pNCC-HMtE,29885
|
|
7
|
+
jarvis/jarvis_coder/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
jarvis/jarvis_coder/git_utils.py,sha256=u5mUe_R3JDJthDoamlNOkrN3bJKf-47pf8YqCvtmYK4,2284
|
|
9
|
+
jarvis/jarvis_coder/main.py,sha256=ZgmASwDsRLUx8_E_9Cnr2n_pXnyp-lHWAA1IGHwsfb8,25294
|
|
10
|
+
jarvis/jarvis_coder/patch_handler.py,sha256=OsAt-hCz49eoRgUW0c2hGf9Bcq_i5JrkCWaUtg4WWiw,21500
|
|
11
|
+
jarvis/jarvis_coder/plan_generator.py,sha256=xtiYEE-RhexBWamBnsat_pUyzzc4IdP5PCI6p8wyqLE,2845
|
|
7
12
|
jarvis/jarvis_platform/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
13
|
jarvis/jarvis_platform/main.py,sha256=uOv5TlxKVWO_lD2mnB7KAILkqCbezhOwiJ6g_CRQBlU,4868
|
|
9
14
|
jarvis/jarvis_rag/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -11,18 +16,19 @@ jarvis/jarvis_rag/main.py,sha256=Gu8llgtBaRTg7sKMB-3pRLb0Tjs1ee_mbZLOku0kDPk,327
|
|
|
11
16
|
jarvis/jarvis_smart_shell/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
17
|
jarvis/jarvis_smart_shell/main.py,sha256=wqTbbXMaM3X6YIdOtNVF6B3Ua7fxu0XTeXBR7lfdWg0,3812
|
|
13
18
|
jarvis/models/__init__.py,sha256=mrOt67nselz_H1gX9wdAO4y2DY5WPXzABqJbr5Des8k,63
|
|
14
|
-
jarvis/models/ai8.py,sha256=
|
|
19
|
+
jarvis/models/ai8.py,sha256=ARzNIg7v7-Vy5TtHHmTGV3Fn8rXbNxKw2pe_BylyADE,11887
|
|
15
20
|
jarvis/models/base.py,sha256=qIpO32lejPhaZk5T3VIua3td4gEguXMaeFER5kXYwLY,1782
|
|
16
21
|
jarvis/models/kimi.py,sha256=cB1tC_ifdTAZUEqndzNTIcgHWi4w4tM8zdzSOcDhOrQ,16348
|
|
17
22
|
jarvis/models/ollama.py,sha256=fLVGGBfE5S_sFDiQ1ZC6-Oz9AY6EMnRqvILLi7lP-gw,5603
|
|
18
|
-
jarvis/models/openai.py,sha256=
|
|
19
|
-
jarvis/models/oyi.py,sha256=
|
|
23
|
+
jarvis/models/openai.py,sha256=XdBsWRwlJgUwsqasux0IhUHhjo4UGZt0eg7xFQVNZhY,4400
|
|
24
|
+
jarvis/models/oyi.py,sha256=ZMyX2WMHC_HG0mGCtTyJwfiARQmlLKtgOfpNP5YX0DI,14463
|
|
20
25
|
jarvis/models/registry.py,sha256=SDnrNzf0wQi8mb7qbu4ZNfYIy5vhz1CxmVL3Ru-VATk,8797
|
|
21
26
|
jarvis/tools/__init__.py,sha256=7Rqyj5hBAv5cWDVr5T9ZTZASO7ssBHeQNm2_4ZARdkA,72
|
|
22
|
-
jarvis/tools/ask_user.py,sha256=
|
|
27
|
+
jarvis/tools/ask_user.py,sha256=naLLVYKKMSVkQSExvnyZbL9FHwFrpTqEQjlBFcJadp8,1865
|
|
23
28
|
jarvis/tools/base.py,sha256=EGRGbdfbLXDLwtyoWdvp9rlxNX7bzc20t0Vc2VkwIEY,652
|
|
24
29
|
jarvis/tools/chdir.py,sha256=TjfPbX8yvNKgUNJEMXh3ZlVDEIse_Fo8xMoVsiK7_dA,2688
|
|
25
30
|
jarvis/tools/codebase_qa.py,sha256=Lk8EXkin45RKUsp5C_UHm6jADBhyCT-xsYubwJ1hSiE,2403
|
|
31
|
+
jarvis/tools/coder.py,sha256=ws25Vni7Q_fKxSNyQLapqlcjlpP9jkavgJRIv78ATww,2315
|
|
26
32
|
jarvis/tools/file_ops.py,sha256=h8g0eT9UvlJf4kt0DLXvdSsjcPj7x19lxWdDApeDfpg,3842
|
|
27
33
|
jarvis/tools/generator.py,sha256=TB1zcw_JmRL2W9w6L4IxtrLF3gjnNw5Jj2Zrowj0eSg,5763
|
|
28
34
|
jarvis/tools/methodology.py,sha256=UG6s5VYRcd9wrKX4cg6f7zJhet5AIcthFGMOAdevBiw,5175
|
|
@@ -33,9 +39,9 @@ jarvis/tools/shell.py,sha256=UPKshPyOaUwTngresUw-ot1jHjQIb4wCY5nkJqa38lU,2520
|
|
|
33
39
|
jarvis/tools/sub_agent.py,sha256=rEtAmSVY2ZjFOZEKr5m5wpACOQIiM9Zr_3dT92FhXYU,2621
|
|
34
40
|
jarvis/tools/thinker.py,sha256=yjY-JMf-Vp_UZdBNa7auvFZl8Wohcu1AqqNO2GSel-w,4598
|
|
35
41
|
jarvis/tools/webpage.py,sha256=d3w3Jcjcu1ESciezTkz3n3Zf-rp_l91PrVoDEZnckOo,2391
|
|
36
|
-
jarvis_ai_assistant-0.1.
|
|
37
|
-
jarvis_ai_assistant-0.1.
|
|
38
|
-
jarvis_ai_assistant-0.1.
|
|
39
|
-
jarvis_ai_assistant-0.1.
|
|
40
|
-
jarvis_ai_assistant-0.1.
|
|
41
|
-
jarvis_ai_assistant-0.1.
|
|
42
|
+
jarvis_ai_assistant-0.1.93.dist-info/LICENSE,sha256=AGgVgQmTqFvaztRtCAXsAMryUymB18gZif7_l2e1XOg,1063
|
|
43
|
+
jarvis_ai_assistant-0.1.93.dist-info/METADATA,sha256=9Xodq2q2pIZAi9fGA48lhjOgttGzDQafYVtK7OURt9c,12766
|
|
44
|
+
jarvis_ai_assistant-0.1.93.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
45
|
+
jarvis_ai_assistant-0.1.93.dist-info/entry_points.txt,sha256=1D14s9v6rwpNzVD0muwe0tCKffJDEvLRBlEShbSFSbQ,331
|
|
46
|
+
jarvis_ai_assistant-0.1.93.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
|
|
47
|
+
jarvis_ai_assistant-0.1.93.dist-info/RECORD,,
|
{jarvis_ai_assistant-0.1.92.dist-info → jarvis_ai_assistant-0.1.93.dist-info}/entry_points.txt
RENAMED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
[console_scripts]
|
|
2
2
|
jarvis = jarvis.main:main
|
|
3
3
|
jarvis-codebase = jarvis.jarvis_codebase.main:main
|
|
4
|
+
jarvis-coder = jarvis.jarvis_coder.main:main
|
|
4
5
|
jarvis-platform = jarvis.jarvis_platform.main:main
|
|
5
6
|
jarvis-rag = jarvis.jarvis_rag.main:main
|
|
6
7
|
jarvis-smart-shell = jarvis.jarvis_smart_shell.main:main
|
|
File without changes
|
|
File without changes
|
|
File without changes
|