35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import sys
|
|
from rag_tools import search_knowledge_base, add_to_knowledge_base
|
|
|
|
def run_cli():
|
|
print("RAG Agent CLI. Commands: /add <title> <file>, /search <query>, /quit")
|
|
while True:
|
|
try:
|
|
inp = input("> ")
|
|
except EOFError:
|
|
break
|
|
if not inp:
|
|
continue
|
|
if inp.startswith("/quit"):
|
|
break
|
|
if inp.startswith("/add"):
|
|
parts = inp.split(maxsplit=2)
|
|
if len(parts) < 3:
|
|
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:
|
|
print("Unknown command")
|
|
|
|
if __name__ == "__main__":
|
|
run_cli()
|