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
|
@@ -5,20 +5,23 @@ from typing import Dict, Any
|
|
|
5
5
|
import tempfile
|
|
6
6
|
import yaml
|
|
7
7
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
8
|
-
from jarvis.jarvis_utils import OutputType, PrettyOutput, has_uncommitted_changes, init_env
|
|
9
8
|
import sys
|
|
10
9
|
import argparse
|
|
11
10
|
|
|
11
|
+
from jarvis.jarvis_utils.git_utils import has_uncommitted_changes
|
|
12
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
13
|
+
from jarvis.jarvis_utils.utils import init_env
|
|
14
|
+
|
|
12
15
|
|
|
13
16
|
class GitCommitTool:
|
|
14
17
|
name = "git_commit_agent"
|
|
15
|
-
description = "
|
|
18
|
+
description = "根据代码变更自动生成并执行Git提交"
|
|
16
19
|
parameters = {
|
|
17
20
|
"type": "object",
|
|
18
21
|
"properties": {
|
|
19
22
|
"lang": {
|
|
20
23
|
"type": "string",
|
|
21
|
-
"description": "
|
|
24
|
+
"description": "提交信息的语言",
|
|
22
25
|
"default": "Chinese"
|
|
23
26
|
}
|
|
24
27
|
},
|
|
@@ -67,21 +70,21 @@ class GitCommitTool:
|
|
|
67
70
|
diff = process.communicate()[0].decode()
|
|
68
71
|
PrettyOutput.print(diff, OutputType.CODE, lang="diff")
|
|
69
72
|
|
|
70
|
-
prompt = f'''
|
|
71
|
-
|
|
72
|
-
#
|
|
73
|
-
|
|
73
|
+
prompt = f'''根据以下规则生成提交信息:
|
|
74
|
+
提交信息应使用{args.get('lang', '中文')}书写
|
|
75
|
+
# 必需结构
|
|
76
|
+
必须使用以下格式:
|
|
74
77
|
<COMMIT_MESSAGE>
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
<类型>(<范围>): <主题>
|
|
79
|
+
使用祈使语气描述变更内容
|
|
77
80
|
</COMMIT_MESSAGE>
|
|
78
|
-
#
|
|
79
|
-
1.
|
|
80
|
-
2.
|
|
81
|
-
3.
|
|
82
|
-
4.
|
|
83
|
-
5.
|
|
84
|
-
#
|
|
81
|
+
# 格式规则
|
|
82
|
+
1. 类型: fix, feat, docs, style, refactor, test, chore
|
|
83
|
+
2. 范围表示模块 (例如: auth, database)
|
|
84
|
+
3. 主题行 <= 72个字符,不以句号结尾
|
|
85
|
+
4. 正文使用现在时态解释每个变更的内容和原因
|
|
86
|
+
5. 不要遗漏任何变更
|
|
87
|
+
# 分析材料
|
|
85
88
|
{diff}
|
|
86
89
|
'''
|
|
87
90
|
|
|
@@ -131,4 +134,4 @@ def main():
|
|
|
131
134
|
tool.execute({"lang": args.lang if hasattr(args, 'lang') else 'Chinese'})
|
|
132
135
|
|
|
133
136
|
if __name__ == "__main__":
|
|
134
|
-
sys.exit(main())
|
|
137
|
+
sys.exit(main())
|
|
@@ -3,15 +3,15 @@ from typing import Dict, Any
|
|
|
3
3
|
from jarvis.jarvis_lsp.registry import LSPRegistry
|
|
4
4
|
|
|
5
5
|
class LSPFindDefinitionTool:
|
|
6
|
-
"""
|
|
6
|
+
"""使用LSP在代码中查找符号定义的工具"""
|
|
7
7
|
|
|
8
8
|
name = "lsp_find_definition"
|
|
9
|
-
description = "
|
|
9
|
+
description = "在代码中查找符号的定义"
|
|
10
10
|
parameters = {
|
|
11
|
-
"file_path": "
|
|
12
|
-
"line": "
|
|
13
|
-
"character": "
|
|
14
|
-
"language": f"
|
|
11
|
+
"file_path": "包含符号的文件路径",
|
|
12
|
+
"line": "符号所在的行号(从0开始)",
|
|
13
|
+
"character": "符号在行中的字符位置",
|
|
14
|
+
"language": f"文件的编程语言({', '.join(LSPRegistry.get_global_lsp_registry().get_supported_languages())})"
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
@staticmethod
|
|
@@ -65,7 +65,7 @@ class LSPFindDefinitionTool:
|
|
|
65
65
|
|
|
66
66
|
try:
|
|
67
67
|
# Initialize LSP
|
|
68
|
-
if not lsp.initialize(os.path.
|
|
68
|
+
if not lsp.initialize(os.path.abspath(os.getcwd())):
|
|
69
69
|
return {
|
|
70
70
|
"success": False,
|
|
71
71
|
"stderr": "LSP initialization failed",
|
|
@@ -131,4 +131,4 @@ class LSPFindDefinitionTool:
|
|
|
131
131
|
}
|
|
132
132
|
finally:
|
|
133
133
|
if lsp:
|
|
134
|
-
lsp.shutdown()
|
|
134
|
+
lsp.shutdown()
|
|
@@ -65,7 +65,7 @@ class LSPFindReferencesTool:
|
|
|
65
65
|
|
|
66
66
|
try:
|
|
67
67
|
# Initialize LSP
|
|
68
|
-
if not lsp.initialize(os.path.
|
|
68
|
+
if not lsp.initialize(os.path.abspath(os.getcwd())):
|
|
69
69
|
return {
|
|
70
70
|
"success": False,
|
|
71
71
|
"stderr": "LSP initialization failed",
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from typing import Dict, Any
|
|
3
3
|
from jarvis.jarvis_lsp.registry import LSPRegistry
|
|
4
|
-
|
|
5
4
|
class LSPGetDiagnosticsTool:
|
|
6
5
|
"""Tool for getting diagnostics (errors, warnings) from code using LSP."""
|
|
7
6
|
|
|
7
|
+
# 工具名称
|
|
8
8
|
name = "lsp_get_diagnostics"
|
|
9
|
+
# 工具描述
|
|
9
10
|
description = "Get diagnostic information (errors, warnings) from code files"
|
|
11
|
+
# 工具参数定义
|
|
10
12
|
parameters = {
|
|
11
13
|
"file_path": "Path to the file to analyze",
|
|
12
14
|
"language": f"Programming language of the file ({', '.join(LSPRegistry.get_global_lsp_registry().get_supported_languages())})"
|
|
@@ -14,16 +16,16 @@ class LSPGetDiagnosticsTool:
|
|
|
14
16
|
|
|
15
17
|
@staticmethod
|
|
16
18
|
def check() -> bool:
|
|
17
|
-
"""
|
|
19
|
+
"""检查是否有可用的LSP服务器"""
|
|
18
20
|
registry = LSPRegistry.get_global_lsp_registry()
|
|
19
21
|
return len(registry.get_supported_languages()) > 0
|
|
20
22
|
|
|
21
23
|
def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
22
|
-
"""
|
|
24
|
+
"""执行工具的主要逻辑"""
|
|
23
25
|
file_path = args.get("file_path", "")
|
|
24
26
|
language = args.get("language", "")
|
|
25
27
|
|
|
26
|
-
#
|
|
28
|
+
# 验证输入参数
|
|
27
29
|
if not all([file_path, language]):
|
|
28
30
|
return {
|
|
29
31
|
"success": False,
|
|
@@ -31,6 +33,7 @@ class LSPGetDiagnosticsTool:
|
|
|
31
33
|
"stdout": ""
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
# 检查文件是否存在
|
|
34
37
|
if not os.path.exists(file_path):
|
|
35
38
|
return {
|
|
36
39
|
"success": False,
|
|
@@ -38,10 +41,11 @@ class LSPGetDiagnosticsTool:
|
|
|
38
41
|
"stdout": ""
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
#
|
|
44
|
+
# 获取LSP实例
|
|
42
45
|
registry = LSPRegistry.get_global_lsp_registry()
|
|
43
46
|
lsp = registry.create_lsp(language)
|
|
44
47
|
|
|
48
|
+
# 检查语言是否支持
|
|
45
49
|
if not lsp:
|
|
46
50
|
return {
|
|
47
51
|
"success": False,
|
|
@@ -50,17 +54,18 @@ class LSPGetDiagnosticsTool:
|
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
try:
|
|
53
|
-
#
|
|
54
|
-
if not lsp.initialize(os.path.
|
|
57
|
+
# 初始化LSP
|
|
58
|
+
if not lsp.initialize(os.path.abspath(os.getcwd())):
|
|
55
59
|
return {
|
|
56
60
|
"success": False,
|
|
57
61
|
"stderr": "LSP initialization failed",
|
|
58
62
|
"stdout": ""
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
#
|
|
65
|
+
# 获取诊断信息
|
|
62
66
|
diagnostics = lsp.get_diagnostics(file_path)
|
|
63
67
|
|
|
68
|
+
# 如果没有诊断信息
|
|
64
69
|
if not diagnostics:
|
|
65
70
|
return {
|
|
66
71
|
"success": True,
|
|
@@ -68,16 +73,18 @@ class LSPGetDiagnosticsTool:
|
|
|
68
73
|
"stderr": ""
|
|
69
74
|
}
|
|
70
75
|
|
|
71
|
-
#
|
|
76
|
+
# 格式化输出
|
|
72
77
|
output = ["Diagnostics:"]
|
|
78
|
+
# 严重程度映射
|
|
73
79
|
severity_map = {1: "Error", 2: "Warning", 3: "Info", 4: "Hint"}
|
|
74
80
|
|
|
75
|
-
#
|
|
81
|
+
# 按严重程度和行号排序诊断信息
|
|
76
82
|
sorted_diagnostics = sorted(
|
|
77
83
|
diagnostics,
|
|
78
84
|
key=lambda x: (x["severity"], x["range"]["start"]["line"])
|
|
79
85
|
)
|
|
80
86
|
|
|
87
|
+
# 处理每个诊断信息
|
|
81
88
|
for diag in sorted_diagnostics:
|
|
82
89
|
severity = severity_map.get(diag["severity"], "Unknown")
|
|
83
90
|
start = diag["range"]["start"]
|
|
@@ -90,7 +97,7 @@ class LSPGetDiagnosticsTool:
|
|
|
90
97
|
"-" * 60
|
|
91
98
|
])
|
|
92
99
|
|
|
93
|
-
#
|
|
100
|
+
# 处理相关附加信息
|
|
94
101
|
if diag.get("relatedInformation"):
|
|
95
102
|
output.append("Related information:")
|
|
96
103
|
for info in diag["relatedInformation"]:
|
|
@@ -117,5 +124,6 @@ class LSPGetDiagnosticsTool:
|
|
|
117
124
|
"stdout": ""
|
|
118
125
|
}
|
|
119
126
|
finally:
|
|
127
|
+
# 确保关闭LSP连接
|
|
120
128
|
if lsp:
|
|
121
129
|
lsp.shutdown()
|
|
@@ -50,7 +50,7 @@ class LSPGetDocumentSymbolsTool:
|
|
|
50
50
|
|
|
51
51
|
try:
|
|
52
52
|
# Initialize LSP
|
|
53
|
-
if not lsp.initialize(os.path.
|
|
53
|
+
if not lsp.initialize(os.path.abspath(os.getcwd())):
|
|
54
54
|
return {
|
|
55
55
|
"success": False,
|
|
56
56
|
"stderr": "LSP initialization failed",
|
|
@@ -3,15 +3,15 @@ from typing import Dict, Any
|
|
|
3
3
|
from jarvis.jarvis_lsp.registry import LSPRegistry
|
|
4
4
|
|
|
5
5
|
class LSPPrepareRenameTool:
|
|
6
|
-
"""
|
|
6
|
+
"""使用LSP检查符号是否可以安全重命名并显示所有受影响位置的工具"""
|
|
7
7
|
|
|
8
8
|
name = "lsp_prepare_rename"
|
|
9
|
-
description = "
|
|
9
|
+
description = "检查符号是否可以安全重命名,并显示所有受影响的位置"
|
|
10
10
|
parameters = {
|
|
11
|
-
"file_path": "
|
|
12
|
-
"line": "
|
|
13
|
-
"character": "
|
|
14
|
-
"language": f"
|
|
11
|
+
"file_path": "包含符号的文件路径",
|
|
12
|
+
"line": "符号所在的行号(从0开始)",
|
|
13
|
+
"character": "符号在行中的字符位置",
|
|
14
|
+
"language": f"文件的编程语言({', '.join(LSPRegistry.get_global_lsp_registry().get_supported_languages())})"
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
@staticmethod
|
|
@@ -65,7 +65,7 @@ class LSPPrepareRenameTool:
|
|
|
65
65
|
|
|
66
66
|
try:
|
|
67
67
|
# Initialize LSP
|
|
68
|
-
if not lsp.initialize(os.path.
|
|
68
|
+
if not lsp.initialize(os.path.abspath(os.getcwd())):
|
|
69
69
|
return {
|
|
70
70
|
"success": False,
|
|
71
71
|
"stderr": "LSP initialization failed",
|
|
@@ -127,4 +127,4 @@ class LSPPrepareRenameTool:
|
|
|
127
127
|
}
|
|
128
128
|
finally:
|
|
129
129
|
if lsp:
|
|
130
|
-
lsp.shutdown()
|
|
130
|
+
lsp.shutdown()
|
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import yaml
|
|
3
3
|
from typing import Dict, Optional, Any
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
from jarvis.jarvis_utils.config import is_use_methodology
|
|
6
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
7
|
+
|
|
5
8
|
|
|
6
9
|
|
|
7
10
|
class MethodologyTool:
|
|
8
|
-
"""
|
|
11
|
+
"""经验管理工具"""
|
|
9
12
|
|
|
10
13
|
name = "methodology"
|
|
11
|
-
description = "
|
|
14
|
+
description = "管理问题解决方法论,支持添加、更新和删除操作"
|
|
12
15
|
parameters = {
|
|
13
16
|
"type": "object",
|
|
14
17
|
"properties": {
|
|
15
18
|
"operation": {
|
|
16
19
|
"type": "string",
|
|
17
|
-
"description": "
|
|
20
|
+
"description": "操作类型(delete/update/add)",
|
|
18
21
|
"enum": ["delete", "update", "add"]
|
|
19
22
|
},
|
|
20
23
|
"problem_type": {
|
|
21
24
|
"type": "string",
|
|
22
|
-
"description": "
|
|
25
|
+
"description": "问题类型,例如:code_review, bug_fix 等"
|
|
23
26
|
},
|
|
24
27
|
"content": {
|
|
25
28
|
"type": "string",
|
|
26
|
-
"description": "
|
|
29
|
+
"description": "方法论内容(更新和添加时必填)",
|
|
27
30
|
"optional": True
|
|
28
31
|
}
|
|
29
32
|
},
|
|
@@ -57,7 +60,7 @@ class MethodologyTool:
|
|
|
57
60
|
except Exception as e:
|
|
58
61
|
PrettyOutput.print(f"加载方法论失败: {str(e)}", OutputType.ERROR)
|
|
59
62
|
return {}
|
|
60
|
-
|
|
63
|
+
|
|
61
64
|
def _save_methodologies(self, methodologies: Dict):
|
|
62
65
|
"""Save all methodologies"""
|
|
63
66
|
try:
|
jarvis/jarvis_tools/rag.py
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
from typing import Dict, Any
|
|
2
2
|
import os
|
|
3
|
-
from jarvis.jarvis_utils import OutputType, PrettyOutput, dont_use_local_model
|
|
4
3
|
from jarvis.jarvis_rag.main import RAGTool as RAGCore
|
|
4
|
+
from jarvis.jarvis_utils.config import dont_use_local_model
|
|
5
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
5
6
|
|
|
6
7
|
class RAGTool:
|
|
7
8
|
name = "rag"
|
|
8
|
-
description = "
|
|
9
|
+
description = "基于文档目录进行问答,支持多种文档格式(txt、pdf、docx等)"
|
|
9
10
|
parameters = {
|
|
10
11
|
"type": "object",
|
|
11
12
|
"properties": {
|
|
12
13
|
"dir": {
|
|
13
14
|
"type": "string",
|
|
14
|
-
"description": "
|
|
15
|
+
"description": "文档目录路径,支持相对路径和绝对路径"
|
|
15
16
|
},
|
|
16
17
|
"question": {
|
|
17
18
|
"type": "string",
|
|
18
|
-
"description": "
|
|
19
|
+
"description": "要询问的问题"
|
|
19
20
|
},
|
|
20
21
|
"rebuild_index": {
|
|
21
22
|
"type": "boolean",
|
|
22
|
-
"description": "
|
|
23
|
+
"description": "是否重建索引",
|
|
23
24
|
"default": False
|
|
24
25
|
}
|
|
25
26
|
},
|
|
@@ -48,25 +49,28 @@ class RAGTool:
|
|
|
48
49
|
return self.rag_instances[dir_path]
|
|
49
50
|
|
|
50
51
|
def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
51
|
-
"""
|
|
52
|
+
"""执行文档问答
|
|
52
53
|
|
|
53
54
|
Args:
|
|
54
|
-
args:
|
|
55
|
-
- dir:
|
|
56
|
-
- question:
|
|
57
|
-
- rebuild_index:
|
|
55
|
+
args: 包含参数的字典
|
|
56
|
+
- dir: 文档目录路径
|
|
57
|
+
- question: 要询问的问题
|
|
58
|
+
- rebuild_index: 是否重建索引
|
|
58
59
|
|
|
59
60
|
Returns:
|
|
60
|
-
Dict[str, Any]:
|
|
61
|
+
Dict[str, Any]: 执行结果,包含以下字段:
|
|
62
|
+
- success: 布尔值,表示操作是否成功
|
|
63
|
+
- stdout: 如果成功,包含问题的答案
|
|
64
|
+
- stderr: 如果失败,包含错误信息
|
|
61
65
|
"""
|
|
62
66
|
try:
|
|
63
|
-
#
|
|
64
|
-
dir_path = os.path.expanduser(args["dir"])
|
|
65
|
-
dir_path = os.path.abspath(dir_path)
|
|
67
|
+
# 获取参数
|
|
68
|
+
dir_path = os.path.expanduser(args["dir"])
|
|
69
|
+
dir_path = os.path.abspath(dir_path)
|
|
66
70
|
question = args["question"]
|
|
67
71
|
rebuild_index = args.get("rebuild_index", False)
|
|
68
72
|
|
|
69
|
-
#
|
|
73
|
+
# 检查目录是否存在
|
|
70
74
|
if not os.path.exists(dir_path):
|
|
71
75
|
return {
|
|
72
76
|
"success": False,
|
|
@@ -74,7 +78,7 @@ class RAGTool:
|
|
|
74
78
|
"stderr": f"Directory does not exist: {dir_path}"
|
|
75
79
|
}
|
|
76
80
|
|
|
77
|
-
#
|
|
81
|
+
# 检查路径是否为目录
|
|
78
82
|
if not os.path.isdir(dir_path):
|
|
79
83
|
return {
|
|
80
84
|
"success": False,
|
|
@@ -82,18 +86,19 @@ class RAGTool:
|
|
|
82
86
|
"stderr": f"The path is not a directory: {dir_path}"
|
|
83
87
|
}
|
|
84
88
|
|
|
85
|
-
#
|
|
89
|
+
# 获取RAG实例
|
|
86
90
|
rag = self._get_rag_instance(dir_path)
|
|
87
91
|
|
|
88
|
-
#
|
|
92
|
+
# 如果需要重建索引或索引不存在
|
|
89
93
|
if rebuild_index or not rag.is_index_built():
|
|
90
94
|
PrettyOutput.print("正在构建文档索引...", OutputType.INFO)
|
|
91
95
|
rag.build_index(dir_path)
|
|
92
96
|
|
|
93
|
-
#
|
|
97
|
+
# 执行问答
|
|
94
98
|
PrettyOutput.print(f"问题: {question}", OutputType.INFO)
|
|
95
99
|
response = rag.ask(question)
|
|
96
100
|
|
|
101
|
+
# 处理未找到相关文档的情况
|
|
97
102
|
if response is None:
|
|
98
103
|
return {
|
|
99
104
|
"success": False,
|
|
@@ -101,6 +106,7 @@ class RAGTool:
|
|
|
101
106
|
"stderr": "Failed to get answer, possibly no relevant documents found"
|
|
102
107
|
}
|
|
103
108
|
|
|
109
|
+
# 返回成功响应
|
|
104
110
|
return {
|
|
105
111
|
"success": True,
|
|
106
112
|
"stdout": response,
|
|
@@ -108,6 +114,7 @@ class RAGTool:
|
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
except Exception as e:
|
|
117
|
+
# 处理任何意外错误
|
|
111
118
|
PrettyOutput.print(f"文档问答失败:{str(e)}", OutputType.ERROR)
|
|
112
119
|
return {
|
|
113
120
|
"success": False,
|
|
@@ -138,4 +145,4 @@ def main():
|
|
|
138
145
|
PrettyOutput.print(result["stderr"], OutputType.WARNING)
|
|
139
146
|
|
|
140
147
|
if __name__ == "__main__":
|
|
141
|
-
main()
|
|
148
|
+
main()
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
from typing import Dict, Any
|
|
2
2
|
import requests
|
|
3
3
|
from bs4 import BeautifulSoup
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
5
6
|
|
|
6
7
|
class WebpageTool:
|
|
7
8
|
name = "read_webpage"
|
|
8
|
-
description = "
|
|
9
|
+
description = "读取网页内容,提取标题、文本和超链接"
|
|
9
10
|
parameters = {
|
|
10
11
|
"type": "object",
|
|
11
12
|
"properties": {
|
|
12
13
|
"url": {
|
|
13
14
|
"type": "string",
|
|
14
|
-
"description": "
|
|
15
|
+
"description": "要读取的网页URL"
|
|
15
16
|
}
|
|
16
17
|
},
|
|
17
18
|
"required": ["url"]
|