Spaces:
Sleeping
Sleeping
| # /example/example.py | |
| """ | |
| Simple CLI/REPL example for the ChatBot. | |
| Usage: | |
| python example/example.py "hello world" | |
| python example/example.py # enters interactive mode | |
| """ | |
| import argparse | |
| import json | |
| import sys | |
| try: | |
| from agenticcore.chatbot.services import ChatBot | |
| except ImportError as e: | |
| print("β Could not import ChatBot. Did you set PYTHONPATH or install agenticcore?") | |
| sys.exit(1) | |
| def main(): | |
| parser = argparse.ArgumentParser(description="ChatBot CLI/REPL example") | |
| parser.add_argument( | |
| "message", | |
| nargs="*", | |
| help="Message to send. Leave empty to start interactive mode.", | |
| ) | |
| args = parser.parse_args() | |
| try: | |
| bot = ChatBot() | |
| except Exception as e: | |
| print(f"β Failed to initialize ChatBot: {e}") | |
| sys.exit(1) | |
| if args.message: | |
| # One-shot mode | |
| msg = " ".join(args.message) | |
| result = bot.reply(msg) | |
| print(json.dumps(result, indent=2)) | |
| else: | |
| # Interactive REPL | |
| print("π¬ Interactive mode. Type 'quit' or 'exit' to stop.") | |
| while True: | |
| try: | |
| msg = input("> ").strip() | |
| except (EOFError, KeyboardInterrupt): | |
| print("\nπ Exiting.") | |
| break | |
| if msg.lower() in {"quit", "exit"}: | |
| print("π Goodbye.") | |
| break | |
| if not msg: | |
| continue | |
| result = bot.reply(msg) | |
| print(json.dumps(result, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |