Leonydis137 commited on
Commit
d5499fd
·
verified ·
1 Parent(s): b2d2f75

Upload 2 files

Browse files
Files changed (2) hide show
  1. knowledge.py +27 -0
  2. tasks.py +10 -0
knowledge.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from sentence_transformers import SentenceTransformer
3
+ import faiss
4
+ import os
5
+
6
+ class KnowledgeIngestor:
7
+ def __init__(self):
8
+ self.model = SentenceTransformer("all-MiniLM-L6-v2")
9
+ self.index = faiss.IndexFlatL2(384)
10
+ self.texts = []
11
+
12
+ def ingest_directory(self, dir_path):
13
+ for fname in os.listdir(dir_path):
14
+ if fname.endswith(".txt"):
15
+ with open(os.path.join(dir_path, fname), "r", encoding="utf-8") as f:
16
+ content = f.read()
17
+ self.add_text(content)
18
+
19
+ def add_text(self, text):
20
+ vec = self.model.encode([text])
21
+ self.index.add(vec)
22
+ self.texts.append(text)
23
+
24
+ def search(self, query, top_k=3):
25
+ vec = self.model.encode([query])
26
+ D, I = self.index.search(vec, top_k)
27
+ return [self.texts[i] for i in I[0]]
tasks.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import subprocess
3
+
4
+ class TaskAgent:
5
+ def run_shell_command(self, command):
6
+ try:
7
+ result = subprocess.run(command, shell=True, capture_output=True, text=True, timeout=10)
8
+ return result.stdout or result.stderr
9
+ except Exception as e:
10
+ return f"[TaskAgent Error] {str(e)}"