Spaces:
Sleeping
Sleeping
File size: 1,560 Bytes
8bbe87c ecbc643 8bbe87c ecbc643 8bbe87c ecbc643 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | # /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()
|