Skip to content

Commit 4797df9

Browse files
json upload files authentications, deletion and model validation
1 parent aa5b955 commit 4797df9

File tree

7 files changed

+5
-472
lines changed

7 files changed

+5
-472
lines changed

src/backend/.env.sample

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ AZURE_OPENAI_MODEL_NAME=gpt-4o
77
AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4o
88
AZURE_OPENAI_API_VERSION=2024-08-01-preview
99

10-
AZURE_SEARCH_ENDPOINT=
11-
AZURE_SEARCH_INDEX_NAME=
12-
1310
APPLICATIONINSIGHTS_INSTRUMENTATION_KEY=
1411
AZURE_AI_PROJECT_ENDPOINT=
1512
AZURE_AI_SUBSCRIPTION_ID=

src/backend/app_kernel.py

Lines changed: 2 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from services.json_service import JsonService
4343
from services.model_validation_service import ModelValidationService
4444
from services.search_validation_service import SearchValidationService
45-
from services.foundry_agent_service import FoundryAgentService
45+
4646

4747
# Updated import for KernelArguments
4848
from utils_kernel import initialize_runtime_and_context, rai_success, rai_validate_team_config
@@ -1629,160 +1629,6 @@ async def upload_team_config_endpoint(request: Request, file: UploadFile = File(
16291629
raise HTTPException(status_code=500, detail="Internal server error occurred")
16301630

16311631

1632-
@app.post("/api/upload_scenarios")
1633-
async def upload_scenarios_endpoint(request: Request, file: UploadFile = File(...)):
1634-
"""
1635-
Upload scenario data and create agents in Azure AI Foundry.
1636-
1637-
This endpoint processes a JSON file containing scenario definitions with agents,
1638-
validates the content using RAI checks, and creates the agents in Azure AI Foundry.
1639-
1640-
---
1641-
tags:
1642-
- Scenarios
1643-
parameters:
1644-
- name: user_principal_id
1645-
in: header
1646-
type: string
1647-
required: true
1648-
description: User ID extracted from the authentication header
1649-
- name: file
1650-
in: formData
1651-
type: file
1652-
required: true
1653-
description: JSON file containing scenario data with agents
1654-
responses:
1655-
200:
1656-
description: Scenarios processed and agents created successfully
1657-
schema:
1658-
type: object
1659-
properties:
1660-
status:
1661-
type: string
1662-
message:
1663-
type: string
1664-
results:
1665-
type: object
1666-
properties:
1667-
total_agents:
1668-
type: integer
1669-
created_count:
1670-
type: integer
1671-
failed_count:
1672-
type: integer
1673-
created_agents:
1674-
type: array
1675-
failed_agents:
1676-
type: array
1677-
400:
1678-
description: Invalid request, file format, or RAI validation failure
1679-
401:
1680-
description: Missing or invalid user information
1681-
500:
1682-
description: Internal server error
1683-
"""
1684-
# Validate user authentication
1685-
authenticated_user = get_authenticated_user_details(request_headers=request.headers)
1686-
user_id = authenticated_user["user_principal_id"]
1687-
if not user_id:
1688-
raise HTTPException(
1689-
status_code=401, detail="Missing or invalid user information"
1690-
)
1691-
1692-
# Validate file is provided and is JSON
1693-
if not file:
1694-
raise HTTPException(status_code=400, detail="No file provided")
1695-
1696-
if not file.filename.endswith(".json"):
1697-
raise HTTPException(status_code=400, detail="File must be a JSON file")
1698-
1699-
try:
1700-
# Read and parse JSON content
1701-
content = await file.read()
1702-
try:
1703-
scenario_data = json.loads(content.decode("utf-8"))
1704-
except json.JSONDecodeError as e:
1705-
raise HTTPException(
1706-
status_code=400, detail=f"Invalid JSON format: {str(e)}"
1707-
)
1708-
1709-
# Validate JSON structure
1710-
if not isinstance(scenario_data, dict):
1711-
raise HTTPException(
1712-
status_code=400, detail="JSON must contain a valid object"
1713-
)
1714-
1715-
if "scenarios" not in scenario_data:
1716-
raise HTTPException(
1717-
status_code=400, detail="JSON must contain a 'scenarios' array"
1718-
)
1719-
1720-
if not isinstance(scenario_data["scenarios"], list):
1721-
raise HTTPException(
1722-
status_code=400, detail="'scenarios' must be an array"
1723-
)
1724-
1725-
if not scenario_data["scenarios"]:
1726-
raise HTTPException(
1727-
status_code=400, detail="At least one scenario must be provided"
1728-
)
1729-
1730-
# Initialize the Foundry Agent Service
1731-
foundry_service = FoundryAgentService()
1732-
1733-
# Process scenarios and create agents in Foundry
1734-
success, message, results = await foundry_service.create_agents_from_scenarios(scenario_data)
1735-
1736-
# Track the event
1737-
track_event_if_configured(
1738-
"Scenario upload and agent creation",
1739-
{
1740-
"status": "success" if success else "partial_failure",
1741-
"user_id": user_id,
1742-
"filename": file.filename,
1743-
"total_agents": results.get("total_agents", 0),
1744-
"created_count": results.get("created_count", 0),
1745-
"failed_count": results.get("failed_count", 0),
1746-
},
1747-
)
1748-
1749-
if success:
1750-
return {
1751-
"status": "success",
1752-
"message": message,
1753-
"results": results
1754-
}
1755-
else:
1756-
# Partial failure or complete failure
1757-
if results.get("created_count", 0) > 0:
1758-
# Some agents were created successfully
1759-
return {
1760-
"status": "partial_success",
1761-
"message": message,
1762-
"results": results
1763-
}
1764-
else:
1765-
# Complete failure
1766-
raise HTTPException(status_code=400, detail=message)
1767-
1768-
except HTTPException:
1769-
# Re-raise HTTP exceptions
1770-
raise
1771-
except Exception as e:
1772-
# Log and return generic error for unexpected exceptions
1773-
logging.error(f"Unexpected error processing scenarios: {str(e)}")
1774-
track_event_if_configured(
1775-
"Scenario upload failed",
1776-
{
1777-
"status": "error",
1778-
"user_id": user_id,
1779-
"filename": file.filename,
1780-
"error": str(e),
1781-
},
1782-
)
1783-
raise HTTPException(status_code=500, detail="Internal server error occurred")
1784-
1785-
17861632
@app.get("/api/team_configs")
17871633
async def get_team_configs_endpoint(request: Request):
17881634
"""
@@ -2089,4 +1935,4 @@ async def get_search_indexes_endpoint(request: Request):
20891935
if __name__ == "__main__":
20901936
import uvicorn
20911937

2092-
uvicorn.run("app_kernel:app", host="127.0.0.1", port=8000, reload=True)
1938+
uvicorn.run("app_kernel:app", host="127.0.0.1", port=8000, reload=True)

src/backend/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
fastapi
22
uvicorn
3-
aiohttp
43

54
azure-cosmos
65
azure-monitor-opentelemetry

0 commit comments

Comments
 (0)