mirror of
https://github.com/microsoft/autogen.git
synced 2025-07-08 17:43:40 +00:00

<!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> <!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. --> ## Why are these changes needed? Add support for default model client, in AGS updates to settings UI. A default model client will be used for subsequent background tasks (e.g, automatically naming sessions to meaningful names). <img width="1441" alt="image" src="https://github.com/user-attachments/assets/31675ef4-8f80-4a8c-9762-3d6bcbc6d33d" /> <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> Closes #5685 ## Checks - [ ] I've included any doc changes needed for <https://microsoft.github.io/autogen/>. See <https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md> to build and test documentation locally. - [ ] I've added tests (if relevant) corresponding to the changes introduced in this PR. - [ ] I've made sure all auto checks have passed.
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
# api/routes/settings.py
|
|
from typing import Dict
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
|
|
from ...datamodel import Settings, SettingsConfig
|
|
from ..deps import get_db
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/")
|
|
async def get_settings(user_id: str, db=Depends(get_db)) -> Dict:
|
|
try:
|
|
response = db.get(Settings, filters={"user_id": user_id})
|
|
if not response.status or not response.data:
|
|
# create a default settings
|
|
config = SettingsConfig()
|
|
default_settings = Settings(user_id=user_id, config=config.model_dump())
|
|
db.upsert(default_settings)
|
|
response = db.get(Settings, filters={"user_id": user_id})
|
|
# print(response.data[0])
|
|
return {"status": True, "data": response.data[0]}
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=str(e)) from e
|
|
|
|
|
|
@router.put("/")
|
|
async def update_settings(settings: Settings, db=Depends(get_db)) -> Dict:
|
|
response = db.upsert(settings)
|
|
if not response.status:
|
|
raise HTTPException(status_code=400, detail=response.message)
|
|
return {"status": True, "data": response.data}
|