Files
task-6a1d75c5fd30e81cf3126ae7/src/cli.py
T
2026-06-04 23:23:44 +00:00

45 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""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())