Victor Dibia 8f8ee0478a
AGS - Test Model Component in UI, Compare Sessions (#5963)
<!-- 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?

- Adds ability to test model clients in UI after configrations, before
they are used in agents or teams
- Adds UI side by side comparison of sessions
<img width="1878" alt="image"
src="https://github.com/user-attachments/assets/f792d8d6-3f5d-4d8c-a365-5a9e9c00f49e"
/>
<img width="1877" alt="image"
src="https://github.com/user-attachments/assets/5a115a5a-95e1-4956-a733-5f0065711fe3"
/>


<!-- Please give a short summary of the change and the problem this
solves. -->

## Related issue number

<!-- For example: "Closes #1234" -->

Closes #4273 
Closes #5728

## 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.
2025-03-17 11:00:46 -07:00

72 lines
2.8 KiB
Python

# api/routes/gallery.py
from fastapi import APIRouter, Depends, HTTPException
from ...database import DatabaseManager
from ...datamodel import Gallery, Response
from ...gallery.builder import create_default_gallery
from ..deps import get_db
router = APIRouter()
@router.put("/{gallery_id}")
async def update_gallery_entry(
gallery_id: int, gallery_data: Gallery, user_id: str, db: DatabaseManager = Depends(get_db)
) -> Response:
# Check ownership first
result = db.get(Gallery, filters={"id": gallery_id})
if not result.status or not result.data:
raise HTTPException(status_code=404, detail="Gallery entry not found")
if result.data[0].user_id != user_id:
raise HTTPException(status_code=403, detail="Not authorized to update this gallery entry")
# Update if authorized
gallery_data.id = gallery_id # Ensure ID matches
gallery_data.user_id = user_id # Ensure user_id matches
return db.upsert(gallery_data)
@router.post("/")
async def create_gallery_entry(gallery_data: Gallery, db: DatabaseManager = Depends(get_db)) -> Response:
response = db.upsert(gallery_data)
if not response.status:
raise HTTPException(status_code=400, detail=response.message)
return response
@router.get("/")
async def list_gallery_entries(user_id: str, db: DatabaseManager = Depends(get_db)) -> Response:
try:
result = db.get(Gallery, filters={"user_id": user_id})
if not result.data or len(result.data) == 0:
# create a default gallery entry
gallery_config = create_default_gallery()
default_gallery = Gallery(user_id=user_id, config=gallery_config.model_dump())
db.upsert(default_gallery)
result = db.get(Gallery, filters={"user_id": user_id})
return result
except Exception as e:
return Response(status=False, data=[], message=f"Error retrieving gallery entries: {str(e)}")
@router.get("/{gallery_id}")
async def get_gallery_entry(gallery_id: int, user_id: str, db: DatabaseManager = Depends(get_db)) -> Response:
result = db.get(Gallery, filters={"id": gallery_id, "user_id": user_id})
if not result.status or not result.data:
raise HTTPException(status_code=404, detail="Gallery entry not found")
return Response(status=result.status, data=result.data[0], message=result.message)
@router.delete("/{gallery_id}")
async def delete_gallery_entry(gallery_id: int, user_id: str, db: DatabaseManager = Depends(get_db)) -> Response:
# Check ownership first
result = db.get(Gallery, filters={"id": gallery_id, "user_id": user_id})
if not result.status or not result.data:
raise HTTPException(status_code=404, detail="Gallery entry not found")
response = db.delete(Gallery, filters={"id": gallery_id})
# Delete if authorized
return response