- CLI tool for testing (cli.py) - Docker Compose for easy deployment - Dockerfile for backend - QUICKSTART.md with setup instructions Ready to deploy! Run: python cli.py or docker-compose up
85 lines
2.3 KiB
Python
Executable File
85 lines
2.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Grimlock CLI - Simple command line interface for testing
|
|
"""
|
|
|
|
import asyncio
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Add backend to path
|
|
sys.path.insert(0, str(Path(__file__).parent / "backend"))
|
|
|
|
from core.ai_client import AIClient
|
|
from core.context_manager import ContextManager
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv("backend/.env")
|
|
|
|
async def main():
|
|
print("=" * 60)
|
|
print("GRIMLOCK CLI")
|
|
print("=" * 60)
|
|
|
|
# Initialize
|
|
api_key = os.getenv("ANTHROPIC_API_KEY")
|
|
if not api_key:
|
|
print("ERROR: ANTHROPIC_API_KEY not set")
|
|
print("Copy backend/.env.example to backend/.env and add your API key")
|
|
return
|
|
|
|
print("\nInitializing...")
|
|
context_manager = ContextManager("backend/context")
|
|
context_manager.load_all_context()
|
|
print(f"Context loaded: {context_manager.get_summary()}")
|
|
|
|
ai_client = AIClient(api_key=api_key)
|
|
print("AI client ready")
|
|
|
|
# Interactive loop
|
|
print("\nGrimlock is online. Type 'exit' to quit.\n")
|
|
|
|
messages = []
|
|
|
|
while True:
|
|
try:
|
|
user_input = input("You: ").strip()
|
|
|
|
if not user_input:
|
|
continue
|
|
|
|
if user_input.lower() in ['exit', 'quit', 'q']:
|
|
print("\nGoodbye!")
|
|
break
|
|
|
|
# Add user message
|
|
messages.append({"role": "user", "content": user_input})
|
|
|
|
# Get context
|
|
context = context_manager.get_context_for_query(user_input)
|
|
system_prompt = context_manager.get_system_prompt()
|
|
if context:
|
|
system_prompt += f"\n\n# Company Context\n{context}"
|
|
|
|
# Get response
|
|
print("\nGrimlock: ", end="", flush=True)
|
|
response = await ai_client.chat(
|
|
messages=messages,
|
|
system_prompt=system_prompt
|
|
)
|
|
print(response)
|
|
print()
|
|
|
|
# Add assistant message
|
|
messages.append({"role": "assistant", "content": response})
|
|
|
|
except KeyboardInterrupt:
|
|
print("\n\nGoodbye!")
|
|
break
|
|
except Exception as e:
|
|
print(f"\nError: {e}\n")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|