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? - 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.
38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
# api/routes/validation.py
|
|
|
|
from fastapi import APIRouter
|
|
|
|
from ...validation.component_test_service import ComponentTestRequest, ComponentTestResult, ComponentTestService
|
|
from ...validation.validation_service import ValidationError, ValidationRequest, ValidationResponse, ValidationService
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post("/")
|
|
async def validate_component(request: ValidationRequest) -> ValidationResponse:
|
|
"""Validate a component configuration"""
|
|
try:
|
|
return ValidationService.validate(request.component)
|
|
except Exception as e:
|
|
return ValidationResponse(
|
|
is_valid=False, errors=[ValidationError(field="validation", error=str(e))], warnings=[]
|
|
)
|
|
|
|
|
|
@router.post("/test")
|
|
async def test_component(request: ComponentTestRequest) -> ComponentTestResult:
|
|
"""Test a component functionality with appropriate inputs based on type"""
|
|
# First validate the component configuration
|
|
validation_result = ValidationService.validate(request.component)
|
|
|
|
# Only proceed with testing if the component is valid
|
|
if not validation_result.is_valid:
|
|
return ComponentTestResult(
|
|
status=False, message="Component validation failed", logs=[e.error for e in validation_result.errors]
|
|
)
|
|
|
|
# If validation passed, run the functional test
|
|
return await ComponentTestService.test_component(
|
|
component=request.component, timeout=request.timeout if request.timeout else 60
|
|
)
|