jarvis-ai-assistant 0.1.77__tar.gz → 0.1.78__tar.gz
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_ai_assistant-0.1.77/src/jarvis_ai_assistant.egg-info → jarvis_ai_assistant-0.1.78}/PKG-INFO +1 -1
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/pyproject.toml +1 -1
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/setup.py +1 -1
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/__init__.py +1 -1
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/agent.py +2 -3
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/jarvis_codebase/main.py +6 -26
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/jarvis_coder/main.py +0 -11
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/main.py +1 -16
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/models/registry.py +19 -14
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/rag/main.py +119 -36
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/tools/generator.py +1 -5
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/tools/search.py +1 -1
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/utils.py +3 -1
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78/src/jarvis_ai_assistant.egg-info}/PKG-INFO +1 -1
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/MANIFEST.in +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/README.md +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/setup.cfg +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/jarvis_codebase/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/jarvis_coder/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/models/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/models/ai8.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/models/base.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/models/kimi.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/models/openai.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/models/oyi.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/rag/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/tools/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/tools/base.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/tools/codebase_qa.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/tools/coder.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/tools/file_ops.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/tools/methodology.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/tools/registry.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/tools/shell.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/tools/sub_agent.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/tools/webpage.py +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis_ai_assistant.egg-info/SOURCES.txt +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis_ai_assistant.egg-info/dependency_links.txt +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis_ai_assistant.egg-info/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis_ai_assistant.egg-info/requires.txt +0 -0
- {jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis_ai_assistant.egg-info/top_level.txt +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "jarvis-ai-assistant"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.78"
|
|
8
8
|
description = "Jarvis: An AI assistant that uses tools to interact with the system"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [{ name = "Your Name", email = "your.email@example.com" }]
|
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name="jarvis-ai-assistant",
|
|
5
|
-
version="0.1.
|
|
5
|
+
version="0.1.78",
|
|
6
6
|
author="skyfire",
|
|
7
7
|
author_email="skyfireitdiy@hotmail.com",
|
|
8
8
|
description="An AI assistant that uses various tools to interact with the system",
|
|
@@ -24,7 +24,7 @@ class Agent:
|
|
|
24
24
|
name: Agent名称,默认为"Jarvis"
|
|
25
25
|
is_sub_agent: 是否为子Agent,默认为False
|
|
26
26
|
"""
|
|
27
|
-
self.model = PlatformRegistry.
|
|
27
|
+
self.model = PlatformRegistry.get_global_platform_registry().get_normal_platform()
|
|
28
28
|
self.tool_registry = ToolRegistry.get_global_tool_registry()
|
|
29
29
|
self.name = name
|
|
30
30
|
self.is_sub_agent = is_sub_agent
|
|
@@ -32,12 +32,11 @@ class Agent:
|
|
|
32
32
|
self.conversation_turns = 0
|
|
33
33
|
|
|
34
34
|
# 从环境变量加载嵌入模型配置
|
|
35
|
-
self.embedding_model_name = os.environ.get("JARVIS_EMBEDDING_MODEL", "BAAI/bge-large-zh-v1.5")
|
|
36
35
|
self.embedding_dimension = 1536 # Default for many embedding models
|
|
37
36
|
|
|
38
37
|
# 初始化嵌入模型
|
|
39
38
|
try:
|
|
40
|
-
self.embedding_model = load_embedding_model(
|
|
39
|
+
self.embedding_model = load_embedding_model()
|
|
41
40
|
|
|
42
41
|
# 预热模型并获取正确的维度
|
|
43
42
|
test_text = "这是一段测试文本,用于确保模型完全加载。"
|
{jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/jarvis_codebase/main.py
RENAMED
|
@@ -19,22 +19,6 @@ class CodeBase:
|
|
|
19
19
|
self.root_dir = root_dir
|
|
20
20
|
os.chdir(self.root_dir)
|
|
21
21
|
self.thread_count = int(os.environ.get("JARVIS_THREAD_COUNT") or 10)
|
|
22
|
-
self.cheap_platform = os.environ.get("JARVIS_CHEAP_PLATFORM") or os.environ.get("JARVIS_PLATFORM") or "kimi"
|
|
23
|
-
self.cheap_model = os.environ.get("JARVIS_CHEAP_MODEL") or os.environ.get("JARVIS_MODEL") or "kimi"
|
|
24
|
-
self.normal_platform = os.environ.get("JARVIS_PLATFORM") or "kimi"
|
|
25
|
-
self.codegen_platform = os.environ.get("JARVIS_CODEGEN_PLATFORM") or os.environ.get("JARVIS_PLATFORM") or "kimi"
|
|
26
|
-
self.codegen_model = os.environ.get("JARVIS_CODEGEN_MODEL") or os.environ.get("JARVIS_MODEL") or "kimi"
|
|
27
|
-
self.normal_model = os.environ.get("JARVIS_MODEL") or "kimi"
|
|
28
|
-
self.embedding_model_name = os.environ.get("JARVIS_EMBEDDING_MODEL") or "BAAI/bge-large-zh-v1.5"
|
|
29
|
-
if not self.cheap_platform or not self.cheap_model or not self.codegen_platform or not self.codegen_model or not self.embedding_model_name or not self.normal_platform or not self.normal_model:
|
|
30
|
-
raise ValueError("JARVIS_CHEAP_PLATFORM or JARVIS_CHEAP_MODEL or JARVIS_CODEGEN_PLATFORM or JARVIS_CODEGEN_MODEL or JARVIS_EMBEDDING_MODEL or JARVIS_PLATFORM or JARVIS_MODEL is not set")
|
|
31
|
-
|
|
32
|
-
PrettyOutput.print(f"廉价模型使用平台: {self.cheap_platform} 模型: {self.cheap_model}", output_type=OutputType.INFO)
|
|
33
|
-
PrettyOutput.print(f"代码生成模型使用平台: {self.codegen_platform} 模型: {self.codegen_model}", output_type=OutputType.INFO)
|
|
34
|
-
PrettyOutput.print(f"分析模型使用平台: {self.normal_platform} 模型: {self.normal_model}", output_type=OutputType.INFO)
|
|
35
|
-
PrettyOutput.print(f"嵌入模型: {self.embedding_model_name}", output_type=OutputType.INFO)
|
|
36
|
-
PrettyOutput.print(f"索引建立线程数: {self.thread_count}", output_type=OutputType.INFO)
|
|
37
|
-
PrettyOutput.print(f"检索算法:分层导航小世界算法", output_type=OutputType.INFO)
|
|
38
22
|
|
|
39
23
|
# 初始化数据目录
|
|
40
24
|
self.data_dir = os.path.join(self.root_dir, ".jarvis-codebase")
|
|
@@ -43,7 +27,7 @@ class CodeBase:
|
|
|
43
27
|
|
|
44
28
|
# 初始化嵌入模型,使用系统默认缓存目录
|
|
45
29
|
try:
|
|
46
|
-
self.embedding_model = load_embedding_model(
|
|
30
|
+
self.embedding_model = load_embedding_model()
|
|
47
31
|
|
|
48
32
|
# 强制完全加载所有模型组件
|
|
49
33
|
test_text = """
|
|
@@ -62,7 +46,7 @@ class CodeBase:
|
|
|
62
46
|
self.vector_dim = self.embedding_model.get_sentence_embedding_dimension()
|
|
63
47
|
|
|
64
48
|
self.git_file_list = self.get_git_file_list()
|
|
65
|
-
self.platform_registry = PlatformRegistry
|
|
49
|
+
self.platform_registry = PlatformRegistry.get_global_platform_registry()
|
|
66
50
|
|
|
67
51
|
# 初始化缓存和索引
|
|
68
52
|
self.cache_path = os.path.join(self.data_dir, "cache.pkl")
|
|
@@ -102,8 +86,7 @@ class CodeBase:
|
|
|
102
86
|
return False
|
|
103
87
|
|
|
104
88
|
def make_description(self, file_path: str) -> str:
|
|
105
|
-
model =
|
|
106
|
-
model.set_model_name(self.cheap_model)
|
|
89
|
+
model = PlatformRegistry.get_global_platform_registry().get_codegen_platform()
|
|
107
90
|
model.set_suppress_output(True)
|
|
108
91
|
content = open(file_path, "r", encoding="utf-8").read()
|
|
109
92
|
prompt = f"""请分析以下代码文件,并生成一个详细的描述。描述应该包含以下要点:
|
|
@@ -411,8 +394,7 @@ class CodeBase:
|
|
|
411
394
|
if not initial_results:
|
|
412
395
|
return []
|
|
413
396
|
|
|
414
|
-
model =
|
|
415
|
-
model.set_model_name(self.normal_model)
|
|
397
|
+
model = PlatformRegistry.get_global_platform_registry().get_normal_platform()
|
|
416
398
|
model.set_suppress_output(True)
|
|
417
399
|
|
|
418
400
|
try:
|
|
@@ -470,8 +452,7 @@ class CodeBase:
|
|
|
470
452
|
|
|
471
453
|
def search_similar(self, query: str, top_k: int = 20) -> List[Tuple[str, float, str]]:
|
|
472
454
|
"""搜索相似文件"""
|
|
473
|
-
model =
|
|
474
|
-
model.set_model_name(self.normal_model)
|
|
455
|
+
model = PlatformRegistry.get_global_platform_registry().get_normal_platform()
|
|
475
456
|
model.set_suppress_output(True)
|
|
476
457
|
|
|
477
458
|
try:
|
|
@@ -554,8 +535,7 @@ class CodeBase:
|
|
|
554
535
|
|
|
555
536
|
请用专业的语言回答用户的问题,如果给出的文件内容不足以回答用户的问题,请告诉用户,绝对不要胡编乱造。
|
|
556
537
|
"""
|
|
557
|
-
model =
|
|
558
|
-
model.set_model_name(self.codegen_model)
|
|
538
|
+
model = PlatformRegistry.get_global_platform_registry().get_codegen_platform()
|
|
559
539
|
try:
|
|
560
540
|
response = model.chat(prompt)
|
|
561
541
|
return response
|
|
@@ -21,13 +21,7 @@ index_lock = threading.Lock()
|
|
|
21
21
|
class JarvisCoder:
|
|
22
22
|
def __init__(self, root_dir: str, language: str):
|
|
23
23
|
"""初始化代码修改工具"""
|
|
24
|
-
|
|
25
|
-
self.platform = os.environ.get("JARVIS_CODEGEN_PLATFORM") or os.environ.get("JARVIS_PLATFORM")
|
|
26
|
-
self.model = os.environ.get("JARVIS_CODEGEN_MODEL") or os.environ.get("JARVIS_MODEL")
|
|
27
|
-
|
|
28
24
|
|
|
29
|
-
if not self.platform or not self.model:
|
|
30
|
-
raise ValueError("JARVIS_CODEGEN_PLATFORM or JARVIS_CODEGEN_MODEL is not set")
|
|
31
25
|
|
|
32
26
|
self.root_dir = find_git_root(root_dir)
|
|
33
27
|
if not self.root_dir:
|
|
@@ -486,8 +480,6 @@ def main():
|
|
|
486
480
|
load_env_from_file()
|
|
487
481
|
|
|
488
482
|
parser = argparse.ArgumentParser(description='代码修改工具')
|
|
489
|
-
parser.add_argument('-p', '--platform', help='AI平台名称', default=os.environ.get('JARVIS_CODEGEN_PLATFORM'))
|
|
490
|
-
parser.add_argument('-m', '--model', help='模型名称', default=os.environ.get('JARVIS_CODEGEN_MODEL'))
|
|
491
483
|
parser.add_argument('-d', '--dir', help='项目根目录', default=os.getcwd())
|
|
492
484
|
parser.add_argument('-l', '--language', help='编程语言', default="python")
|
|
493
485
|
args = parser.parse_args()
|
|
@@ -495,9 +487,6 @@ def main():
|
|
|
495
487
|
# 设置平台
|
|
496
488
|
if not args.platform:
|
|
497
489
|
print("错误: 未指定AI平台,请使用 -p 参数")
|
|
498
|
-
# 设置模型
|
|
499
|
-
if args.model:
|
|
500
|
-
os.environ['JARVIS_CODEGEN_MODEL'] = args.model
|
|
501
490
|
|
|
502
491
|
tool = JarvisCoder(args.dir, args.language)
|
|
503
492
|
|
|
@@ -104,31 +104,16 @@ def main():
|
|
|
104
104
|
parser = argparse.ArgumentParser(description='Jarvis AI 助手')
|
|
105
105
|
parser.add_argument('-f', '--files', nargs='*', help='要处理的文件列表')
|
|
106
106
|
parser.add_argument('--keep-history', action='store_true', help='保持聊天历史(不删除会话)')
|
|
107
|
-
parser.add_argument('-p', '--platform', default=os.getenv('JARVIS_PLATFORM') or 'kimi', help='选择AI平台')
|
|
108
|
-
parser.add_argument('-m', '--model', default=os.getenv('JARVIS_MODEL') or '', help='模型') # 用于指定使用的模型名称,默认使用环境变量或平台默认模型
|
|
109
107
|
args = parser.parse_args()
|
|
110
108
|
|
|
111
|
-
platform = args.platform if args.platform else os.getenv('JARVIS_PLATFORM')
|
|
112
|
-
|
|
113
|
-
if not platform:
|
|
114
|
-
PrettyOutput.print("未指定AI平台,请使用 -p 参数或者设置 JARVIS_PLATFORM 环境变量", OutputType.ERROR)
|
|
115
|
-
return 1
|
|
116
|
-
|
|
117
|
-
PlatformRegistry.get_global_platform_registry().set_global_platform_name(platform)
|
|
118
|
-
|
|
119
|
-
if args.model:
|
|
120
|
-
os.environ["JARVIS_MODEL"] = args.model
|
|
121
|
-
|
|
122
109
|
try:
|
|
123
110
|
# 获取全局模型实例
|
|
124
111
|
agent = Agent()
|
|
125
112
|
|
|
126
113
|
# 如果用户传入了模型参数,则更换当前模型为用户指定的模型
|
|
127
|
-
if args.model:
|
|
128
|
-
agent.model.set_model_name(args.model)
|
|
129
114
|
|
|
130
115
|
# 欢迎信息
|
|
131
|
-
PrettyOutput.print(f"Jarvis 已初始化 - With {
|
|
116
|
+
PrettyOutput.print(f"Jarvis 已初始化 - With {agent.model.name()}", OutputType.SYSTEM)
|
|
132
117
|
if args.keep_history:
|
|
133
118
|
PrettyOutput.print("已启用历史保留模式", OutputType.INFO)
|
|
134
119
|
|
|
@@ -152,14 +152,26 @@ class PlatformRegistry:
|
|
|
152
152
|
"""
|
|
153
153
|
self.platforms: Dict[str, Type[BasePlatform]] = {}
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
"""
|
|
158
|
-
platform =
|
|
159
|
-
|
|
160
|
-
|
|
155
|
+
def get_normal_platform(self) -> BasePlatform:
|
|
156
|
+
platform_name = os.environ.get("JARVIS_PLATFORM", "kimi")
|
|
157
|
+
model_name = os.environ.get("JARVIS_MODEL", "kimi")
|
|
158
|
+
platform = self.create_platform(platform_name)
|
|
159
|
+
platform.set_model_name(model_name)
|
|
160
|
+
return platform
|
|
161
|
+
|
|
162
|
+
def get_codegen_platform(self) -> BasePlatform:
|
|
163
|
+
platform_name = os.environ.get("JARVIS_CODEGEN_PLATFORM", os.environ.get("JARVIS_PLATFORM", "kimi"))
|
|
164
|
+
model_name = os.environ.get("JARVIS_CODEGEN_MODEL", os.environ.get("JARVIS_MODEL", "kimi"))
|
|
165
|
+
platform = self.create_platform(platform_name)
|
|
166
|
+
platform.set_model_name(model_name)
|
|
167
|
+
return platform
|
|
168
|
+
|
|
169
|
+
def get_cheap_platform(self) -> BasePlatform:
|
|
170
|
+
platform_name = os.environ.get("JARVIS_CHEAP_PLATFORM", os.environ.get("JARVIS_PLATFORM", "kimi"))
|
|
171
|
+
model_name = os.environ.get("JARVIS_CHEAP_MODEL", os.environ.get("JARVIS_MODEL", "kimi"))
|
|
172
|
+
platform = self.create_platform(platform_name)
|
|
173
|
+
platform.set_model_name(model_name)
|
|
161
174
|
return platform
|
|
162
|
-
|
|
163
175
|
|
|
164
176
|
def register_platform(self, name: str, platform_class: Type[BasePlatform]):
|
|
165
177
|
"""注册平台类
|
|
@@ -195,10 +207,3 @@ class PlatformRegistry:
|
|
|
195
207
|
"""获取可用平台列表"""
|
|
196
208
|
return list(self.platforms.keys())
|
|
197
209
|
|
|
198
|
-
def set_global_platform_name(self, platform_name: str):
|
|
199
|
-
"""设置全局平台"""
|
|
200
|
-
PlatformRegistry.global_platform_name = platform_name
|
|
201
|
-
|
|
202
|
-
def get_global_platform_name(self) -> str:
|
|
203
|
-
"""获取全局平台名称"""
|
|
204
|
-
return PlatformRegistry.global_platform_name
|
|
@@ -13,6 +13,7 @@ from tqdm import tqdm
|
|
|
13
13
|
import fitz # PyMuPDF for PDF files
|
|
14
14
|
from docx import Document as DocxDocument # python-docx for DOCX files
|
|
15
15
|
from pathlib import Path
|
|
16
|
+
from jarvis.models.registry import PlatformRegistry
|
|
16
17
|
|
|
17
18
|
@dataclass
|
|
18
19
|
class Document:
|
|
@@ -140,7 +141,6 @@ class RAGTool:
|
|
|
140
141
|
# 初始化配置
|
|
141
142
|
self.min_paragraph_length = int(os.environ.get("JARVIS_MIN_PARAGRAPH_LENGTH", "50")) # 最小段落长度
|
|
142
143
|
self.max_paragraph_length = int(os.environ.get("JARVIS_MAX_PARAGRAPH_LENGTH", "1000")) # 最大段落长度
|
|
143
|
-
self.embedding_model_name = os.environ.get("JARVIS_EMBEDDING_MODEL", "BAAI/bge-large-zh-v1.5")
|
|
144
144
|
|
|
145
145
|
# 初始化数据目录
|
|
146
146
|
self.data_dir = os.path.join(self.root_dir, ".jarvis-rag")
|
|
@@ -149,7 +149,7 @@ class RAGTool:
|
|
|
149
149
|
|
|
150
150
|
# 初始化嵌入模型
|
|
151
151
|
try:
|
|
152
|
-
self.embedding_model = load_embedding_model(
|
|
152
|
+
self.embedding_model = load_embedding_model()
|
|
153
153
|
self.vector_dim = self.embedding_model.get_sentence_embedding_dimension()
|
|
154
154
|
PrettyOutput.print("模型加载完成", output_type=OutputType.SUCCESS)
|
|
155
155
|
except Exception as e:
|
|
@@ -363,11 +363,11 @@ class RAGTool:
|
|
|
363
363
|
output_type=OutputType.ERROR)
|
|
364
364
|
return []
|
|
365
365
|
|
|
366
|
-
def build_index(self):
|
|
366
|
+
def build_index(self, dir: str):
|
|
367
367
|
"""构建文档索引"""
|
|
368
368
|
# 获取所有文件
|
|
369
369
|
all_files = []
|
|
370
|
-
for root, _, files in os.walk(
|
|
370
|
+
for root, _, files in os.walk(dir):
|
|
371
371
|
if any(ignored in root for ignored in ['.jarvis-rag', '.git', '__pycache__', 'node_modules']):
|
|
372
372
|
continue
|
|
373
373
|
for file in files:
|
|
@@ -431,8 +431,73 @@ class RAGTool:
|
|
|
431
431
|
|
|
432
432
|
return results
|
|
433
433
|
|
|
434
|
+
def is_index_built(self):
|
|
435
|
+
"""检查索引是否已构建"""
|
|
436
|
+
return self.index is not None
|
|
437
|
+
|
|
438
|
+
def query(self, query: str) -> List[Document]:
|
|
439
|
+
"""查询相关文档
|
|
440
|
+
|
|
441
|
+
Args:
|
|
442
|
+
query: 查询文本
|
|
443
|
+
|
|
444
|
+
Returns:
|
|
445
|
+
相关文档列表
|
|
446
|
+
"""
|
|
447
|
+
if not self.is_index_built():
|
|
448
|
+
raise ValueError("索引未构建,请先调用build_index()")
|
|
449
|
+
|
|
450
|
+
results = self.search(query)
|
|
451
|
+
return [doc for doc, _ in results]
|
|
452
|
+
|
|
453
|
+
def ask(self, question: str) -> Optional[str]:
|
|
454
|
+
"""询问关于文档的问题
|
|
455
|
+
|
|
456
|
+
Args:
|
|
457
|
+
question: 用户问题
|
|
458
|
+
|
|
459
|
+
Returns:
|
|
460
|
+
模型回答,如果失败则返回 None
|
|
461
|
+
"""
|
|
462
|
+
try:
|
|
463
|
+
# 搜索相关文档片段
|
|
464
|
+
results = self.query(question)
|
|
465
|
+
if not results:
|
|
466
|
+
return None
|
|
467
|
+
|
|
468
|
+
# 构建上下文
|
|
469
|
+
context = []
|
|
470
|
+
for doc in results:
|
|
471
|
+
context.append(f"""
|
|
472
|
+
来源文件: {doc.metadata['file_path']}
|
|
473
|
+
片段位置: {doc.metadata['chunk_index'] + 1}/{doc.metadata['total_chunks']}
|
|
474
|
+
内容:
|
|
475
|
+
{doc.content}
|
|
476
|
+
---
|
|
477
|
+
""")
|
|
478
|
+
|
|
479
|
+
# 构建提示词
|
|
480
|
+
prompt = f"""请基于以下文档片段回答用户的问题。如果文档片段中的信息不足以完整回答问题,请明确指出。
|
|
481
|
+
|
|
482
|
+
用户问题: {question}
|
|
483
|
+
|
|
484
|
+
相关文档片段:
|
|
485
|
+
{''.join(context)}
|
|
486
|
+
|
|
487
|
+
请提供准确、简洁的回答,并在适当时引用具体的文档来源。
|
|
488
|
+
"""
|
|
489
|
+
# 获取模型实例并生成回答
|
|
490
|
+
model = PlatformRegistry.get_global_platform_registry().get_normal_platform()
|
|
491
|
+
response = model.chat(prompt)
|
|
492
|
+
|
|
493
|
+
return response
|
|
494
|
+
|
|
495
|
+
except Exception as e:
|
|
496
|
+
PrettyOutput.print(f"问答失败: {str(e)}", output_type=OutputType.ERROR)
|
|
497
|
+
return None
|
|
498
|
+
|
|
434
499
|
def main():
|
|
435
|
-
"""
|
|
500
|
+
"""主函数"""
|
|
436
501
|
import argparse
|
|
437
502
|
import sys
|
|
438
503
|
|
|
@@ -442,39 +507,57 @@ def main():
|
|
|
442
507
|
sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict')
|
|
443
508
|
sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict')
|
|
444
509
|
|
|
445
|
-
parser = argparse.ArgumentParser(description='
|
|
446
|
-
parser.add_argument('--dir', type=str,
|
|
447
|
-
parser.add_argument('--build', action='store_true', help='
|
|
448
|
-
parser.add_argument('--
|
|
449
|
-
parser.add_argument('--
|
|
450
|
-
|
|
510
|
+
parser = argparse.ArgumentParser(description='文档检索和分析工具')
|
|
511
|
+
parser.add_argument('--dir', type=str, help='要处理的文档目录')
|
|
512
|
+
parser.add_argument('--build', action='store_true', help='构建文档索引')
|
|
513
|
+
parser.add_argument('--search', type=str, help='搜索文档内容')
|
|
514
|
+
parser.add_argument('--ask', type=str, help='询问关于文档的问题')
|
|
451
515
|
args = parser.parse_args()
|
|
452
|
-
|
|
516
|
+
|
|
453
517
|
try:
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
518
|
+
current_dir = find_git_root()
|
|
519
|
+
rag = RAGTool(current_dir)
|
|
520
|
+
|
|
521
|
+
if args.dir and args.build:
|
|
522
|
+
PrettyOutput.print(f"正在处理目录: {args.dir}", output_type=OutputType.INFO)
|
|
523
|
+
rag.build_index(args.dir)
|
|
524
|
+
return 0
|
|
525
|
+
|
|
526
|
+
if args.search or args.ask:
|
|
527
|
+
if not rag.is_index_built():
|
|
528
|
+
PrettyOutput.print("索引尚未构建,请先使用 --dir 和 --build 参数构建索引", output_type=OutputType.WARNING)
|
|
529
|
+
return 1
|
|
530
|
+
|
|
531
|
+
if args.search:
|
|
532
|
+
results = rag.query(args.search)
|
|
533
|
+
if not results:
|
|
534
|
+
PrettyOutput.print("未找到相关内容", output_type=OutputType.WARNING)
|
|
535
|
+
return 1
|
|
536
|
+
|
|
537
|
+
for doc in results:
|
|
538
|
+
PrettyOutput.print(f"\n文件: {doc.metadata['file_path']}", output_type=OutputType.INFO)
|
|
539
|
+
PrettyOutput.print(f"片段 {doc.metadata['chunk_index'] + 1}/{doc.metadata['total_chunks']}",
|
|
540
|
+
output_type=OutputType.INFO)
|
|
541
|
+
PrettyOutput.print("\n内容:", output_type=OutputType.INFO)
|
|
542
|
+
content = doc.content.encode('utf-8', errors='replace').decode('utf-8')
|
|
543
|
+
PrettyOutput.print(content, output_type=OutputType.INFO)
|
|
544
|
+
return 0
|
|
545
|
+
|
|
546
|
+
if args.ask:
|
|
547
|
+
# 调用 ask 方法
|
|
548
|
+
response = rag.ask(args.ask)
|
|
549
|
+
if not response:
|
|
550
|
+
PrettyOutput.print("未能获取答案", output_type=OutputType.WARNING)
|
|
551
|
+
return 1
|
|
552
|
+
|
|
553
|
+
# 显示回答
|
|
554
|
+
PrettyOutput.print("\n回答:", output_type=OutputType.INFO)
|
|
555
|
+
PrettyOutput.print(response, output_type=OutputType.INFO)
|
|
556
|
+
return 0
|
|
557
|
+
|
|
558
|
+
PrettyOutput.print("请指定操作参数。使用 -h 查看帮助。", output_type=OutputType.WARNING)
|
|
559
|
+
return 1
|
|
560
|
+
|
|
478
561
|
except Exception as e:
|
|
479
562
|
PrettyOutput.print(f"执行失败: {str(e)}", output_type=OutputType.ERROR)
|
|
480
563
|
return 1
|
|
@@ -42,11 +42,7 @@ class ToolGeneratorTool:
|
|
|
42
42
|
|
|
43
43
|
def _generate_tool_code(self, tool_name: str, class_name: str, description: str, parameters: Dict) -> str:
|
|
44
44
|
"""使用大模型生成工具代码"""
|
|
45
|
-
|
|
46
|
-
model = PlatformRegistry.create_platform(platform_name)
|
|
47
|
-
model_name = os.getenv("JARVIS_CODEGEN_MODEL")
|
|
48
|
-
if model_name:
|
|
49
|
-
model.set_model_name(model_name)
|
|
45
|
+
model = PlatformRegistry.get_global_platform_registry().get_codegen_platform()
|
|
50
46
|
|
|
51
47
|
prompt = f"""请生成一个Python工具类的代码,要求如下,除了代码,不要输出任何内容:
|
|
52
48
|
|
|
@@ -86,7 +86,7 @@ class SearchTool:
|
|
|
86
86
|
|
|
87
87
|
def __init__(self):
|
|
88
88
|
"""初始化搜索工具,需要传入语言模型用于信息提取"""
|
|
89
|
-
self.model = PlatformRegistry.get_global_platform_registry().
|
|
89
|
+
self.model = PlatformRegistry.get_global_platform_registry().get_normal_platform()
|
|
90
90
|
self.webpage_tool = WebpageTool()
|
|
91
91
|
|
|
92
92
|
def _search(self, query: str, max_results: int) -> List[Dict]:
|
|
@@ -209,8 +209,9 @@ def find_git_root(dir="."):
|
|
|
209
209
|
os.chdir(curr_dir)
|
|
210
210
|
return ret
|
|
211
211
|
|
|
212
|
-
def load_embedding_model(
|
|
212
|
+
def load_embedding_model():
|
|
213
213
|
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
|
214
|
+
model_name = os.environ.get("JARVIS_EMBEDDING_MODEL", "BAAI/bge-large-zh-v1.5")
|
|
214
215
|
PrettyOutput.print(f"正在加载嵌入模型: {model_name}...", OutputType.INFO)
|
|
215
216
|
try:
|
|
216
217
|
# 首先尝试离线加载
|
|
@@ -230,4 +231,5 @@ def load_embedding_model(model_name: str):
|
|
|
230
231
|
cache_folder=os.path.expanduser("~/.cache/huggingface/hub")
|
|
231
232
|
)
|
|
232
233
|
PrettyOutput.print("模型下载并加载成功", OutputType.SUCCESS)
|
|
234
|
+
|
|
233
235
|
return embedding_model
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/jarvis_codebase/__init__.py
RENAMED
|
File without changes
|
{jarvis_ai_assistant-0.1.77 → jarvis_ai_assistant-0.1.78}/src/jarvis/jarvis_coder/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|