File size: 1,631 Bytes
5f63e0d
6905aa5
 
 
8c7ca34
 
19f5032
8c7ca34
 
6905aa5
 
 
5f63e0d
19f5032
 
 
 
5f63e0d
 
 
19f5032
e12655f
 
5f63e0d
19f5032
8c7ca34
6905aa5
 
 
5f63e0d
 
6905aa5
8c7ca34
 
5f63e0d
 
 
19f5032
8c7ca34
 
 
19f5032
5f63e0d
8c7ca34
 
 
bae207d
 
 
 
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
# blaxel_main.py (Updated: New Provider Keys + Core Logic Only)
from fastapi import FastAPI
from pydantic import BaseModel
from sse_starlette.sse import EventSourceResponse
import os
import uvicorn
from typing import Dict, Optional

from agent_logic import StrategicSelectorAgent

app = FastAPI()

# 1. Update Pydantic model to accept all provider keys
class ApiKeys(BaseModel):
    google: str
    anthropic: Optional[str] = None
    sambanova: Optional[str] = None
    # New providers added:
    openai: Optional[str] = None
    nebius: Optional[str] = None

class ProblemRequest(BaseModel):
    problem: str
    # Expansion flag removed - we are sticking to the robust core loop
    keys: ApiKeys

@app.post("/solve_problem")
async def solve_problem(request: ProblemRequest):
    """
    Standard endpoint. Initializes the agent with all provided keys
    and streams the solution process.
    """
    async def stream_solution():
        try:
            # Pass the dictionary of keys (including new ones) to the agent
            # request.keys.dict() will include openai and nebius if sent
            mudabbir_ai = StrategicSelectorAgent(api_keys=request.keys.dict())
            
            async for status_update in mudabbir_ai.solve(request.problem):
                yield status_update
        except Exception as e:
            yield f"AGENT ERROR: {e}"
            print(f"AGENT ERROR: {e}") 

    return EventSourceResponse(stream_solution())

if __name__ == "__main__":
    HOST = os.getenv("BL_SERVER_HOST", "0.0.0.0")
    PORT = int(os.getenv("BL_SERVER_PORT", "8080"))
    uvicorn.run(app, host=HOST, port=PORT)