From 0f4acd1d3661624cec1f0a488b4fe21516eebb05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A0=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Thu, 4 Jun 2026 23:23:44 +0000 Subject: [PATCH] Add src/cli.py --- src/cli.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/cli.py diff --git a/src/cli.py b/src/cli.py new file mode 100644 index 0000000..d9cd9d6 --- /dev/null +++ b/src/cli.py @@ -0,0 +1,45 @@ +"""Command‑line interface for the FAQ‑bot. + +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="FAQ‑bot 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 (Ctrl‑D 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()) \ No newline at end of file