youssefleb commited on
Commit
5f63e0d
·
verified ·
1 Parent(s): 3bd9a83

Update blaxel_main.py

Browse files
Files changed (1) hide show
  1. blaxel_main.py +12 -12
blaxel_main.py CHANGED
@@ -1,4 +1,4 @@
1
- # blaxel_main.py (New Secure Version)
2
  from fastapi import FastAPI
3
  from pydantic import BaseModel
4
  from sse_starlette.sse import EventSourceResponse
@@ -6,44 +6,44 @@ import os
6
  import uvicorn
7
  from typing import Dict, Optional
8
 
9
- # 1. Import our "Brain"
10
  from agent_logic import StrategicSelectorAgent
11
 
12
  app = FastAPI()
13
 
14
- # 2. Update Pydantic model to accept keys (some are optional)
15
  class ApiKeys(BaseModel):
16
  google: str
17
  anthropic: Optional[str] = None
18
  sambanova: Optional[str] = None
 
 
 
19
 
20
  class ProblemRequest(BaseModel):
21
  problem: str
 
22
  keys: ApiKeys
23
 
24
  @app.post("/solve_problem")
25
  async def solve_problem(request: ProblemRequest):
26
  """
27
- This endpoint now creates a *new* agent for every request,
28
- and passes the user's API keys to it.
29
- This is stateless and secure.
30
  """
31
-
32
  async def stream_solution():
33
  try:
34
- # 3. Pass keys to the agent's constructor
35
- mudabbir_ai = StrategicSelectorAgent(api_keys=request.keys.model_dump())
 
36
 
37
  async for status_update in mudabbir_ai.solve(request.problem):
38
  yield status_update
39
  except Exception as e:
40
- # This will catch errors (like invalid keys)
41
  yield f"AGENT ERROR: {e}"
42
- print(f"AGENT ERROR: {e}") # Also log to backend
43
 
44
  return EventSourceResponse(stream_solution())
45
 
46
-
47
  if __name__ == "__main__":
48
  HOST = os.getenv("BL_SERVER_HOST", "0.0.0.0")
49
  PORT = int(os.getenv("BL_SERVER_PORT", "8080"))
 
1
+ # blaxel_main.py (Updated: New Provider Keys + Core Logic Only)
2
  from fastapi import FastAPI
3
  from pydantic import BaseModel
4
  from sse_starlette.sse import EventSourceResponse
 
6
  import uvicorn
7
  from typing import Dict, Optional
8
 
 
9
  from agent_logic import StrategicSelectorAgent
10
 
11
  app = FastAPI()
12
 
13
+ # 1. Update Pydantic model to accept all provider keys
14
  class ApiKeys(BaseModel):
15
  google: str
16
  anthropic: Optional[str] = None
17
  sambanova: Optional[str] = None
18
+ # New providers added:
19
+ openai: Optional[str] = None
20
+ nebius: Optional[str] = None
21
 
22
  class ProblemRequest(BaseModel):
23
  problem: str
24
+ # Expansion flag removed - we are sticking to the robust core loop
25
  keys: ApiKeys
26
 
27
  @app.post("/solve_problem")
28
  async def solve_problem(request: ProblemRequest):
29
  """
30
+ Standard endpoint. Initializes the agent with all provided keys
31
+ and streams the solution process.
 
32
  """
 
33
  async def stream_solution():
34
  try:
35
+ # Pass the dictionary of keys (including new ones) to the agent
36
+ # request.keys.dict() will include openai and nebius if sent
37
+ mudabbir_ai = StrategicSelectorAgent(api_keys=request.keys.dict())
38
 
39
  async for status_update in mudabbir_ai.solve(request.problem):
40
  yield status_update
41
  except Exception as e:
 
42
  yield f"AGENT ERROR: {e}"
43
+ print(f"AGENT ERROR: {e}")
44
 
45
  return EventSourceResponse(stream_solution())
46
 
 
47
  if __name__ == "__main__":
48
  HOST = os.getenv("BL_SERVER_HOST", "0.0.0.0")
49
  PORT = int(os.getenv("BL_SERVER_PORT", "8080"))