jarvis-ai-assistant 0.1.218__py3-none-any.whl → 0.1.220__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 +37 -92
- jarvis/jarvis_agent/shell_input_handler.py +1 -1
- jarvis/jarvis_code_agent/code_agent.py +5 -3
- jarvis/jarvis_data/config_schema.json +30 -0
- jarvis/jarvis_git_squash/main.py +2 -1
- jarvis/jarvis_platform/human.py +2 -7
- jarvis/jarvis_platform/yuanbao.py +3 -1
- jarvis/jarvis_rag/__init__.py +11 -0
- jarvis/jarvis_rag/cache.py +87 -0
- jarvis/jarvis_rag/cli.py +297 -0
- jarvis/jarvis_rag/embedding_manager.py +109 -0
- jarvis/jarvis_rag/llm_interface.py +130 -0
- jarvis/jarvis_rag/query_rewriter.py +63 -0
- jarvis/jarvis_rag/rag_pipeline.py +177 -0
- jarvis/jarvis_rag/reranker.py +56 -0
- jarvis/jarvis_rag/retriever.py +201 -0
- jarvis/jarvis_tools/search_web.py +127 -11
- jarvis/jarvis_utils/config.py +71 -0
- jarvis/jarvis_utils/git_utils.py +27 -18
- jarvis/jarvis_utils/input.py +21 -10
- jarvis/jarvis_utils/utils.py +43 -20
- {jarvis_ai_assistant-0.1.218.dist-info → jarvis_ai_assistant-0.1.220.dist-info}/METADATA +87 -5
- {jarvis_ai_assistant-0.1.218.dist-info → jarvis_ai_assistant-0.1.220.dist-info}/RECORD +28 -19
- {jarvis_ai_assistant-0.1.218.dist-info → jarvis_ai_assistant-0.1.220.dist-info}/entry_points.txt +1 -0
- {jarvis_ai_assistant-0.1.218.dist-info → jarvis_ai_assistant-0.1.220.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.218.dist-info → jarvis_ai_assistant-0.1.220.dist-info}/licenses/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.218.dist-info → jarvis_ai_assistant-0.1.220.dist-info}/top_level.txt +0 -0
jarvis/__init__.py
CHANGED
jarvis/jarvis_agent/__init__.py
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
# 标准库导入
|
3
3
|
import datetime
|
4
4
|
import os
|
5
|
-
from pathlib import Path
|
6
5
|
import platform
|
7
6
|
from typing import Any, Callable, Dict, List, Optional, Protocol, Tuple, Union
|
8
7
|
|
@@ -29,103 +28,57 @@ from jarvis.jarvis_utils.globals import (
|
|
29
28
|
set_agent,
|
30
29
|
set_interrupt,
|
31
30
|
)
|
32
|
-
from jarvis.jarvis_utils.input import get_multiline_input
|
31
|
+
from jarvis.jarvis_utils.input import get_multiline_input, user_confirm
|
33
32
|
from jarvis.jarvis_utils.methodology import load_methodology, upload_methodology
|
34
33
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
35
34
|
from jarvis.jarvis_utils.tag import ct, ot
|
36
|
-
from jarvis.jarvis_utils.utils import user_confirm
|
37
35
|
|
38
36
|
origin_agent_system_prompt = f"""
|
39
37
|
<role>
|
40
38
|
# 🤖 角色
|
41
|
-
|
39
|
+
你是一个专业的任务执行助手,根据用户需求制定并执行详细的计划。
|
42
40
|
</role>
|
43
41
|
|
44
|
-
<
|
45
|
-
#
|
46
|
-
1.
|
47
|
-
2.
|
48
|
-
3.
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
- 请求用户确认 → 永久挂起
|
56
|
-
</violations>
|
42
|
+
<rules>
|
43
|
+
# ❗ 核心规则
|
44
|
+
1. **单步操作**: 每个响应必须包含且仅包含一个工具调用。
|
45
|
+
2. **任务终结**: 当任务完成时,明确指出任务已完成。这是唯一可以不调用工具的例外。
|
46
|
+
3. **无响应错误**: 空响应或仅有分析无工具调用的响应是致命错误,会导致系统挂起。
|
47
|
+
4. **决策即工具**: 所有的决策和分析都必须通过工具调用来体现。
|
48
|
+
5. **等待结果**: 在继续下一步之前,必须等待当前工具的执行结果。
|
49
|
+
6. **持续推进**: 除非任务完成,否则必须生成可操作的下一步。
|
50
|
+
7. **记录沉淀**: 如果解决方案有普适价值,应记录为方法论。
|
51
|
+
8. **用户语言**: 始终使用用户的语言进行交流。
|
52
|
+
</rules>
|
57
53
|
|
58
54
|
<workflow>
|
59
|
-
# 🔄
|
60
|
-
1.
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
→ 必须调用分析工具
|
65
|
-
|
66
|
-
2. 解决方案设计
|
67
|
-
- 生成多个可执行的解决方案
|
68
|
-
- 评估并选择最优方案
|
69
|
-
- 使用PlantUML创建详细行动计划
|
70
|
-
→ 必须调用设计工具
|
71
|
-
|
72
|
-
3. 执行
|
73
|
-
- 一次执行一个步骤
|
74
|
-
- 每个步骤只使用一个工具
|
75
|
-
- 等待工具结果后再继续
|
76
|
-
- 监控结果并根据需要调整
|
77
|
-
→ 必须调用执行工具
|
78
|
-
|
79
|
-
4. 任务完成
|
80
|
-
- 验证目标完成情况
|
81
|
-
- 如有价值则记录方法论
|
55
|
+
# 🔄 工作流程
|
56
|
+
1. **分析**: 理解和分析问题,定义清晰的目标。
|
57
|
+
2. **设计**: 设计解决方案并制定详细的行动计划。
|
58
|
+
3. **执行**: 按照计划,一次一个步骤地执行。
|
59
|
+
4. **完成**: 验证任务是否达成目标,并进行总结。
|
82
60
|
</workflow>
|
83
61
|
|
84
|
-
<principles>
|
85
|
-
# ⚖️ 操作原则
|
86
|
-
- 每个步骤一个操作
|
87
|
-
- 下一步前必须等待结果
|
88
|
-
- 除非任务完成否则必须生成可操作步骤
|
89
|
-
- 根据反馈调整计划
|
90
|
-
- 记录可复用的解决方案
|
91
|
-
- 使用完成命令结束任务
|
92
|
-
- 操作之间不能有中间思考状态
|
93
|
-
- 所有决策必须表现为工具调用
|
94
|
-
</principles>
|
95
|
-
|
96
|
-
<rules>
|
97
|
-
# ❗ 重要规则
|
98
|
-
1. 每个步骤只能使用一个操作
|
99
|
-
2. 必须等待操作执行结果
|
100
|
-
3. 必须验证任务完成情况
|
101
|
-
4. 必须生成可操作步骤
|
102
|
-
5. 如果无需操作必须使用完成命令
|
103
|
-
6. 永远不要使对话处于等待状态
|
104
|
-
7. 始终使用用户语言交流
|
105
|
-
8. 必须记录有价值的方法论
|
106
|
-
9. 违反操作协议将导致系统崩溃
|
107
|
-
10. 空响应会触发永久挂起
|
108
|
-
</rules>
|
109
|
-
|
110
62
|
<system_info>
|
111
|
-
#
|
112
|
-
{platform.platform()}
|
113
|
-
{
|
114
|
-
|
115
|
-
# 当前时间
|
116
|
-
{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
|
63
|
+
# 系统信息
|
64
|
+
- OS: {platform.platform()} {platform.version()}
|
65
|
+
- Time: {datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
|
117
66
|
</system_info>
|
118
67
|
"""
|
119
68
|
|
120
69
|
|
121
70
|
class OutputHandlerProtocol(Protocol):
|
122
|
-
def name(self) -> str:
|
71
|
+
def name(self) -> str:
|
72
|
+
...
|
123
73
|
|
124
|
-
def can_handle(self, response: str) -> bool:
|
74
|
+
def can_handle(self, response: str) -> bool:
|
75
|
+
...
|
125
76
|
|
126
|
-
def prompt(self) -> str:
|
77
|
+
def prompt(self) -> str:
|
78
|
+
...
|
127
79
|
|
128
|
-
def handle(self, response: str, agent: Any) -> Tuple[bool, Any]:
|
80
|
+
def handle(self, response: str, agent: Any) -> Tuple[bool, Any]:
|
81
|
+
...
|
129
82
|
|
130
83
|
|
131
84
|
class Agent:
|
@@ -191,9 +144,7 @@ class Agent:
|
|
191
144
|
if isinstance(platform, str):
|
192
145
|
self.model = PlatformRegistry().create_platform(platform)
|
193
146
|
if self.model is None:
|
194
|
-
PrettyOutput.print(
|
195
|
-
f"平台 {platform} 不存在,将使用普通模型", OutputType.WARNING
|
196
|
-
)
|
147
|
+
PrettyOutput.print(f"平台 {platform} 不存在,将使用普通模型", OutputType.WARNING)
|
197
148
|
self.model = PlatformRegistry().get_normal_platform()
|
198
149
|
else:
|
199
150
|
self.model = platform
|
@@ -818,18 +769,14 @@ arguments:
|
|
818
769
|
|
819
770
|
if get_interrupt():
|
820
771
|
set_interrupt(False)
|
821
|
-
user_input = self.multiline_inputer(
|
822
|
-
f"模型交互期间被中断,请输入用户干预信息:"
|
823
|
-
)
|
772
|
+
user_input = self.multiline_inputer(f"模型交互期间被中断,请输入用户干预信息:")
|
824
773
|
if user_input:
|
825
774
|
# 如果有工具调用且用户确认继续,则将干预信息和工具执行结果拼接为prompt
|
826
775
|
if any(
|
827
776
|
handler.can_handle(current_response)
|
828
777
|
for handler in self.output_handler
|
829
778
|
):
|
830
|
-
if user_confirm(
|
831
|
-
"检测到有工具调用,是否继续处理工具调用?", True
|
832
|
-
):
|
779
|
+
if user_confirm("检测到有工具调用,是否继续处理工具调用?", True):
|
833
780
|
self.prompt = f"{user_input}\n\n{current_response}"
|
834
781
|
continue
|
835
782
|
self.prompt += f"{user_input}"
|
@@ -875,9 +822,7 @@ arguments:
|
|
875
822
|
if self.use_methodology:
|
876
823
|
if not upload_methodology(self.model, other_files=self.files):
|
877
824
|
if self.files:
|
878
|
-
PrettyOutput.print(
|
879
|
-
"文件上传失败,将忽略文件列表", OutputType.WARNING
|
880
|
-
)
|
825
|
+
PrettyOutput.print("文件上传失败,将忽略文件列表", OutputType.WARNING)
|
881
826
|
# 上传失败则回退到本地加载
|
882
827
|
msg = self.prompt
|
883
828
|
for handler in self.input_handler:
|
@@ -885,14 +830,14 @@ arguments:
|
|
885
830
|
self.prompt = f"{self.prompt}\n\n以下是历史类似问题的执行经验,可参考:\n{load_methodology(msg, self.get_tool_registry())}"
|
886
831
|
else:
|
887
832
|
if self.files:
|
888
|
-
self.prompt =
|
833
|
+
self.prompt = (
|
834
|
+
f"{self.prompt}\n\n上传的文件包含历史对话信息和方法论文件,可以从中获取一些经验信息。"
|
835
|
+
)
|
889
836
|
else:
|
890
837
|
self.prompt = f"{self.prompt}\n\n上传的文件包含历史对话信息,可以从中获取一些经验信息。"
|
891
838
|
elif self.files:
|
892
839
|
if not self.model.upload_files(self.files):
|
893
|
-
PrettyOutput.print(
|
894
|
-
"文件上传失败,将忽略文件列表", OutputType.WARNING
|
895
|
-
)
|
840
|
+
PrettyOutput.print("文件上传失败,将忽略文件列表", OutputType.WARNING)
|
896
841
|
else:
|
897
842
|
self.prompt = f"{self.prompt}\n\n上传的文件包含历史对话信息,可以从中获取一些经验信息。"
|
898
843
|
else:
|
@@ -2,7 +2,7 @@
|
|
2
2
|
from typing import Any, Tuple
|
3
3
|
|
4
4
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
5
|
-
from jarvis.jarvis_utils.
|
5
|
+
from jarvis.jarvis_utils.input import user_confirm
|
6
6
|
|
7
7
|
|
8
8
|
def shell_input_handler(user_input: str, agent: Any) -> Tuple[str, bool]:
|
@@ -30,9 +30,9 @@ from jarvis.jarvis_utils.git_utils import (
|
|
30
30
|
handle_commit_workflow,
|
31
31
|
has_uncommitted_changes,
|
32
32
|
)
|
33
|
-
from jarvis.jarvis_utils.input import get_multiline_input
|
33
|
+
from jarvis.jarvis_utils.input import get_multiline_input, user_confirm
|
34
34
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
35
|
-
from jarvis.jarvis_utils.utils import get_loc_stats, init_env
|
35
|
+
from jarvis.jarvis_utils.utils import get_loc_stats, init_env
|
36
36
|
|
37
37
|
|
38
38
|
class CodeAgent:
|
@@ -359,7 +359,9 @@ class CodeAgent:
|
|
359
359
|
|
360
360
|
# 添加提交信息到final_ret
|
361
361
|
if commits:
|
362
|
-
final_ret +=
|
362
|
+
final_ret += (
|
363
|
+
f"\n\n代码已修改完成\n补丁内容:\n```diff\n{diff}\n```\n"
|
364
|
+
)
|
363
365
|
# 修改后的提示逻辑
|
364
366
|
lint_tools_info = "\n".join(
|
365
367
|
f" - {file}: 使用 {'、'.join(get_lint_tools(file))}"
|
@@ -181,6 +181,36 @@
|
|
181
181
|
"description": "是否打印提示",
|
182
182
|
"default": false
|
183
183
|
},
|
184
|
+
"JARVIS_RAG": {
|
185
|
+
"type": "object",
|
186
|
+
"description": "RAG框架的配置",
|
187
|
+
"properties": {
|
188
|
+
"embedding_mode": {
|
189
|
+
"type": "string",
|
190
|
+
"enum": [
|
191
|
+
"performance",
|
192
|
+
"accuracy"
|
193
|
+
],
|
194
|
+
"default": "performance",
|
195
|
+
"description": "嵌入模型的模式, 'performance'表示性能优先, 'accuracy'表示准确度优先"
|
196
|
+
},
|
197
|
+
"embedding_cache_path": {
|
198
|
+
"type": "string",
|
199
|
+
"default": ".jarvis/rag/embeddings",
|
200
|
+
"description": "嵌入向量缓存的路径, 相对于当前工作目录"
|
201
|
+
},
|
202
|
+
"vector_db_path": {
|
203
|
+
"type": "string",
|
204
|
+
"default": ".jarvis/rag/vectordb",
|
205
|
+
"description": "向量数据库的持久化存储路径, 相对于当前工作目录"
|
206
|
+
}
|
207
|
+
},
|
208
|
+
"default": {
|
209
|
+
"embedding_mode": "performance",
|
210
|
+
"embedding_cache_path": ".jarvis/rag/embeddings",
|
211
|
+
"vector_db_path": ".jarvis/rag/vectordb"
|
212
|
+
}
|
213
|
+
},
|
184
214
|
"JARVIS_REPLACE_MAP": {
|
185
215
|
"type": "object",
|
186
216
|
"description": "自定义替换映射表配置",
|
jarvis/jarvis_git_squash/main.py
CHANGED
@@ -6,7 +6,8 @@ from typing import Dict
|
|
6
6
|
|
7
7
|
from jarvis.jarvis_git_utils.git_commiter import GitCommitTool
|
8
8
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
9
|
-
from jarvis.jarvis_utils.utils import init_env
|
9
|
+
from jarvis.jarvis_utils.utils import init_env
|
10
|
+
from jarvis.jarvis_utils.input import user_confirm
|
10
11
|
|
11
12
|
|
12
13
|
class GitSquashTool:
|
jarvis/jarvis_platform/human.py
CHANGED
@@ -12,6 +12,7 @@ from typing import Generator, List, Tuple
|
|
12
12
|
from jarvis.jarvis_platform.base import BasePlatform
|
13
13
|
from jarvis.jarvis_utils.input import get_multiline_input
|
14
14
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
15
|
+
from jarvis.jarvis_utils.utils import copy_to_clipboard
|
15
16
|
|
16
17
|
|
17
18
|
class HumanPlatform(BasePlatform):
|
@@ -57,13 +58,7 @@ class HumanPlatform(BasePlatform):
|
|
57
58
|
prompt = f"{message} {session_info}"
|
58
59
|
|
59
60
|
# 将prompt复制到剪贴板
|
60
|
-
|
61
|
-
|
62
|
-
try:
|
63
|
-
subprocess.run(["xsel", "-ib"], input=prompt.encode("utf-8"), check=True)
|
64
|
-
PrettyOutput.print("提示已复制到剪贴板", OutputType.INFO)
|
65
|
-
except subprocess.CalledProcessError as e:
|
66
|
-
PrettyOutput.print(f"无法复制到剪贴板: {e}", OutputType.WARNING)
|
61
|
+
copy_to_clipboard(prompt)
|
67
62
|
|
68
63
|
response = get_multiline_input(prompt + "\n\n请回复:")
|
69
64
|
yield response
|
@@ -38,7 +38,9 @@ class YuanbaoPlatform(BasePlatform):
|
|
38
38
|
self.agent_id = "naQivTmsDa"
|
39
39
|
|
40
40
|
if not self.cookies:
|
41
|
-
|
41
|
+
raise ValueError(
|
42
|
+
"YUANBAO_COOKIES environment variable not set. Please provide your cookies to use the Yuanbao platform."
|
43
|
+
)
|
42
44
|
|
43
45
|
self.system_message = "" # 系统消息,用于初始化对话
|
44
46
|
self.first_chat = True # 标识是否为第一次对话
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"""
|
2
|
+
Jarvis RAG Framework
|
3
|
+
|
4
|
+
A flexible RAG pipeline with pluggable remote LLMs and local, cache-enabled embedding models.
|
5
|
+
"""
|
6
|
+
|
7
|
+
from .rag_pipeline import JarvisRAGPipeline
|
8
|
+
from .llm_interface import LLMInterface
|
9
|
+
from .embedding_manager import EmbeddingManager
|
10
|
+
|
11
|
+
__all__ = ["JarvisRAGPipeline", "LLMInterface", "EmbeddingManager"]
|
@@ -0,0 +1,87 @@
|
|
1
|
+
import hashlib
|
2
|
+
from typing import List, Optional, Any
|
3
|
+
|
4
|
+
from diskcache import Cache
|
5
|
+
|
6
|
+
|
7
|
+
class EmbeddingCache:
|
8
|
+
"""
|
9
|
+
A disk-based cache for storing and retrieving text embeddings.
|
10
|
+
|
11
|
+
This class uses diskcache to create a persistent, local cache. It generates
|
12
|
+
a key for each text content based on its SHA256 hash, making lookups
|
13
|
+
deterministic and efficient.
|
14
|
+
"""
|
15
|
+
|
16
|
+
def __init__(self, cache_dir: str, salt: str = ""):
|
17
|
+
"""
|
18
|
+
Initializes the EmbeddingCache.
|
19
|
+
|
20
|
+
Args:
|
21
|
+
cache_dir (str): The directory where the cache will be stored.
|
22
|
+
salt (str): A salt to be added to the hash. This is crucial for
|
23
|
+
ensuring that embeddings generated by different models
|
24
|
+
do not collide. For example, use the model name as a salt.
|
25
|
+
"""
|
26
|
+
self.cache = Cache(cache_dir)
|
27
|
+
self.salt = salt
|
28
|
+
|
29
|
+
def _get_key(self, text: str) -> str:
|
30
|
+
"""Generates a unique cache key for a given text and salt."""
|
31
|
+
hash_object = hashlib.sha256((self.salt + text).encode("utf-8"))
|
32
|
+
return hash_object.hexdigest()
|
33
|
+
|
34
|
+
def get(self, text: str) -> Optional[Any]:
|
35
|
+
"""
|
36
|
+
Retrieves an embedding from the cache.
|
37
|
+
|
38
|
+
Args:
|
39
|
+
text (str): The text to look up.
|
40
|
+
|
41
|
+
Returns:
|
42
|
+
The cached embedding, or None if it's not in the cache.
|
43
|
+
"""
|
44
|
+
key = self._get_key(text)
|
45
|
+
return self.cache.get(key)
|
46
|
+
|
47
|
+
def set(self, text: str, embedding: Any) -> None:
|
48
|
+
"""
|
49
|
+
Stores an embedding in the cache.
|
50
|
+
|
51
|
+
Args:
|
52
|
+
text (str): The text corresponding to the embedding.
|
53
|
+
embedding (Any): The embedding vector to store.
|
54
|
+
"""
|
55
|
+
key = self._get_key(text)
|
56
|
+
self.cache.set(key, embedding)
|
57
|
+
|
58
|
+
def get_batch(self, texts: List[str]) -> List[Optional[Any]]:
|
59
|
+
"""
|
60
|
+
Retrieves a batch of embeddings from the cache.
|
61
|
+
|
62
|
+
Args:
|
63
|
+
texts (List[str]): A list of texts to look up.
|
64
|
+
|
65
|
+
Returns:
|
66
|
+
A list containing cached embeddings or None for cache misses.
|
67
|
+
"""
|
68
|
+
return [self.get(text) for text in texts]
|
69
|
+
|
70
|
+
def set_batch(self, texts: List[str], embeddings: List[Any]) -> None:
|
71
|
+
"""
|
72
|
+
Stores a batch of embeddings in the cache.
|
73
|
+
|
74
|
+
Args:
|
75
|
+
texts (List[str]): The list of texts.
|
76
|
+
embeddings (List[Any]): The list of corresponding embeddings.
|
77
|
+
"""
|
78
|
+
if len(texts) != len(embeddings):
|
79
|
+
raise ValueError("Length of texts and embeddings must be the same.")
|
80
|
+
|
81
|
+
with self.cache.transact():
|
82
|
+
for text, embedding in zip(texts, embeddings):
|
83
|
+
self.set(text, embedding)
|
84
|
+
|
85
|
+
def close(self):
|
86
|
+
"""Closes the cache connection."""
|
87
|
+
self.cache.close()
|