add cli
This commit is contained in:
@@ -1,19 +1,34 @@
|
|||||||
import sys
|
import sys
|
||||||
from agent import executor
|
from rag_tools import search_knowledge_base, add_to_knowledge_base
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def run_cli():
|
||||||
print("RAG Agent CLI. Commands: /add <title> <file>, /search <query>, /quit")
|
print("RAG Agent CLI. Commands: /add <title> <file>, /search <query>, /quit")
|
||||||
while True:
|
while True:
|
||||||
line = input("> ")
|
try:
|
||||||
if line.startswith("/quit"):
|
inp = input("> ")
|
||||||
|
except EOFError:
|
||||||
break
|
break
|
||||||
if line.startswith("/add"):
|
if not inp:
|
||||||
_, title, file = line.split(maxsplit=2)
|
continue
|
||||||
with open(file, "r", encoding="utf-8") as f:
|
if inp.startswith("/quit"):
|
||||||
text = f.read()
|
break
|
||||||
print(executor.invoke({"input": f"add {title} {text}"}))
|
if inp.startswith("/add"):
|
||||||
elif line.startswith("/search"):
|
parts = inp.split(maxsplit=2)
|
||||||
_, query = line.split(maxsplit=1)
|
if len(parts) < 3:
|
||||||
print(executor.invoke({"input": f"search {query}"}))
|
print("Usage: /add <title> <file>")
|
||||||
|
continue
|
||||||
|
title, file_path = parts[1], parts[2]
|
||||||
|
try:
|
||||||
|
with open(file_path, 'r', encoding='utf-8') as f:
|
||||||
|
content = f.read()
|
||||||
|
print(add_to_knowledge_base(content, title))
|
||||||
|
except Exception as e:
|
||||||
|
print("Error:", e)
|
||||||
|
elif inp.startswith("/search"):
|
||||||
|
query = inp[7:].strip()
|
||||||
|
print(search_knowledge_base(query))
|
||||||
else:
|
else:
|
||||||
print("Unknown command")
|
print("Unknown command")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run_cli()
|
||||||
|
|||||||
Reference in New Issue
Block a user