jarvis-ai-assistant 0.1.124__py3-none-any.whl → 0.1.126__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/jarvis_agent/__init__.py +134 -136
- jarvis/jarvis_code_agent/code_agent.py +198 -52
- jarvis/jarvis_code_agent/file_select.py +6 -19
- jarvis/jarvis_code_agent/patch.py +183 -312
- jarvis/jarvis_code_agent/shell_input_handler.py +22 -0
- jarvis/jarvis_codebase/main.py +89 -86
- jarvis/jarvis_dev/main.py +695 -715
- jarvis/jarvis_git_squash/__init__.py +0 -0
- jarvis/jarvis_git_squash/main.py +81 -0
- jarvis/jarvis_lsp/base.py +0 -12
- jarvis/jarvis_lsp/cpp.py +1 -10
- jarvis/jarvis_lsp/go.py +1 -10
- jarvis/jarvis_lsp/python.py +0 -28
- jarvis/jarvis_lsp/registry.py +2 -3
- jarvis/jarvis_lsp/rust.py +1 -10
- jarvis/jarvis_multi_agent/__init__.py +53 -53
- jarvis/jarvis_platform/ai8.py +2 -1
- jarvis/jarvis_platform/base.py +19 -24
- jarvis/jarvis_platform/kimi.py +2 -3
- jarvis/jarvis_platform/ollama.py +3 -1
- jarvis/jarvis_platform/openai.py +1 -1
- jarvis/jarvis_platform/oyi.py +2 -1
- jarvis/jarvis_platform/registry.py +2 -1
- jarvis/jarvis_platform_manager/main.py +4 -6
- jarvis/jarvis_platform_manager/openai_test.py +0 -1
- jarvis/jarvis_rag/main.py +5 -2
- jarvis/jarvis_smart_shell/main.py +9 -4
- jarvis/jarvis_tools/ask_codebase.py +18 -13
- jarvis/jarvis_tools/ask_user.py +5 -4
- jarvis/jarvis_tools/base.py +22 -8
- jarvis/jarvis_tools/chdir.py +8 -9
- jarvis/jarvis_tools/code_review.py +19 -20
- jarvis/jarvis_tools/create_code_agent.py +6 -6
- jarvis/jarvis_tools/create_sub_agent.py +9 -9
- jarvis/jarvis_tools/execute_shell.py +55 -20
- jarvis/jarvis_tools/execute_shell_script.py +7 -7
- jarvis/jarvis_tools/file_operation.py +39 -10
- jarvis/jarvis_tools/git_commiter.py +20 -17
- jarvis/jarvis_tools/lsp_find_definition.py +8 -8
- jarvis/jarvis_tools/lsp_find_references.py +1 -1
- jarvis/jarvis_tools/lsp_get_diagnostics.py +19 -11
- jarvis/jarvis_tools/lsp_get_document_symbols.py +1 -1
- jarvis/jarvis_tools/lsp_prepare_rename.py +8 -8
- jarvis/jarvis_tools/methodology.py +10 -7
- jarvis/jarvis_tools/rag.py +27 -20
- jarvis/jarvis_tools/read_webpage.py +4 -3
- jarvis/jarvis_tools/registry.py +143 -140
- jarvis/jarvis_tools/{search.py → search_web.py} +10 -7
- jarvis/jarvis_tools/select_code_files.py +4 -4
- jarvis/jarvis_tools/tool_generator.py +33 -34
- jarvis/jarvis_utils/__init__.py +19 -982
- jarvis/jarvis_utils/config.py +138 -0
- jarvis/jarvis_utils/embedding.py +201 -0
- jarvis/jarvis_utils/git_utils.py +120 -0
- jarvis/jarvis_utils/globals.py +82 -0
- jarvis/jarvis_utils/input.py +161 -0
- jarvis/jarvis_utils/methodology.py +128 -0
- jarvis/jarvis_utils/output.py +235 -0
- jarvis/jarvis_utils/utils.py +150 -0
- jarvis_ai_assistant-0.1.126.dist-info/METADATA +305 -0
- jarvis_ai_assistant-0.1.126.dist-info/RECORD +74 -0
- {jarvis_ai_assistant-0.1.124.dist-info → jarvis_ai_assistant-0.1.126.dist-info}/WHEEL +1 -1
- {jarvis_ai_assistant-0.1.124.dist-info → jarvis_ai_assistant-0.1.126.dist-info}/entry_points.txt +1 -0
- jarvis/jarvis_tools/lsp_validate_edit.py +0 -141
- jarvis/jarvis_tools/read_code.py +0 -191
- jarvis_ai_assistant-0.1.124.dist-info/METADATA +0 -460
- jarvis_ai_assistant-0.1.124.dist-info/RECORD +0 -65
- {jarvis_ai_assistant-0.1.124.dist-info → jarvis_ai_assistant-0.1.126.dist-info}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.124.dist-info → jarvis_ai_assistant-0.1.126.dist-info}/top_level.txt +0 -0
jarvis/jarvis_tools/registry.py
CHANGED
|
@@ -9,45 +9,48 @@ import yaml
|
|
|
9
9
|
from jarvis.jarvis_agent.output_handler import OutputHandler
|
|
10
10
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
11
11
|
from jarvis.jarvis_tools.base import Tool
|
|
12
|
-
from jarvis.jarvis_utils import
|
|
12
|
+
from jarvis.jarvis_utils.config import get_max_token_count
|
|
13
|
+
from jarvis.jarvis_utils.embedding import get_context_token_count
|
|
14
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
15
|
+
|
|
13
16
|
|
|
14
17
|
|
|
15
18
|
tool_call_help = """
|
|
16
|
-
# 🛠️
|
|
17
|
-
|
|
19
|
+
# 🛠️ 工具使用系统
|
|
20
|
+
您正在使用一个需要精确格式和严格规则的工具执行系统。
|
|
18
21
|
|
|
19
|
-
# 📋
|
|
22
|
+
# 📋 工具调用格式
|
|
20
23
|
<TOOL_CALL>
|
|
21
|
-
name:
|
|
24
|
+
name: 工具名称
|
|
22
25
|
arguments:
|
|
23
|
-
param1:
|
|
24
|
-
param2:
|
|
26
|
+
param1: 值1
|
|
27
|
+
param2: 值2
|
|
25
28
|
</TOOL_CALL>
|
|
26
29
|
|
|
27
|
-
# ❗
|
|
28
|
-
1.
|
|
29
|
-
-
|
|
30
|
-
-
|
|
30
|
+
# ❗ 关键规则
|
|
31
|
+
1. 每次只使用一个工具
|
|
32
|
+
- 一次只执行一个工具
|
|
33
|
+
- 等待结果后再进行下一步
|
|
31
34
|
|
|
32
|
-
2.
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
35
|
+
2. 严格遵守格式
|
|
36
|
+
- 完全按照上述格式
|
|
37
|
+
- 使用正确的YAML缩进
|
|
38
|
+
- 包含所有必需参数
|
|
36
39
|
|
|
37
|
-
3.
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
40
|
+
3. 结果处理
|
|
41
|
+
- 等待执行结果
|
|
42
|
+
- 不要假设结果
|
|
43
|
+
- 不要创建虚假响应
|
|
44
|
+
- 不要想象对话
|
|
42
45
|
|
|
43
|
-
4.
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
46
|
+
4. 信息管理
|
|
47
|
+
- 如果信息不足,询问用户
|
|
48
|
+
- 跳过不必要的步骤
|
|
49
|
+
- 如果卡住,请求指导
|
|
50
|
+
- 不要在没有完整信息的情况下继续
|
|
48
51
|
|
|
49
|
-
# 📝
|
|
50
|
-
|
|
52
|
+
# 📝 字符串参数格式
|
|
53
|
+
始终使用 | 语法表示字符串参数:
|
|
51
54
|
|
|
52
55
|
<TOOL_CALL>
|
|
53
56
|
name: execute_shell
|
|
@@ -56,19 +59,19 @@ arguments:
|
|
|
56
59
|
git status --porcelain
|
|
57
60
|
</TOOL_CALL>
|
|
58
61
|
|
|
59
|
-
# 💡
|
|
60
|
-
-
|
|
61
|
-
-
|
|
62
|
-
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
|
|
66
|
-
# ⚠️
|
|
67
|
-
-
|
|
68
|
-
-
|
|
69
|
-
-
|
|
70
|
-
-
|
|
71
|
-
-
|
|
62
|
+
# 💡 最佳实践
|
|
63
|
+
- 准备好后立即开始执行
|
|
64
|
+
- 无需请求许可即可开始
|
|
65
|
+
- 使用正确的字符串格式
|
|
66
|
+
- 监控进度并调整
|
|
67
|
+
- 遇到困难时请求帮助
|
|
68
|
+
|
|
69
|
+
# ⚠️ 常见错误
|
|
70
|
+
- 同时调用多个工具
|
|
71
|
+
- 字符串参数缺少 |
|
|
72
|
+
- 假设工具结果
|
|
73
|
+
- 创建虚构对话
|
|
74
|
+
- 在没有所需信息的情况下继续
|
|
72
75
|
"""
|
|
73
76
|
|
|
74
77
|
class ToolRegistry(OutputHandler):
|
|
@@ -82,14 +85,14 @@ class ToolRegistry(OutputHandler):
|
|
|
82
85
|
return False
|
|
83
86
|
|
|
84
87
|
def prompt(self) -> str:
|
|
85
|
-
"""
|
|
88
|
+
"""加载工具"""
|
|
86
89
|
tools = self.get_all_tools()
|
|
87
90
|
if tools:
|
|
88
|
-
tools_prompt = "##
|
|
91
|
+
tools_prompt = "## 可用工具:\n"
|
|
89
92
|
for tool in tools:
|
|
90
|
-
tools_prompt += f"-
|
|
91
|
-
tools_prompt += f"
|
|
92
|
-
tools_prompt += f"
|
|
93
|
+
tools_prompt += f"- 名称: {tool['name']}\n"
|
|
94
|
+
tools_prompt += f" 描述: {tool['description']}\n"
|
|
95
|
+
tools_prompt += f" 参数: {tool['parameters']}\n"
|
|
93
96
|
tools_prompt += tool_call_help
|
|
94
97
|
return tools_prompt
|
|
95
98
|
return ""
|
|
@@ -98,87 +101,87 @@ class ToolRegistry(OutputHandler):
|
|
|
98
101
|
tool_calls = self._extract_tool_calls(response)
|
|
99
102
|
if len(tool_calls) > 1:
|
|
100
103
|
PrettyOutput.print(f"操作失败:检测到多个操作。一次只能执行一个操作。尝试执行的操作:{', '.join([tool_call['name'] for tool_call in tool_calls])}", OutputType.WARNING)
|
|
101
|
-
return False, f"
|
|
104
|
+
return False, f"调用失败:请一次只处理一个工具调用。"
|
|
102
105
|
if len(tool_calls) == 0:
|
|
103
106
|
return False, ""
|
|
104
107
|
tool_call = tool_calls[0]
|
|
105
108
|
return False, self.handle_tool_calls(tool_call)
|
|
106
109
|
|
|
107
110
|
def __init__(self):
|
|
108
|
-
"""
|
|
111
|
+
"""初始化工具注册表"""
|
|
109
112
|
self.tools: Dict[str, Tool] = {}
|
|
110
|
-
#
|
|
113
|
+
# 加载内置工具和外部工具
|
|
111
114
|
self._load_builtin_tools()
|
|
112
115
|
self._load_external_tools()
|
|
113
|
-
#
|
|
116
|
+
# 确保max_token_count是整数
|
|
114
117
|
self.max_token_count = int(get_max_token_count() * 0.8)
|
|
115
118
|
|
|
116
119
|
def use_tools(self, name: List[str]):
|
|
117
|
-
"""
|
|
120
|
+
"""使用指定工具"""
|
|
118
121
|
missing_tools = [tool_name for tool_name in name if tool_name not in self.tools]
|
|
119
122
|
if missing_tools:
|
|
120
123
|
PrettyOutput.print(f"工具 {missing_tools} 不存在,可用的工具有: {', '.join(self.tools.keys())}", OutputType.WARNING)
|
|
121
124
|
self.tools = {tool_name: self.tools[tool_name] for tool_name in name}
|
|
122
125
|
|
|
123
126
|
def dont_use_tools(self, names: List[str]):
|
|
124
|
-
"""
|
|
127
|
+
"""从注册表中移除指定工具"""
|
|
125
128
|
self.tools = {name: tool for name, tool in self.tools.items() if name not in names}
|
|
126
129
|
|
|
127
130
|
def _load_builtin_tools(self):
|
|
128
|
-
"""
|
|
131
|
+
"""从内置工具目录加载工具"""
|
|
129
132
|
tools_dir = Path(__file__).parent
|
|
130
133
|
|
|
131
|
-
#
|
|
134
|
+
# 遍历目录中的所有.py文件
|
|
132
135
|
for file_path in tools_dir.glob("*.py"):
|
|
133
|
-
#
|
|
136
|
+
# 跳过base.py和__init__.py
|
|
134
137
|
if file_path.name in ["base.py", "__init__.py", "registry.py"]:
|
|
135
138
|
continue
|
|
136
139
|
|
|
137
140
|
self.register_tool_by_file(str(file_path))
|
|
138
141
|
|
|
139
142
|
def _load_external_tools(self):
|
|
140
|
-
"""
|
|
143
|
+
"""从~/.jarvis/tools加载外部工具"""
|
|
141
144
|
external_tools_dir = Path.home() / '.jarvis/tools'
|
|
142
145
|
if not external_tools_dir.exists():
|
|
143
146
|
return
|
|
144
147
|
|
|
145
|
-
#
|
|
148
|
+
# 遍历目录中的所有.py文件
|
|
146
149
|
for file_path in external_tools_dir.glob("*.py"):
|
|
147
|
-
#
|
|
150
|
+
# 跳过__init__.py
|
|
148
151
|
if file_path.name == "__init__.py":
|
|
149
152
|
continue
|
|
150
153
|
|
|
151
154
|
self.register_tool_by_file(str(file_path))
|
|
152
155
|
|
|
153
156
|
def register_tool_by_file(self, file_path: str):
|
|
154
|
-
"""
|
|
157
|
+
"""从指定文件加载并注册工具
|
|
155
158
|
|
|
156
|
-
|
|
157
|
-
file_path:
|
|
159
|
+
参数:
|
|
160
|
+
file_path: 工具文件的路径
|
|
158
161
|
|
|
159
|
-
|
|
160
|
-
bool:
|
|
162
|
+
返回:
|
|
163
|
+
bool: 工具是否加载成功
|
|
161
164
|
"""
|
|
162
165
|
try:
|
|
163
|
-
p_file_path = Path(file_path).resolve() #
|
|
166
|
+
p_file_path = Path(file_path).resolve() # 获取绝对路径
|
|
164
167
|
if not p_file_path.exists() or not p_file_path.is_file():
|
|
165
168
|
PrettyOutput.print(f"文件不存在: {p_file_path}", OutputType.ERROR)
|
|
166
169
|
return False
|
|
167
170
|
|
|
168
|
-
#
|
|
171
|
+
# 临时将父目录添加到sys.path
|
|
169
172
|
parent_dir = str(p_file_path.parent)
|
|
170
173
|
sys.path.insert(0, parent_dir)
|
|
171
174
|
|
|
172
175
|
try:
|
|
173
|
-
#
|
|
176
|
+
# 使用标准导入机制导入模块
|
|
174
177
|
module_name = p_file_path.stem
|
|
175
178
|
module = __import__(module_name)
|
|
176
179
|
|
|
177
|
-
#
|
|
180
|
+
# 在模块中查找工具类
|
|
178
181
|
tool_found = False
|
|
179
182
|
for item_name in dir(module):
|
|
180
183
|
item = getattr(module, item_name)
|
|
181
|
-
#
|
|
184
|
+
# 检查是否是类并具有必要属性
|
|
182
185
|
if (isinstance(item, type) and
|
|
183
186
|
hasattr(item, 'name') and
|
|
184
187
|
hasattr(item, 'description') and
|
|
@@ -190,10 +193,10 @@ class ToolRegistry(OutputHandler):
|
|
|
190
193
|
if not item.check():
|
|
191
194
|
continue
|
|
192
195
|
|
|
193
|
-
#
|
|
196
|
+
# 实例化工具类
|
|
194
197
|
tool_instance = item()
|
|
195
198
|
|
|
196
|
-
#
|
|
199
|
+
# 注册工具
|
|
197
200
|
self.register_tool(
|
|
198
201
|
name=tool_instance.name,
|
|
199
202
|
description=tool_instance.description,
|
|
@@ -209,7 +212,7 @@ class ToolRegistry(OutputHandler):
|
|
|
209
212
|
return True
|
|
210
213
|
|
|
211
214
|
finally:
|
|
212
|
-
#
|
|
215
|
+
# 从sys.path中移除目录
|
|
213
216
|
sys.path.remove(parent_dir)
|
|
214
217
|
|
|
215
218
|
except Exception as e:
|
|
@@ -217,18 +220,18 @@ class ToolRegistry(OutputHandler):
|
|
|
217
220
|
return False
|
|
218
221
|
@staticmethod
|
|
219
222
|
def _extract_tool_calls(content: str) -> List[Dict]:
|
|
220
|
-
"""
|
|
223
|
+
"""从内容中提取工具调用。
|
|
221
224
|
|
|
222
|
-
|
|
223
|
-
content:
|
|
225
|
+
参数:
|
|
226
|
+
content: 包含工具调用的内容
|
|
224
227
|
|
|
225
|
-
|
|
226
|
-
List[Dict]:
|
|
228
|
+
返回:
|
|
229
|
+
List[Dict]: 包含名称和参数的提取工具调用列表
|
|
227
230
|
|
|
228
|
-
|
|
229
|
-
Exception:
|
|
231
|
+
异常:
|
|
232
|
+
Exception: 如果工具调用缺少必要字段
|
|
230
233
|
"""
|
|
231
|
-
#
|
|
234
|
+
# 将内容拆分为行
|
|
232
235
|
data = re.findall(r'<TOOL_CALL>(.*?)</TOOL_CALL>', content, re.DOTALL)
|
|
233
236
|
ret = []
|
|
234
237
|
for item in data:
|
|
@@ -241,68 +244,68 @@ class ToolRegistry(OutputHandler):
|
|
|
241
244
|
return ret
|
|
242
245
|
|
|
243
246
|
def register_tool(self, name: str, description: str, parameters: Dict, func: Callable):
|
|
244
|
-
"""
|
|
247
|
+
"""注册新工具"""
|
|
245
248
|
self.tools[name] = Tool(name, description, parameters, func)
|
|
246
249
|
|
|
247
250
|
def get_tool(self, name: str) -> Optional[Tool]:
|
|
248
|
-
"""
|
|
251
|
+
"""获取工具"""
|
|
249
252
|
return self.tools.get(name)
|
|
250
253
|
|
|
251
254
|
def get_all_tools(self) -> List[Dict]:
|
|
252
|
-
"""
|
|
255
|
+
"""获取所有工具(Ollama格式定义)"""
|
|
253
256
|
return [tool.to_dict() for tool in self.tools.values()]
|
|
254
257
|
|
|
255
258
|
def execute_tool(self, name: str, arguments: Dict) -> Dict[str, Any]:
|
|
256
|
-
"""
|
|
259
|
+
"""执行指定工具"""
|
|
257
260
|
tool = self.get_tool(name)
|
|
258
261
|
if tool is None:
|
|
259
|
-
return {"success": False, "stderr": f"
|
|
262
|
+
return {"success": False, "stderr": f"工具 {name} 不存在,可用的工具有: {', '.join(self.tools.keys())}", "stdout": ""}
|
|
260
263
|
return tool.execute(arguments)
|
|
261
264
|
|
|
262
265
|
def handle_tool_calls(self, tool_call: Dict) -> str:
|
|
263
|
-
"""
|
|
266
|
+
"""处理工具调用,只处理第一个工具"""
|
|
264
267
|
try:
|
|
265
|
-
#
|
|
268
|
+
# 只处理第一个工具调用
|
|
266
269
|
name = tool_call["name"]
|
|
267
270
|
args = tool_call["arguments"]
|
|
268
271
|
|
|
269
272
|
tool_call_help = """
|
|
270
|
-
# 🛠️
|
|
271
|
-
|
|
273
|
+
# 🛠️ 工具使用系统
|
|
274
|
+
您正在使用一个需要精确格式和严格规则的工具执行系统。
|
|
272
275
|
|
|
273
|
-
# 📋
|
|
276
|
+
# 📋 工具调用格式
|
|
274
277
|
|
|
275
278
|
<TOOL_CALL>
|
|
276
|
-
name:
|
|
279
|
+
name: 工具名称
|
|
277
280
|
arguments:
|
|
278
|
-
param1:
|
|
279
|
-
param2:
|
|
281
|
+
param1: 值1
|
|
282
|
+
param2: 值2
|
|
280
283
|
</TOOL_CALL>
|
|
281
284
|
|
|
282
|
-
# ❗
|
|
283
|
-
1.
|
|
284
|
-
-
|
|
285
|
-
-
|
|
285
|
+
# ❗ 关键规则
|
|
286
|
+
1. 每次只使用一个工具
|
|
287
|
+
- 一次只执行一个工具
|
|
288
|
+
- 等待结果后再进行下一步
|
|
286
289
|
|
|
287
|
-
2.
|
|
288
|
-
-
|
|
289
|
-
-
|
|
290
|
-
-
|
|
290
|
+
2. 严格遵守格式
|
|
291
|
+
- 完全按照上述格式
|
|
292
|
+
- 使用正确的YAML缩进
|
|
293
|
+
- 包含所有必需参数
|
|
291
294
|
|
|
292
|
-
3.
|
|
293
|
-
-
|
|
294
|
-
-
|
|
295
|
-
-
|
|
296
|
-
-
|
|
295
|
+
3. 结果处理
|
|
296
|
+
- 等待执行结果
|
|
297
|
+
- 不要假设结果
|
|
298
|
+
- 不要创建虚假响应
|
|
299
|
+
- 不要想象对话
|
|
297
300
|
|
|
298
|
-
4.
|
|
299
|
-
-
|
|
300
|
-
-
|
|
301
|
-
-
|
|
302
|
-
-
|
|
301
|
+
4. 信息管理
|
|
302
|
+
- 如果信息不足,询问用户
|
|
303
|
+
- 跳过不必要的步骤
|
|
304
|
+
- 如果卡住,请求指导
|
|
305
|
+
- 不要在没有完整信息的情况下继续
|
|
303
306
|
|
|
304
|
-
# 📝
|
|
305
|
-
|
|
307
|
+
# 📝 字符串参数格式
|
|
308
|
+
始终使用 | 语法表示字符串参数:
|
|
306
309
|
|
|
307
310
|
<TOOL_CALL>
|
|
308
311
|
name: execute_shell
|
|
@@ -311,19 +314,19 @@ arguments:
|
|
|
311
314
|
git status --porcelain
|
|
312
315
|
</TOOL_CALL>
|
|
313
316
|
|
|
314
|
-
# 💡
|
|
315
|
-
-
|
|
316
|
-
-
|
|
317
|
-
-
|
|
318
|
-
-
|
|
319
|
-
-
|
|
320
|
-
|
|
321
|
-
# ⚠️
|
|
322
|
-
-
|
|
323
|
-
-
|
|
324
|
-
-
|
|
325
|
-
-
|
|
326
|
-
-
|
|
317
|
+
# 💡 最佳实践
|
|
318
|
+
- 准备好后立即开始执行
|
|
319
|
+
- 无需请求许可即可开始
|
|
320
|
+
- 使用正确的字符串格式
|
|
321
|
+
- 监控进度并调整
|
|
322
|
+
- 遇到困难时请求帮助
|
|
323
|
+
|
|
324
|
+
# ⚠️ 常见错误
|
|
325
|
+
- 同时调用多个工具
|
|
326
|
+
- 字符串参数缺少 |
|
|
327
|
+
- 假设工具结果
|
|
328
|
+
- 创建虚构对话
|
|
329
|
+
- 在没有所需信息的情况下继续
|
|
327
330
|
"""
|
|
328
331
|
|
|
329
332
|
if isinstance(args, str):
|
|
@@ -351,11 +354,11 @@ arguments:
|
|
|
351
354
|
stderr = result.get("stderr", "")
|
|
352
355
|
output_parts = []
|
|
353
356
|
if stdout:
|
|
354
|
-
output_parts.append(f"
|
|
357
|
+
output_parts.append(f"输出:\n{stdout}")
|
|
355
358
|
if stderr:
|
|
356
|
-
output_parts.append(f"
|
|
359
|
+
output_parts.append(f"错误:\n{stderr}")
|
|
357
360
|
output = "\n\n".join(output_parts)
|
|
358
|
-
output = "
|
|
361
|
+
output = "无输出和错误" if not output else output
|
|
359
362
|
|
|
360
363
|
# Process the result
|
|
361
364
|
if result["success"]:
|
|
@@ -372,33 +375,33 @@ arguments:
|
|
|
372
375
|
max_count = self.max_token_count
|
|
373
376
|
if get_context_token_count(output) > max_count:
|
|
374
377
|
output_to_summarize = output[-max_count:]
|
|
375
|
-
truncation_notice = f"\n(
|
|
378
|
+
truncation_notice = f"\n(注意:由于输出过长,仅总结最后 {max_count} 个字符)"
|
|
376
379
|
else:
|
|
377
380
|
output_to_summarize = output
|
|
378
381
|
truncation_notice = ""
|
|
379
382
|
|
|
380
|
-
prompt = f"""
|
|
381
|
-
1.
|
|
382
|
-
2.
|
|
383
|
-
3.
|
|
384
|
-
4.
|
|
383
|
+
prompt = f"""请总结以下工具的执行结果,提取关键信息和重要结果。注意:
|
|
384
|
+
1. 保留所有重要的数值、路径、错误信息等
|
|
385
|
+
2. 保持结果的准确性
|
|
386
|
+
3. 用简洁的语言描述主要内容
|
|
387
|
+
4. 如果有错误信息,确保包含在总结中
|
|
385
388
|
|
|
386
|
-
|
|
387
|
-
|
|
389
|
+
工具名称: {name}
|
|
390
|
+
执行结果:
|
|
388
391
|
{output_to_summarize}
|
|
389
392
|
|
|
390
|
-
|
|
393
|
+
请提供总结:"""
|
|
391
394
|
|
|
392
395
|
summary = model.chat_until_success(prompt)
|
|
393
|
-
output = f"""---
|
|
396
|
+
output = f"""--- 原始输出过长,以下是总结 ---{truncation_notice}
|
|
394
397
|
|
|
395
398
|
{summary}
|
|
396
399
|
|
|
397
|
-
---
|
|
400
|
+
--- 总结结束 ---"""
|
|
398
401
|
|
|
399
402
|
except Exception as e:
|
|
400
403
|
PrettyOutput.print(f"总结失败: {str(e)}", OutputType.ERROR)
|
|
401
|
-
output = f"
|
|
404
|
+
output = f"输出过长 ({len(output)} 字符),建议查看原始输出。\n前300字符预览:\n{output[:300]}..."
|
|
402
405
|
|
|
403
406
|
else:
|
|
404
407
|
PrettyOutput.section("执行失败", OutputType.WARNING)
|
|
@@ -407,4 +410,4 @@ Please provide a summary:"""
|
|
|
407
410
|
|
|
408
411
|
except Exception as e:
|
|
409
412
|
PrettyOutput.print(f"工具执行失败:{str(e)}", OutputType.ERROR)
|
|
410
|
-
return f"
|
|
413
|
+
return f"工具调用失败: {str(e)}"
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
from typing import Dict, Any, List
|
|
2
2
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
3
|
-
from jarvis.jarvis_utils import PrettyOutput, OutputType, get_context_token_count, get_max_token_count
|
|
4
3
|
from jarvis.jarvis_tools.read_webpage import WebpageTool
|
|
5
4
|
from playwright.sync_api import sync_playwright
|
|
6
5
|
from urllib.parse import quote
|
|
7
6
|
|
|
7
|
+
from jarvis.jarvis_utils.config import get_max_token_count
|
|
8
|
+
from jarvis.jarvis_utils.embedding import get_context_token_count
|
|
9
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
10
|
+
|
|
8
11
|
def bing_search(query):
|
|
9
12
|
try:
|
|
10
13
|
with sync_playwright() as p:
|
|
@@ -62,22 +65,22 @@ def bing_search(query):
|
|
|
62
65
|
return None
|
|
63
66
|
|
|
64
67
|
class SearchTool:
|
|
65
|
-
name = "
|
|
66
|
-
description = "
|
|
68
|
+
name = "search_web"
|
|
69
|
+
description = "使用Bing搜索引擎搜索信息,并根据问题提取关键信息"
|
|
67
70
|
parameters = {
|
|
68
71
|
"type": "object",
|
|
69
72
|
"properties": {
|
|
70
73
|
"query": {
|
|
71
74
|
"type": "string",
|
|
72
|
-
"description": "
|
|
75
|
+
"description": "搜索关键词"
|
|
73
76
|
},
|
|
74
77
|
"question": {
|
|
75
78
|
"type": "string",
|
|
76
|
-
"description": "
|
|
79
|
+
"description": "要回答的具体问题,用于从搜索结果中提取相关信息"
|
|
77
80
|
},
|
|
78
81
|
"max_results": {
|
|
79
82
|
"type": "integer",
|
|
80
|
-
"description": "
|
|
83
|
+
"description": "最大搜索结果数量",
|
|
81
84
|
"default": 3
|
|
82
85
|
}
|
|
83
86
|
},
|
|
@@ -290,4 +293,4 @@ def main():
|
|
|
290
293
|
sys.exit(1)
|
|
291
294
|
|
|
292
295
|
if __name__ == "__main__":
|
|
293
|
-
main()
|
|
296
|
+
main()
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
from typing import Dict, Any
|
|
2
2
|
|
|
3
|
-
from jarvis.jarvis_utils import OutputType, PrettyOutput
|
|
4
3
|
from jarvis.jarvis_code_agent.file_select import select_files
|
|
4
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class CodeFileSelecterTool:
|
|
8
8
|
name = "select_code_files"
|
|
9
|
-
description = "
|
|
9
|
+
description = "通过交互式文件选择工具选择和修改代码文件"
|
|
10
10
|
parameters = {
|
|
11
11
|
"type": "object",
|
|
12
12
|
"properties": {
|
|
@@ -15,12 +15,12 @@ class CodeFileSelecterTool:
|
|
|
15
15
|
"items": {
|
|
16
16
|
"type": "string",
|
|
17
17
|
},
|
|
18
|
-
"description": "
|
|
18
|
+
"description": "初始相关的文件列表",
|
|
19
19
|
"default": []
|
|
20
20
|
},
|
|
21
21
|
"root_dir": {
|
|
22
22
|
"type": "string",
|
|
23
|
-
"description": "
|
|
23
|
+
"description": "代码库的根目录",
|
|
24
24
|
"default": "."
|
|
25
25
|
}
|
|
26
26
|
},
|