Skip to content

Commit 8662358

Browse files
New API endpoint that allows creating or updating assistants
1 parent 3321226 commit 8662358

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

routers/assistants.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from fastapi import APIRouter, Depends
2+
from openai import AsyncOpenAI
3+
from utils.create_assistant import create_or_update_assistant, request
4+
import logging
5+
import os
6+
from dotenv import load_dotenv
7+
8+
# Configure logger
9+
logger = logging.getLogger("uvicorn.error")
10+
11+
# Load environment variables
12+
load_dotenv()
13+
14+
router = APIRouter(
15+
prefix="/assistants",
16+
tags=["assistants"]
17+
)
18+
19+
20+
@router.post("/create-update")
21+
async def create_update_assistant(
22+
client: AsyncOpenAI = Depends(lambda: AsyncOpenAI())
23+
):
24+
"""
25+
Create a new assistant or update an existing one.
26+
Returns the assistant ID and status of the operation.
27+
"""
28+
assistant_id = os.getenv("ASSISTANT_ID")
29+
30+
assistant_id: str = await create_or_update_assistant(
31+
client=client,
32+
assistant_id=assistant_id,
33+
request=request,
34+
logger=logger
35+
)
36+
37+
return {
38+
"message": f"Assistant {assistant_id} successfully created/updated"
39+
}

0 commit comments

Comments
 (0)