Add src/cli.py

This commit is contained in:
2026-06-04 23:23:44 +00:00
parent 5ea484b37a
commit 0f4acd1d36
+45
View File
@@ -0,0 +1,45 @@
"""Commandline interface for the FAQbot.
Examples:
python cli.py --question "What topics are covered in week 3?"
python cli.py --question "What is the course schedule?"
If no question is supplied, an interactive prompt is started.
"""
import argparse
import asyncio
from .agent import create_agent_executor
async def main():
parser = argparse.ArgumentParser(description="FAQbot CLI")
parser.add_argument("--question", type=str, help="Question to ask the bot")
args = parser.parse_args()
executor = await create_agent_executor()
if args.question:
state = {"input": args.question}
result = await executor.ainvoke(state)
print("\nAnswer:")
print(result["answer"])
print(f"\nSource: {result['source']}")
else:
print("Enter a question (CtrlD to exit):")
while True:
try:
q = input("> ")
except EOFError:
break
if not q.strip():
continue
state = {"input": q}
result = await executor.ainvoke(state)
print("\nAnswer:")
print(result["answer"])
print(f"\nSource: {result['source']}")
print("\n---")
if __name__ == "__main__":
asyncio.run(main())