You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
657 B
24 lines
657 B
2 years ago
|
from fastapi import FastAPI, HTTPException
|
||
|
from swarms.swarms import swarm
|
||
|
from pydantic import BaseModel
|
||
|
|
||
|
app = FastAPI()
|
||
|
|
||
|
class SwarmInput(BaseModel):
|
||
|
api_key: set
|
||
|
objective: str
|
||
|
|
||
|
|
||
|
@app.post("/chat")
|
||
|
async def run_swarms(swarm_input: SwarmInput):
|
||
|
try:
|
||
|
results = swarm(swarm_input.api_key, swarm_input.objective)
|
||
|
if not results:
|
||
|
raise HTTPException(status_code=500, detaile="Failed to run swarms")
|
||
|
return {"results": results}
|
||
|
except ValueError as ve:
|
||
|
raise HTTPException(status_code=400, detail=str(ve))
|
||
|
except Exception as e:
|
||
|
raise HTTPException(status_code=500, detail=str(e))
|
||
|
|