File size: 2,203 Bytes
b70539a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from datetime import datetime
import os
from dotenv import load_dotenv
from typing import List, Optional
from uuid import uuid4

from rag import RAGSystem, load_config

# Load environment variables
load_dotenv()

# Load configuration
CONFIG = load_config()
MOB_MAPPINGS = CONFIG['mob_mappings']

# Get API key
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
if not OPENAI_API_KEY:
    raise ValueError("OPENAI_API_KEY environment variable is not set")

# Initialize FastAPI app
app = FastAPI(
    title="CubixAI API",
    description="API for CubixAI - Minecraft bot with AI capabilities",
    version="0.1.0",
)

# Initialize RAG system
rag_system = RAGSystem(openai_api_key=OPENAI_API_KEY)

# Status response model
class StatusResponse(BaseModel):
    status: str
    version: str
    timestamp: str

# Message request model
class MessageRequest(BaseModel):
    message: str
    user_id: Optional[str] = None

# Document URL model
class DocumentURLs(BaseModel):
    urls: List[str]

app.get("/")
def read_root():
    return {"Hello": "World"}

@app.get("/status", response_model=StatusResponse)
async def get_status():
    """Get the current status of the API."""
    return StatusResponse(
        status="online",
        version=app.version,
        timestamp=datetime.now().isoformat()
    )

@app.post("/process_message")
async def process_message(request: MessageRequest):
    """Process a message from a player and generate a structured JSON response."""
    user_id = request.user_id or str(uuid4())
    response = rag_system.generate_response(user_id, request.message)
    
    # Just add user_id to response without other modifications
    if isinstance(response, dict):
        response["user_id"] = user_id
    
    return response

@app.get("/mob_mappings")
async def get_mob_mappings():
    """Get the mapping of mob names to entity IDs."""
    return MOB_MAPPINGS

@app.get("/command_specs")
async def get_command_specs():
    """Get the command specifications."""
    return CONFIG['command_specs']

if __name__ == "__main__":
    import uvicorn
    uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)