Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 12 additions & 41 deletions src/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
from azure.ai.projects.models import AgentVersionObject, AgentReference
from openai.types.conversations.message import Message
from openai.types.responses import Response, ResponseOutputText, ResponseOutputMessage, ResponseInputText, ResponseInputMessageItem
from openai.types.responses import ResponseOutputMessage
from openai.types.conversations import Conversation
from openai.types.responses.response_output_text import AnnotationFileCitation

from azure.ai.projects.aio import AIProjectClient

from openai.types.responses import ResponseTextDeltaEvent, ResponseCompletedEvent, ResponseTextDoneEvent, ResponseCreatedEvent, ResponseOutputItemDoneEvent
from util import encode_project_resource_id

from urllib.parse import quote


from openai import AsyncOpenAI

Expand Down Expand Up @@ -289,7 +291,13 @@ async def history(
async def get_chat_agent(
agent: AgentVersionObject = Depends(get_agent_version_obj),
):
return JSONResponse(content={"name": agent.name, "metadata": agent.metadata})
wsid = os.environ.get("AZURE_EXISTING_AIPROJECT_RESOURCE_ID")
agent_id = os.environ.get("AZURE_EXISTING_AGENT_ID")
agent_name = agent_id.split(":")[0]
agent_version = agent_id.split(":")[1]
agent_playground_url = f"https://ai.azure.com/nextgen/r/{encode_project_resource_id(wsid)}/build/agents/{quote(agent_name)}/build?version={agent_version}"
return JSONResponse(content={"name": agent.name, "metadata": agent.metadata, "agentPlaygroundUrl": agent_playground_url})


@router.post("/chat")
async def chat(
Expand Down Expand Up @@ -338,40 +346,3 @@ async def chat(
response.set_cookie("conversation_id", conversation_id)
response.set_cookie("agent_id", agent_id)
return response

def read_file(path: str) -> str:
with open(path, 'r') as file:
return file.read()

@router.get("/config/azure")
async def get_azure_config(_ = auth_dependency):
"""Get Azure configuration for frontend use"""
try:
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "")
tenant_id = os.environ.get("AZURE_TENANT_ID", "")
resource_group = os.environ.get("AZURE_RESOURCE_GROUP", "")
ai_project_resource_id = os.environ.get("AZURE_EXISTING_AIPROJECT_RESOURCE_ID", "")

# Extract resource name and project name from the resource ID
# Format: /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.CognitiveServices/accounts/{resource}/projects/{project}
resource_name = ""
project_name = ""

if ai_project_resource_id:
parts = ai_project_resource_id.split("/")
if len(parts) >= 8:
resource_name = parts[8] # accounts/{resource_name}
if len(parts) >= 10:
project_name = parts[10] # projects/{project_name}

return JSONResponse({
"subscriptionId": subscription_id,
"tenantId": tenant_id,
"resourceGroup": resource_group,
"resourceName": resource_name,
"projectName": project_name,
"wsid": ai_project_resource_id
})
except Exception as e:
logger.error(f"Error getting Azure config: {e}")
raise HTTPException(status_code=500, detail="Failed to get Azure configuration")
3 changes: 3 additions & 0 deletions src/frontend/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const App: React.FC = () => {
metadata: {
logo: "robot",
},
agentPlaygroundUrl: "",
});

// Fetch agent details when component mounts
Expand Down Expand Up @@ -52,6 +53,7 @@ const App: React.FC = () => {
metadata: {
logo: "robot",
},
agentPlaygroundUrl: "",
});
}
} catch (error) {
Expand All @@ -67,6 +69,7 @@ const App: React.FC = () => {
metadata: {
logo: "robot",
},
agentPlaygroundUrl: "",
});
}
};
Expand Down
11 changes: 7 additions & 4 deletions src/frontend/src/components/agents/AgentPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import { AgentPreviewChatBot } from "./AgentPreviewChatBot";
import { MenuButton } from "../core/MenuButton/MenuButton";
import { IChatItem } from "./chatbot/types";
import { Waves } from "./Waves";
/* temporarily disable BuiltWithBadge */
// import { BuiltWithBadge } from "./BuiltWithBadge";
import { BuiltWithBadge } from "./BuiltWithBadge";

import styles from "./AgentPreview.module.css";

Expand All @@ -39,6 +38,7 @@ interface IAgent {
};
metadata?: Record<string, any>;
response_format?: "auto" | string;
agentPlaygroundUrl: string;
}

interface IAgentPreviewProps {
Expand Down Expand Up @@ -601,8 +601,11 @@ export function AgentPreview({ agentDetails }: IAgentPreviewProps): ReactNode {
)}
</div>

{/* temporarily disable BuiltWithBadge */}
{/* <BuiltWithBadge className={styles.builtWithBadge} /> */}
{agentDetails.agentPlaygroundUrl && agentDetails.agentPlaygroundUrl.length > 0 ? (
<BuiltWithBadge className={styles.builtWithBadge} agentPlaygroundUrl={agentDetails.agentPlaygroundUrl} />
) : (
<></>
)}
</div>

{/* Settings Panel */}
Expand Down
42 changes: 4 additions & 38 deletions src/frontend/src/components/agents/BuiltWithBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,21 @@
import { ReactNode, useEffect, useState } from "react";
import { ReactNode } from "react";
import { Caption1Strong } from "@fluentui/react-components";
import { ArrowRight16Filled } from "@fluentui/react-icons";
import clsx from "clsx";

import { AIFoundryLogo } from "../icons/AIFoundryLogo";
import styles from "./BuiltWithBadge.module.css";

interface AzureConfig {
subscriptionId: string;
tenantId: string;
resourceGroup: string;
resourceName: string;
projectName: string;
wsid: string;
}

export function BuiltWithBadge({
className,
agentPlaygroundUrl
}: {
className?: string;
agentPlaygroundUrl?: string;
}): ReactNode {
const [azureConfig, setAzureConfig] = useState<AzureConfig | null>(null);

useEffect(() => {
const fetchAzureConfig = async () => {
try {
const response = await fetch("/config/azure");
if (response.ok) {
const config = await response.json();
setAzureConfig(config);
} else {
console.error("Failed to fetch Azure configuration");
}
} catch (error) {
console.error("Error fetching Azure configuration:", error);
}
};

fetchAzureConfig();
}, []);

const handleClick = () => {
if (azureConfig) {
const { wsid, tenantId } = azureConfig;
const azureAiUrl = `https://ai.azure.com/resource/agentsList?wsid=${encodeURIComponent(
wsid
)}&tid=${tenantId}`;
window.open(azureAiUrl, "_blank");
} else {
console.log("Azure configuration not available");
}
window.open(agentPlaygroundUrl, "_blank");
};
return (
<button
Expand Down
Loading