Update cli.py
This commit is contained in:
@@ -1,49 +1 @@
|
||||
"""Simple interactive CLI for the RAG agent.
|
||||
|
||||
Commands:
|
||||
/add title content – add a document to the knowledge base.
|
||||
/search query – perform a semantic search.
|
||||
/quit – exit.
|
||||
any other text – will be sent to the agent for normal answering.
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
from .agent import create_agent_executor
|
||||
|
||||
agent = create_agent_executor()
|
||||
|
||||
print("RAG Agent CLI. Type /quit to exit.")
|
||||
while True:
|
||||
try:
|
||||
user_input = input(">>> ")
|
||||
except EOFError:
|
||||
break
|
||||
if not user_input:
|
||||
continue
|
||||
if user_input.lower() == "/quit":
|
||||
print("Goodbye!")
|
||||
break
|
||||
if user_input.startswith("/add "):
|
||||
# Expected format: /add title content
|
||||
parts = user_input.split(" ", 2)
|
||||
if len(parts) < 3:
|
||||
print("Usage: /add title content")
|
||||
continue
|
||||
title, content = parts[1], parts[2]
|
||||
# Directly call the tool via the agent
|
||||
result = agent.run({"input": f"Add document: {title} – {content}"})
|
||||
print(result)
|
||||
continue
|
||||
if user_input.startswith("/search "):
|
||||
query = user_input[8:].strip()
|
||||
result = agent.run({"input": f"Search for: {query}"})
|
||||
print(result)
|
||||
continue
|
||||
# Normal conversation
|
||||
result = agent.run({"input": user_input})
|
||||
print(result)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# The CLI is already running in the main thread
|
||||
pass
|
||||
# Legacy file removed
|
||||
Reference in New Issue
Block a user