jarvis-ai-assistant 0.1.3__py3-none-any.whl → 0.1.6__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/__pycache__/__init__.cpython-313.pyc +0 -0
- jarvis/__pycache__/agent.cpython-313.pyc +0 -0
- jarvis/__pycache__/main.cpython-313.pyc +0 -0
- jarvis/__pycache__/models.cpython-313.pyc +0 -0
- jarvis/__pycache__/utils.cpython-313.pyc +0 -0
- jarvis/__pycache__/zte_llm.cpython-313.pyc +0 -0
- jarvis/agent.py +131 -36
- jarvis/main.py +44 -24
- jarvis/models.py +54 -36
- jarvis/tools/__init__.py +3 -9
- jarvis/tools/__pycache__/__init__.cpython-313.pyc +0 -0
- jarvis/tools/__pycache__/base.cpython-313.pyc +0 -0
- jarvis/tools/__pycache__/shell.cpython-313.pyc +0 -0
- jarvis/tools/__pycache__/sub_agent.cpython-313.pyc +0 -0
- jarvis/tools/__pycache__/user_input.cpython-313.pyc +0 -0
- jarvis/tools/base.py +57 -138
- jarvis/tools/shell.py +62 -48
- jarvis/tools/sub_agent.py +141 -0
- jarvis/tools/user_input.py +74 -0
- jarvis/utils.py +123 -64
- jarvis/zte_llm.py +136 -0
- {jarvis_ai_assistant-0.1.3.dist-info → jarvis_ai_assistant-0.1.6.dist-info}/METADATA +6 -4
- jarvis_ai_assistant-0.1.6.dist-info/RECORD +38 -0
- {jarvis_ai_assistant-0.1.3.dist-info → jarvis_ai_assistant-0.1.6.dist-info}/WHEEL +1 -1
- jarvis/.jarvis +0 -1
- jarvis/tools/python_script.py +0 -150
- jarvis/tools/rag.py +0 -154
- jarvis/tools/user_confirmation.py +0 -58
- jarvis/tools/user_interaction.py +0 -86
- jarvis_ai_assistant-0.1.3.dist-info/RECORD +0 -36
- {jarvis_ai_assistant-0.1.3.dist-info → jarvis_ai_assistant-0.1.6.dist-info}/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.1.3.dist-info → jarvis_ai_assistant-0.1.6.dist-info}/top_level.txt +0 -0
jarvis/tools/rag.py
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
from typing import Dict, Any, List
|
|
2
|
-
import chromadb
|
|
3
|
-
from chromadb.utils import embedding_functions
|
|
4
|
-
import hashlib
|
|
5
|
-
import re
|
|
6
|
-
from ..utils import PrettyOutput, OutputType
|
|
7
|
-
|
|
8
|
-
class RAGTool:
|
|
9
|
-
name = "rag_query"
|
|
10
|
-
description = """Execute RAG queries on documents.
|
|
11
|
-
Features:
|
|
12
|
-
1. Auto-creates document embeddings
|
|
13
|
-
2. Returns relevant passages
|
|
14
|
-
3. Maintains embedding database
|
|
15
|
-
"""
|
|
16
|
-
parameters = {
|
|
17
|
-
"type": "object",
|
|
18
|
-
"properties": {
|
|
19
|
-
"files": {
|
|
20
|
-
"type": "array",
|
|
21
|
-
"items": {"type": "string"},
|
|
22
|
-
"description": "Files to process"
|
|
23
|
-
},
|
|
24
|
-
"query": {
|
|
25
|
-
"type": "string",
|
|
26
|
-
"description": "Query text"
|
|
27
|
-
},
|
|
28
|
-
"num_passages": {
|
|
29
|
-
"type": "integer",
|
|
30
|
-
"description": "Number of passages",
|
|
31
|
-
"default": 3
|
|
32
|
-
},
|
|
33
|
-
"chunk_size": {
|
|
34
|
-
"type": "integer",
|
|
35
|
-
"description": "Chunk size",
|
|
36
|
-
"default": 500
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
"required": ["files", "query"]
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
def _get_document_hash(self, content: str) -> str:
|
|
43
|
-
return hashlib.md5(content.encode()).hexdigest()
|
|
44
|
-
|
|
45
|
-
def _chunk_text(self, text: str, chunk_size: int = 500) -> List[str]:
|
|
46
|
-
"""将文本分割成适当大小的块"""
|
|
47
|
-
# 按句子分割
|
|
48
|
-
sentences = re.split(r'(?<=[.!?])\s+', text)
|
|
49
|
-
chunks = []
|
|
50
|
-
current_chunk = []
|
|
51
|
-
current_length = 0
|
|
52
|
-
|
|
53
|
-
for sentence in sentences:
|
|
54
|
-
sentence_length = len(sentence)
|
|
55
|
-
if current_length + sentence_length > chunk_size and current_chunk:
|
|
56
|
-
chunks.append(" ".join(current_chunk))
|
|
57
|
-
current_chunk = []
|
|
58
|
-
current_length = 0
|
|
59
|
-
current_chunk.append(sentence)
|
|
60
|
-
current_length += sentence_length
|
|
61
|
-
|
|
62
|
-
if current_chunk:
|
|
63
|
-
chunks.append(" ".join(current_chunk))
|
|
64
|
-
|
|
65
|
-
return chunks
|
|
66
|
-
|
|
67
|
-
def execute(self, args: Dict) -> Dict[str, Any]:
|
|
68
|
-
"""执行RAG查询"""
|
|
69
|
-
try:
|
|
70
|
-
files = args["files"]
|
|
71
|
-
query = args["query"]
|
|
72
|
-
num_passages = args.get("num_passages", 3)
|
|
73
|
-
chunk_size = args.get("chunk_size", 500)
|
|
74
|
-
|
|
75
|
-
# 初始化ChromaDB
|
|
76
|
-
chroma_client = chromadb.PersistentClient(path="./data/chromadb")
|
|
77
|
-
|
|
78
|
-
# 使用sentence-transformers作为嵌入模型
|
|
79
|
-
embedding_function = embedding_functions.SentenceTransformerEmbeddingFunction(
|
|
80
|
-
model_name="all-MiniLM-L6-v2"
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
# 获取或创建集合
|
|
84
|
-
collection = chroma_client.get_or_create_collection(
|
|
85
|
-
name="document_store",
|
|
86
|
-
embedding_function=embedding_function
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
# 处理每个文件
|
|
90
|
-
for file_path in files:
|
|
91
|
-
try:
|
|
92
|
-
with open(file_path, 'r', encoding='utf-8') as f:
|
|
93
|
-
content = f.read()
|
|
94
|
-
|
|
95
|
-
# 计算文档哈希值
|
|
96
|
-
doc_hash = self._get_document_hash(content)
|
|
97
|
-
|
|
98
|
-
# 检查文档是否已经存在且未更改
|
|
99
|
-
existing_ids = collection.get(
|
|
100
|
-
where={"doc_hash": doc_hash}
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
if not existing_ids["ids"]:
|
|
104
|
-
# 分块处理文档
|
|
105
|
-
chunks = self._chunk_text(content, chunk_size)
|
|
106
|
-
|
|
107
|
-
# 为每个块生成唯一ID
|
|
108
|
-
chunk_ids = [f"{doc_hash}_{i}" for i in range(len(chunks))]
|
|
109
|
-
|
|
110
|
-
# 添加到数据库
|
|
111
|
-
collection.add(
|
|
112
|
-
documents=chunks,
|
|
113
|
-
ids=chunk_ids,
|
|
114
|
-
metadatas=[{
|
|
115
|
-
"file_path": file_path,
|
|
116
|
-
"doc_hash": doc_hash,
|
|
117
|
-
"chunk_index": i
|
|
118
|
-
} for i in range(len(chunks))]
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
PrettyOutput.print(f"已添加文档: {file_path}", OutputType.INFO)
|
|
122
|
-
else:
|
|
123
|
-
PrettyOutput.print(f"文档已存在且未更改: {file_path}", OutputType.INFO)
|
|
124
|
-
|
|
125
|
-
except Exception as e:
|
|
126
|
-
PrettyOutput.print(f"处理文件 {file_path} 时出错: {str(e)}", OutputType.ERROR)
|
|
127
|
-
|
|
128
|
-
# 执行查询
|
|
129
|
-
results = collection.query(
|
|
130
|
-
query_texts=[query],
|
|
131
|
-
n_results=num_passages
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
# 格式化输出
|
|
135
|
-
output = [f"查询: {query}\n"]
|
|
136
|
-
output.append(f"找到 {len(results['documents'][0])} 个相关段落:\n")
|
|
137
|
-
|
|
138
|
-
for i, (doc, metadata) in enumerate(zip(results['documents'][0], results['metadatas'][0]), 1):
|
|
139
|
-
output.append(f"\n段落 {i}:")
|
|
140
|
-
output.append(f"来源: {metadata['file_path']}")
|
|
141
|
-
output.append(f"相关内容:\n{doc}\n")
|
|
142
|
-
output.append("-" * 50)
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
"success": True,
|
|
146
|
-
"stdout": "\n".join(output),
|
|
147
|
-
"stderr": ""
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
except Exception as e:
|
|
151
|
-
return {
|
|
152
|
-
"success": False,
|
|
153
|
-
"error": f"RAG查询失败: {str(e)}"
|
|
154
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
from typing import Dict, Any
|
|
2
|
-
from ..utils import PrettyOutput, OutputType
|
|
3
|
-
|
|
4
|
-
class UserConfirmationTool:
|
|
5
|
-
name = "ask_user_confirmation"
|
|
6
|
-
description = "Request confirmation from user, returns yes/no"
|
|
7
|
-
parameters = {
|
|
8
|
-
"type": "object",
|
|
9
|
-
"properties": {
|
|
10
|
-
"question": {
|
|
11
|
-
"type": "string",
|
|
12
|
-
"description": "Question to ask for confirmation"
|
|
13
|
-
},
|
|
14
|
-
"details": {
|
|
15
|
-
"type": "string",
|
|
16
|
-
"description": "Additional details or context",
|
|
17
|
-
"default": ""
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"required": ["question"]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
def execute(self, args: Dict) -> Dict[str, Any]:
|
|
24
|
-
"""获取用户确认"""
|
|
25
|
-
try:
|
|
26
|
-
question = args["question"]
|
|
27
|
-
details = args.get("details", "")
|
|
28
|
-
|
|
29
|
-
# 打印详细信息
|
|
30
|
-
if details:
|
|
31
|
-
PrettyOutput.print(details, OutputType.INFO)
|
|
32
|
-
PrettyOutput.print("", OutputType.INFO) # 空行
|
|
33
|
-
|
|
34
|
-
# 打印问题
|
|
35
|
-
PrettyOutput.print(f"{question} (y/n)", OutputType.INFO)
|
|
36
|
-
|
|
37
|
-
while True:
|
|
38
|
-
response = input(">>> ").strip().lower()
|
|
39
|
-
if response in ['y', 'yes']:
|
|
40
|
-
result = True
|
|
41
|
-
break
|
|
42
|
-
elif response in ['n', 'no']:
|
|
43
|
-
result = False
|
|
44
|
-
break
|
|
45
|
-
else:
|
|
46
|
-
PrettyOutput.print("请输入 y/yes 或 n/no", OutputType.ERROR)
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
"success": True,
|
|
50
|
-
"stdout": str(result),
|
|
51
|
-
"stderr": ""
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
except Exception as e:
|
|
55
|
-
return {
|
|
56
|
-
"success": False,
|
|
57
|
-
"error": f"获取用户确认失败: {str(e)}"
|
|
58
|
-
}
|
jarvis/tools/user_interaction.py
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
from typing import Dict, Any, List
|
|
2
|
-
from ..utils import PrettyOutput, OutputType, get_multiline_input
|
|
3
|
-
|
|
4
|
-
class UserInteractionTool:
|
|
5
|
-
name = "ask_user"
|
|
6
|
-
description = "Ask user for information, supports option selection and multiline input"
|
|
7
|
-
parameters = {
|
|
8
|
-
"type": "object",
|
|
9
|
-
"properties": {
|
|
10
|
-
"question": {
|
|
11
|
-
"type": "string",
|
|
12
|
-
"description": "Question to ask the user"
|
|
13
|
-
},
|
|
14
|
-
"options": {
|
|
15
|
-
"type": "array",
|
|
16
|
-
"items": {"type": "string"},
|
|
17
|
-
"description": "List of options for user to choose from",
|
|
18
|
-
"default": []
|
|
19
|
-
},
|
|
20
|
-
"multiline": {
|
|
21
|
-
"type": "boolean",
|
|
22
|
-
"description": "Allow multiline input",
|
|
23
|
-
"default": False
|
|
24
|
-
},
|
|
25
|
-
"description": {
|
|
26
|
-
"type": "string",
|
|
27
|
-
"description": "Additional description or context",
|
|
28
|
-
"default": ""
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
"required": ["question"]
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
def execute(self, args: Dict) -> Dict[str, Any]:
|
|
35
|
-
"""获取用户输入"""
|
|
36
|
-
try:
|
|
37
|
-
question = args["question"]
|
|
38
|
-
options = args.get("options", [])
|
|
39
|
-
multiline = args.get("multiline", False)
|
|
40
|
-
description = args.get("description", "")
|
|
41
|
-
|
|
42
|
-
# 打印问题描述
|
|
43
|
-
if description:
|
|
44
|
-
PrettyOutput.print(description, OutputType.INFO)
|
|
45
|
-
|
|
46
|
-
# 如果有选项,显示选项列表
|
|
47
|
-
if options:
|
|
48
|
-
PrettyOutput.print("\n可选项:", OutputType.INFO)
|
|
49
|
-
for i, option in enumerate(options, 1):
|
|
50
|
-
PrettyOutput.print(f"[{i}] {option}", OutputType.INFO)
|
|
51
|
-
|
|
52
|
-
while True:
|
|
53
|
-
try:
|
|
54
|
-
choice = input("\n请选择 (输入数字): ").strip()
|
|
55
|
-
if not choice:
|
|
56
|
-
continue
|
|
57
|
-
|
|
58
|
-
choice = int(choice)
|
|
59
|
-
if 1 <= choice <= len(options):
|
|
60
|
-
response = options[choice - 1]
|
|
61
|
-
break
|
|
62
|
-
else:
|
|
63
|
-
PrettyOutput.print("无效选择,请重试", OutputType.ERROR)
|
|
64
|
-
except ValueError:
|
|
65
|
-
PrettyOutput.print("请输入有效数字", OutputType.ERROR)
|
|
66
|
-
|
|
67
|
-
# 多行输入
|
|
68
|
-
elif multiline:
|
|
69
|
-
response = get_multiline_input(question)
|
|
70
|
-
|
|
71
|
-
# 单行输入
|
|
72
|
-
else:
|
|
73
|
-
PrettyOutput.print(question, OutputType.INFO)
|
|
74
|
-
response = input(">>> ").strip()
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
"success": True,
|
|
78
|
-
"stdout": response,
|
|
79
|
-
"stderr": ""
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
except Exception as e:
|
|
83
|
-
return {
|
|
84
|
-
"success": False,
|
|
85
|
-
"error": f"获取用户输入失败: {str(e)}"
|
|
86
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
jarvis/.jarvis,sha256=S4ZMmLqlVLHAPmnwHFQ3vYt0gnDFp-KQRH4okBh8Hpw,209
|
|
2
|
-
jarvis/__init__.py,sha256=rLUKzHgrbk82WAMvg4u4GlFDRal1Yw3XpMg_741mQXw,49
|
|
3
|
-
jarvis/agent.py,sha256=hEatrIothG6C_RuOsygZz4ez1aF1EycnUPwY2Krwiwk,4092
|
|
4
|
-
jarvis/main.py,sha256=wAeeGoRq8fFiTWUCQ31MYVeU9o6SZ48ORUow0jlMJJE,5259
|
|
5
|
-
jarvis/models.py,sha256=ZQAyc39e_UsNmHkME6ATp6053safQ7Gog-oWwETsrMM,4415
|
|
6
|
-
jarvis/utils.py,sha256=-fOPAgiKVPC6DevHM7A7IJvvIzvvFlGM0pHBKyBXDcA,3044
|
|
7
|
-
jarvis/__pycache__/__init__.cpython-313.pyc,sha256=u64PLu4KyOPrirhIqNXZSkj9B6yB1L_ohFYhPX8p334,208
|
|
8
|
-
jarvis/__pycache__/agent.cpython-313.pyc,sha256=I1JYUKC-zedURwuxQQjd9saj_yQKUhpdbb1KNWlY6Ss,4940
|
|
9
|
-
jarvis/__pycache__/models.cpython-313.pyc,sha256=fot2VOV0lgODg4b_WuD-kkq-g7uZGLuZlYXiljlW13U,6350
|
|
10
|
-
jarvis/__pycache__/tools.cpython-313.pyc,sha256=lAD4LrnnWzNZQmHXGfZ_2l7oskOpr2_2OC-gdFhxQY8,33933
|
|
11
|
-
jarvis/__pycache__/utils.cpython-313.pyc,sha256=o8Fubq8Dcrvv3ATzQ9BnZoZjQmU3_FNPrfTt0ANdKdI,5804
|
|
12
|
-
jarvis/tools/__init__.py,sha256=FNF5X32UzKvlT08-hPz7-7vcIyqqMngQYj36LXyNbV0,553
|
|
13
|
-
jarvis/tools/base.py,sha256=Y1XInc2skUVZYZzLRPlCpH3JyY3pk1XNZgys6MSCudQ,6586
|
|
14
|
-
jarvis/tools/file_ops.py,sha256=05Vc4u-NGMjLD15WI52eL_nt_RyYt-Z_cXJnnBepf-c,3781
|
|
15
|
-
jarvis/tools/python_script.py,sha256=_eK8LqNs-Mz50zdcgwbjdd8-qAeOl6kJ_qRDvWawGMw,5006
|
|
16
|
-
jarvis/tools/rag.py,sha256=eBrn1fdqy-nd2nR0b4oH1EQpthTYVen-sYDhC5Ypl38,5647
|
|
17
|
-
jarvis/tools/search.py,sha256=dyJmeP_s2tWv5KQejOl-TuVF12B6SXViiXEyTemD1Wo,1412
|
|
18
|
-
jarvis/tools/shell.py,sha256=VhEqEdoUGIRW6CT6F0YNMAlzJxpHcsKS9hSS0VC3ezw,2644
|
|
19
|
-
jarvis/tools/user_confirmation.py,sha256=p0JverifHJfnALeIhtKtaVBBVEGkgSpUzT-PSycG4NY,1850
|
|
20
|
-
jarvis/tools/user_interaction.py,sha256=xOaoYsCKTa9-K3mg5tsu1zegn1HKcO40k2aJ3VygZqM,3073
|
|
21
|
-
jarvis/tools/webpage.py,sha256=UTEomu5j7jbOw8c5az2jsjv5E7LeokWKj1QahvZO7xc,3077
|
|
22
|
-
jarvis/tools/__pycache__/__init__.cpython-313.pyc,sha256=wktmOMuGMwQjQ--eRzooUNsL5YjY0bS_CbcSFUWze54,674
|
|
23
|
-
jarvis/tools/__pycache__/base.cpython-313.pyc,sha256=hqhRtxwQwWLnBEzNqZ1FqcWYuyX87iu89SgHxu10Gho,8192
|
|
24
|
-
jarvis/tools/__pycache__/file_ops.cpython-313.pyc,sha256=bawv11xhWSj5wCtW0QeJLI-InhUBUXaSkogq6rZzvTQ,3636
|
|
25
|
-
jarvis/tools/__pycache__/python_script.cpython-313.pyc,sha256=8JpryqTovEiTvBlWAK1KjZmPvHUuPc9GT9rTXBEQoJc,6693
|
|
26
|
-
jarvis/tools/__pycache__/rag.cpython-313.pyc,sha256=JH6-PSZRMKAvTZqCwlRXJGClxYXNMs-vetU0q7hBLz0,6064
|
|
27
|
-
jarvis/tools/__pycache__/search.cpython-313.pyc,sha256=VX9zztOwIsPCkYwev0A0XJGyu4Tr0PQcQkbbqx8vfB0,1870
|
|
28
|
-
jarvis/tools/__pycache__/shell.cpython-313.pyc,sha256=Xtqt-LzMRfsCXeCE7QxFY8TR8XEeQG_jic73YLkhXQw,2302
|
|
29
|
-
jarvis/tools/__pycache__/user_confirmation.cpython-313.pyc,sha256=wK3Ev10lHSUSRvoYmi7A0GzxYkzU-C4Wfhs5qW_HBqs,2271
|
|
30
|
-
jarvis/tools/__pycache__/user_interaction.cpython-313.pyc,sha256=RuVZ-pmiPBDywY3efgXSfohMAciC1avMGPmBK5qlnew,3305
|
|
31
|
-
jarvis/tools/__pycache__/webpage.cpython-313.pyc,sha256=VcpkaV8IyOOtebedXjn8ybjr8AglU-3-Cs80yzE4FYo,3628
|
|
32
|
-
jarvis_ai_assistant-0.1.3.dist-info/METADATA,sha256=eVKO4jecgKkHOIRUXZGvfvi5KiR9CGaZuQLhDR9W3NY,3675
|
|
33
|
-
jarvis_ai_assistant-0.1.3.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
|
|
34
|
-
jarvis_ai_assistant-0.1.3.dist-info/entry_points.txt,sha256=iKu7OMfew9dtfGhW71gIMTg4wvafuPqKb4wyQOnMAGU,44
|
|
35
|
-
jarvis_ai_assistant-0.1.3.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
|
|
36
|
-
jarvis_ai_assistant-0.1.3.dist-info/RECORD,,
|
{jarvis_ai_assistant-0.1.3.dist-info → jarvis_ai_assistant-0.1.6.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|