-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
49 lines (41 loc) · 1.46 KB
/
main.py
File metadata and controls
49 lines (41 loc) · 1.46 KB
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
from fastapi import FastAPI, Depends, HTTPException, status
from sqlalchemy.orm import Session
from database import engine, get_db, Base
from models import Agent
from schemas import AgentCreate, RegisterResponse, AgentResponse
from auth import get_current_agent
# Initialize database
Base.metadata.create_all(bind=engine)
app = FastAPI(title="Supa Guru AI Agent Management API", version="1.0.0")
@app.post("/api/v1/agents/register", response_model=RegisterResponse)
def register_agent(agent_in: AgentCreate, db: Session = Depends(get_db)):
# Check if agent name already exists
existing_agent = db.query(Agent).filter(Agent.name == agent_in.name).first()
if existing_agent:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Agent with this name already exists"
)
# Create new agent
new_agent = Agent(
name=agent_in.name,
display_name=agent_in.display_name,
description=agent_in.description
)
db.add(new_agent)
db.commit()
db.refresh(new_agent)
return {
"success": True,
"agent": new_agent,
"api_key": new_agent.api_key
}
@app.get("/api/v1/agents/me", response_model=AgentResponse)
def get_my_profile(current_agent: Agent = Depends(get_current_agent)):
return {
"success": True,
"agent": current_agent
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)