From b9cb25362b8a3678818ae43fd447a38ab4618aaa Mon Sep 17 00:00:00 2001 From: howieleung Date: Thu, 5 Jun 2025 14:50:32 -0700 Subject: [PATCH 1/3] Update instructions to better make use AI Search or File Search --- src/gunicorn.conf.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/gunicorn.conf.py b/src/gunicorn.conf.py index 3616ccb0..ed0cceb4 100644 --- a/src/gunicorn.conf.py +++ b/src/gunicorn.conf.py @@ -18,6 +18,7 @@ AzureAISearchTool, FilePurpose, FileSearchTool, + Tool, ) from azure.ai.projects.models import ConnectionType from azure.identity.aio import DefaultAzureCredential @@ -120,9 +121,9 @@ def _get_file_path(file_name: str) -> str: file_name)) -async def get_available_toolset( +async def get_available_tool( project_client: AIProjectClient, - creds: AsyncTokenCredential) -> AsyncToolSet: + creds: AsyncTokenCredential) -> Tool: """ Get the toolset and tool definition for the agent. @@ -145,11 +146,9 @@ async def get_available_toolset( if conn_id: await create_index_maybe(project_client, creds) - ai_search = AzureAISearchTool( + return AzureAISearchTool( index_connection_id=conn_id, index_name=os.environ.get('AZURE_AI_SEARCH_INDEX_NAME')) - - toolset.add(ai_search) else: logger.info( "agent: index was not initialized, falling back to file search.") @@ -169,21 +168,22 @@ async def get_available_toolset( ) logger.info("agent: file store and vector store success") - file_search_tool = FileSearchTool(vector_store_ids=[vector_store.id]) - toolset.add(file_search_tool) - - return toolset + return FileSearchTool(vector_store_ids=[vector_store.id]) async def create_agent(ai_client: AIProjectClient, creds: AsyncTokenCredential) -> Agent: logger.info("Creating new agent with resources") - toolset = await get_available_toolset(ai_client, creds) - + tool = await get_available_tool(ai_client, creds) + toolset = AsyncToolSet() + toolset.add(tool) + + instructions = "Use AI Search always. Avoid to use base knowledge." if isinstance(tool, AzureAISearchTool) else "Use File Search always. Avoid to use base knowledge." + agent = await ai_client.agents.create_agent( model=os.environ["AZURE_AI_AGENT_DEPLOYMENT_NAME"], name=os.environ["AZURE_AI_AGENT_NAME"], - instructions="You are helpful assistant", + instructions=instructions, toolset=toolset ) return agent From 1658df777b9d6e8973f1ed9b4ae960e9acd4cbea Mon Sep 17 00:00:00 2001 From: howieleung Date: Fri, 6 Jun 2025 10:51:45 -0700 Subject: [PATCH 2/3] Fix template validaiton --- scripts/resolve_model_quota.sh | 1 + scripts/set_default_models.sh | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/scripts/resolve_model_quota.sh b/scripts/resolve_model_quota.sh index 463ac8fd..965864a7 100644 --- a/scripts/resolve_model_quota.sh +++ b/scripts/resolve_model_quota.sh @@ -47,6 +47,7 @@ MissingParams=() [[ -z "$Location" ]] && MissingParams+=("location") [[ -z "$Model" ]] && MissingParams+=("model") [[ -z "$Capacity" ]] && MissingParams+=("capacity") +[[ -z "$Format" ]] && MissingParams+=("format") [[ -z "$DeploymentType" ]] && MissingParams+=("deployment-type") if [[ ${#MissingParams[@]} -gt 0 ]]; then diff --git a/scripts/set_default_models.sh b/scripts/set_default_models.sh index cfa07ff2..7fda3e56 100644 --- a/scripts/set_default_models.sh +++ b/scripts/set_default_models.sh @@ -3,8 +3,8 @@ set -e # --- Check Required Environment Variables --- -SubscriptionId="${AZURE_SUBSCRIPTION_ID}" -Location="${AZURE_LOCATION}" +SubscriptionId="${envVars[AZURE_SUBSCRIPTION_ID]}" +Location="${envVars[AZURE_LOCATION]}" Errors=0 @@ -57,12 +57,12 @@ if [ -n "$resourceId" ]; then fi # --- Build Chat Deployment --- -chatDeployment_name="${AZURE_AI_AGENT_DEPLOYMENT_NAME}" -chatDeployment_model_name="${AZURE_AI_AGENT_MODEL_NAME}" -chatDeployment_model_version="${AZURE_AI_AGENT_MODEL_VERSION}" -chatDeployment_model_format="${AZURE_AI_AGENT_MODEL_FORMAT}" -chatDeployment_sku_name="${AZURE_AI_AGENT_DEPLOYMENT_SKU}" -chatDeployment_capacity="${AZURE_AI_AGENT_DEPLOYMENT_CAPACITY}" +chatDeployment_name="${envVars[AZURE_AI_AGENT_DEPLOYMENT_NAME]}" +chatDeployment_model_name="${envVars[AZURE_AI_AGENT_MODEL_NAME]}" +chatDeployment_model_version="${envVars[AZURE_AI_AGENT_MODEL_VERSION]}" +chatDeployment_model_format="${envVars[AZURE_AI_AGENT_MODEL_FORMAT]}" +chatDeployment_sku_name="${envVars[AZURE_AI_AGENT_DEPLOYMENT_SKU]}" +chatDeployment_capacity="${envVars[AZURE_AI_AGENT_DEPLOYMENT_CAPACITY]}" chatDeployment_capacity_env="AZURE_AI_AGENT_DEPLOYMENT_CAPACITY" aiModelDeployments=( @@ -71,12 +71,12 @@ aiModelDeployments=( # --- Optional Embed Deployment --- if [ "$USE_AZURE_AI_SEARCH_SERVICE" == "true" ]; then - embedDeployment_name="${AZURE_AI_EMBED_DEPLOYMENT_NAME}" - embedDeployment_model_name="${AZURE_AI_EMBED_MODEL_NAME}" - embedDeployment_model_version="${AZURE_AI_EMBED_MODEL_VERSION}" - embedDeployment_model_format="${AZURE_AI_EMBED_MODEL_FORMAT}" - embedDeployment_sku_name="${AZURE_AI_EMBED_DEPLOYMENT_SKU}" - embedDeployment_capacity="${AZURE_AI_EMBED_DEPLOYMENT_CAPACITY}" + embedDeployment_name="${envVars[AZURE_AI_EMBED_DEPLOYMENT_NAME]}" + embedDeployment_model_name="${envVars[AZURE_AI_EMBED_MODEL_NAME]}" + embedDeployment_model_version="${envVars[AZURE_AI_EMBED_MODEL_VERSION]}" + embedDeployment_model_format="${envVars[AZURE_AI_EMBED_MODEL_FORMAT]}" + embedDeployment_sku_name="${envVars[AZURE_AI_EMBED_DEPLOYMENT_SKU]}" + embedDeployment_capacity="${envVars[AZURE_AI_EMBED_DEPLOYMENT_CAPACITY]}" embedDeployment_capacity_env="AZURE_AI_EMBED_DEPLOYMENT_CAPACITY" aiModelDeployments+=( From a9414604c06d6029e683746f7c200c330c776f44 Mon Sep 17 00:00:00 2001 From: howieleung Date: Fri, 6 Jun 2025 16:00:33 -0700 Subject: [PATCH 3/3] fixed more --- infra/core/ai/cognitiveservices.bicep | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/infra/core/ai/cognitiveservices.bicep b/infra/core/ai/cognitiveservices.bicep index 3a7ffae1..2fc625e7 100644 --- a/infra/core/ai/cognitiveservices.bicep +++ b/infra/core/ai/cognitiveservices.bicep @@ -5,7 +5,7 @@ param location string = resourceGroup().location param tags object = {} @description('The custom subdomain name used to access the API. Defaults to the value of the name parameter.') param customSubDomainName string = aiServiceName -param disableLocalAuth bool = false +param disableLocalAuth bool = true param deployments array = [] param appInsightsId string param appInsightConnectionString string @@ -51,16 +51,13 @@ resource aiServiceConnection 'Microsoft.CognitiveServices/accounts/connections@2 parent: account properties: { category: 'AzureOpenAI' - authType: 'ApiKey' + authType: 'AAD' isSharedToAll: true target: account.properties.endpoints['OpenAI Language Model Instance API'] metadata: { ApiType: 'azure' ResourceId: account.id } - credentials: { - key: account.listKeys().key1 - } } }