Spaces:
Running
Running
Fix API endpoints to match frontend expectations - resolve 404 errors
Browse files
app.py
CHANGED
|
@@ -65,20 +65,23 @@ async def startup_event():
|
|
| 65 |
character_manager = CharacterManager() # Fallback
|
| 66 |
|
| 67 |
# API Routes (matching your existing REST API)
|
| 68 |
-
@app.post("/api/chat")
|
| 69 |
-
async def chat_endpoint(request: Request):
|
| 70 |
"""Chat endpoint matching your original REST API"""
|
| 71 |
try:
|
| 72 |
data = await request.json()
|
| 73 |
-
character_id = data.get('character', 'moses')
|
| 74 |
message = data.get('message', '')
|
| 75 |
history = data.get('history', [])
|
| 76 |
|
| 77 |
if not character_manager:
|
| 78 |
raise HTTPException(status_code=500, detail="Character manager not initialized")
|
| 79 |
|
| 80 |
-
# Get response from character
|
| 81 |
-
response =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
return {
|
| 84 |
"success": True,
|
|
@@ -115,9 +118,9 @@ async def switch_character_endpoint(request: Request):
|
|
| 115 |
except Exception as e:
|
| 116 |
return {"success": False, "error": str(e)}
|
| 117 |
|
| 118 |
-
@app.get("/api/voice
|
| 119 |
async def voice_status():
|
| 120 |
-
"""Voice status endpoint"""
|
| 121 |
return {
|
| 122 |
"available": False, # Disabled for Spaces deployment
|
| 123 |
"enabled": False
|
|
|
|
| 65 |
character_manager = CharacterManager() # Fallback
|
| 66 |
|
| 67 |
# API Routes (matching your existing REST API)
|
| 68 |
+
@app.post("/api/chat/{character_id}")
|
| 69 |
+
async def chat_endpoint(character_id: str, request: Request):
|
| 70 |
"""Chat endpoint matching your original REST API"""
|
| 71 |
try:
|
| 72 |
data = await request.json()
|
|
|
|
| 73 |
message = data.get('message', '')
|
| 74 |
history = data.get('history', [])
|
| 75 |
|
| 76 |
if not character_manager:
|
| 77 |
raise HTTPException(status_code=500, detail="Character manager not initialized")
|
| 78 |
|
| 79 |
+
# Get response from character using generate_response method
|
| 80 |
+
response = character_manager.generate_response(
|
| 81 |
+
character_id=character_id,
|
| 82 |
+
user_input=message,
|
| 83 |
+
conversation_history=history
|
| 84 |
+
)
|
| 85 |
|
| 86 |
return {
|
| 87 |
"success": True,
|
|
|
|
| 118 |
except Exception as e:
|
| 119 |
return {"success": False, "error": str(e)}
|
| 120 |
|
| 121 |
+
@app.get("/api/voice/status")
|
| 122 |
async def voice_status():
|
| 123 |
+
"""Voice status endpoint matching frontend expectations"""
|
| 124 |
return {
|
| 125 |
"available": False, # Disabled for Spaces deployment
|
| 126 |
"enabled": False
|