jarvis-ai-assistant 0.1.74__tar.gz → 0.1.75__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.
Potentially problematic release.
This version of jarvis-ai-assistant might be problematic. Click here for more details.
- {jarvis_ai_assistant-0.1.74/src/jarvis_ai_assistant.egg-info → jarvis_ai_assistant-0.1.75}/PKG-INFO +1 -1
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/pyproject.toml +1 -1
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/setup.py +1 -1
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/__init__.py +1 -1
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/agent.py +103 -8
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75/src/jarvis_ai_assistant.egg-info}/PKG-INFO +1 -1
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/MANIFEST.in +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/README.md +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/setup.cfg +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/jarvis_codebase/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/jarvis_codebase/main.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/jarvis_coder/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/jarvis_coder/main.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/main.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/models/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/models/ai8.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/models/base.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/models/kimi.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/models/openai.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/models/oyi.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/models/registry.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/tools/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/tools/base.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/tools/codebase_qa.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/tools/coder.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/tools/file_ops.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/tools/generator.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/tools/methodology.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/tools/registry.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/tools/search.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/tools/shell.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/tools/sub_agent.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/tools/webpage.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/utils.py +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis_ai_assistant.egg-info/SOURCES.txt +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis_ai_assistant.egg-info/dependency_links.txt +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis_ai_assistant.egg-info/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis_ai_assistant.egg-info/requires.txt +0 -0
- {jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/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.75"
|
|
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.75",
|
|
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",
|
|
@@ -2,6 +2,9 @@ import time
|
|
|
2
2
|
from typing import Dict, List, Optional
|
|
3
3
|
|
|
4
4
|
import yaml
|
|
5
|
+
import numpy as np
|
|
6
|
+
import faiss
|
|
7
|
+
import json
|
|
5
8
|
|
|
6
9
|
from .models.registry import PlatformRegistry
|
|
7
10
|
from .tools import ToolRegistry
|
|
@@ -9,6 +12,7 @@ from .utils import PrettyOutput, OutputType, get_multiline_input, while_success
|
|
|
9
12
|
import os
|
|
10
13
|
from datetime import datetime
|
|
11
14
|
from prompt_toolkit import prompt
|
|
15
|
+
from sentence_transformers import SentenceTransformer
|
|
12
16
|
|
|
13
17
|
class Agent:
|
|
14
18
|
def __init__(self, name: str = "Jarvis", is_sub_agent: bool = False):
|
|
@@ -26,7 +30,37 @@ class Agent:
|
|
|
26
30
|
self.is_sub_agent = is_sub_agent
|
|
27
31
|
self.prompt = ""
|
|
28
32
|
self.conversation_turns = 0
|
|
29
|
-
|
|
33
|
+
|
|
34
|
+
# 从环境变量加载嵌入模型配置
|
|
35
|
+
self.embedding_model_name = os.environ.get("JARVIS_EMBEDDING_MODEL", "BAAI/bge-large-zh-v1.5")
|
|
36
|
+
self.embedding_dimension = 1536 # Default for many embedding models
|
|
37
|
+
|
|
38
|
+
# 初始化嵌入模型
|
|
39
|
+
try:
|
|
40
|
+
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
|
41
|
+
PrettyOutput.print(f"正在加载嵌入模型: {self.embedding_model_name}...", OutputType.INFO)
|
|
42
|
+
self.embedding_model = SentenceTransformer(self.embedding_model_name)
|
|
43
|
+
|
|
44
|
+
# 预热模型并获取正确的维度
|
|
45
|
+
test_text = "这是一段测试文本,用于确保模型完全加载。"
|
|
46
|
+
test_embedding = self.embedding_model.encode(test_text,
|
|
47
|
+
convert_to_tensor=True,
|
|
48
|
+
normalize_embeddings=True)
|
|
49
|
+
self.embedding_dimension = len(test_embedding)
|
|
50
|
+
PrettyOutput.print("嵌入模型加载完成", OutputType.SUCCESS)
|
|
51
|
+
|
|
52
|
+
# 初始化HNSW索引(使用正确的维度)
|
|
53
|
+
hnsw_index = faiss.IndexHNSWFlat(self.embedding_dimension, 16)
|
|
54
|
+
hnsw_index.hnsw.efConstruction = 40
|
|
55
|
+
hnsw_index.hnsw.efSearch = 16
|
|
56
|
+
self.methodology_index = faiss.IndexIDMap(hnsw_index)
|
|
57
|
+
|
|
58
|
+
except Exception as e:
|
|
59
|
+
PrettyOutput.print(f"加载嵌入模型失败: {str(e)}", OutputType.ERROR)
|
|
60
|
+
raise
|
|
61
|
+
|
|
62
|
+
# 初始化方法论相关属性
|
|
63
|
+
self.methodology_data = []
|
|
30
64
|
|
|
31
65
|
@staticmethod
|
|
32
66
|
def extract_tool_calls(content: str) -> List[Dict]:
|
|
@@ -87,16 +121,77 @@ class Agent:
|
|
|
87
121
|
sleep_time = 30
|
|
88
122
|
continue
|
|
89
123
|
|
|
124
|
+
def _create_methodology_embedding(self, methodology_text: str) -> np.ndarray:
|
|
125
|
+
"""为方法论文本创建嵌入向量"""
|
|
126
|
+
try:
|
|
127
|
+
# 对长文本进行截断
|
|
128
|
+
max_length = 512
|
|
129
|
+
text = ' '.join(methodology_text.split()[:max_length])
|
|
130
|
+
|
|
131
|
+
# 使用sentence_transformers模型获取嵌入向量
|
|
132
|
+
embedding = self.embedding_model.encode([text],
|
|
133
|
+
convert_to_tensor=True,
|
|
134
|
+
normalize_embeddings=True)
|
|
135
|
+
vector = np.array(embedding, dtype=np.float32)
|
|
136
|
+
return vector[0] # 返回第一个向量,因为我们只编码了一个文本
|
|
137
|
+
except Exception as e:
|
|
138
|
+
PrettyOutput.print(f"创建方法论嵌入向量失败: {str(e)}", OutputType.ERROR)
|
|
139
|
+
return np.zeros(self.embedding_dimension, dtype=np.float32)
|
|
90
140
|
|
|
91
|
-
def _load_methodology(self) -> Dict[str, str]:
|
|
92
|
-
"""
|
|
141
|
+
def _load_methodology(self, user_input: str) -> Dict[str, str]:
|
|
142
|
+
"""加载方法论并构建向量索引"""
|
|
93
143
|
user_jarvis_methodology = os.path.expanduser("~/.jarvis_methodology")
|
|
94
|
-
if os.path.exists(user_jarvis_methodology):
|
|
144
|
+
if not os.path.exists(user_jarvis_methodology):
|
|
145
|
+
return {}
|
|
146
|
+
|
|
147
|
+
try:
|
|
95
148
|
with open(user_jarvis_methodology, "r", encoding="utf-8") as f:
|
|
96
149
|
data = yaml.safe_load(f)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
150
|
+
|
|
151
|
+
# 重置数据结构
|
|
152
|
+
self.methodology_data = []
|
|
153
|
+
vectors = []
|
|
154
|
+
ids = []
|
|
155
|
+
|
|
156
|
+
# 为每个方法论创建嵌入向量
|
|
157
|
+
for i, (key, value) in enumerate(data.items()):
|
|
158
|
+
PrettyOutput.print(f"向量化方法论: {key} ...", OutputType.INFO)
|
|
159
|
+
methodology_text = f"{key}\n{value}"
|
|
160
|
+
embedding = self._create_methodology_embedding(methodology_text)
|
|
161
|
+
vectors.append(embedding)
|
|
162
|
+
ids.append(i)
|
|
163
|
+
self.methodology_data.append({"key": key, "value": value})
|
|
164
|
+
|
|
165
|
+
if vectors:
|
|
166
|
+
vectors_array = np.vstack(vectors)
|
|
167
|
+
self.methodology_index.add_with_ids(vectors_array, np.array(ids))
|
|
168
|
+
query_embedding = self._create_methodology_embedding(user_input)
|
|
169
|
+
k = min(5, len(self.methodology_data))
|
|
170
|
+
PrettyOutput.print(f"检索方法论...", OutputType.INFO)
|
|
171
|
+
distances, indices = self.methodology_index.search(
|
|
172
|
+
query_embedding.reshape(1, -1), k
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
relevant_methodologies = {}
|
|
176
|
+
for dist, idx in zip(distances[0], indices[0]):
|
|
177
|
+
if idx >= 0:
|
|
178
|
+
similarity = 1.0 / (1.0 + float(dist))
|
|
179
|
+
methodology = self.methodology_data[idx]
|
|
180
|
+
PrettyOutput.print(
|
|
181
|
+
f"方法论 '{methodology['key']}' 相似度: {similarity:.3f}",
|
|
182
|
+
OutputType.INFO
|
|
183
|
+
)
|
|
184
|
+
if similarity >= 0.5:
|
|
185
|
+
relevant_methodologies[methodology["key"]] = methodology["value"]
|
|
186
|
+
|
|
187
|
+
if relevant_methodologies:
|
|
188
|
+
return relevant_methodologies
|
|
189
|
+
|
|
190
|
+
return {}
|
|
191
|
+
|
|
192
|
+
except Exception as e:
|
|
193
|
+
PrettyOutput.print(f"加载方法论时发生错误: {str(e)}", OutputType.ERROR)
|
|
194
|
+
return {}
|
|
100
195
|
|
|
101
196
|
def _summarize_and_clear_history(self) -> None:
|
|
102
197
|
"""总结当前对话历史并清空历史记录,只保留系统消息和总结
|
|
@@ -211,7 +306,7 @@ class Agent:
|
|
|
211
306
|
self.model.upload_files(file_list)
|
|
212
307
|
|
|
213
308
|
# 加载方法论
|
|
214
|
-
methodology = self._load_methodology()
|
|
309
|
+
methodology = self._load_methodology(user_input)
|
|
215
310
|
methodology_prompt = ""
|
|
216
311
|
if methodology:
|
|
217
312
|
methodology_prompt = f"""这是以往处理问题的标准方法论,如果当前任务与此类似,可参考:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/jarvis_codebase/__init__.py
RENAMED
|
File without changes
|
{jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/src/jarvis/jarvis_codebase/main.py
RENAMED
|
File without changes
|
{jarvis_ai_assistant-0.1.74 → jarvis_ai_assistant-0.1.75}/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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|