Skip to content

Commit 1290101

Browse files
committed
Optional storage string
1 parent a5c5bea commit 1290101

File tree

3 files changed

+14
-39
lines changed

3 files changed

+14
-39
lines changed

evals/safety_evaluation.py

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import argparse
22
import asyncio
3+
import json
34
import logging
45
import os
56
import pathlib
67
from enum import Enum
7-
from typing import Any, Optional
88

99
import requests
1010
from azure.ai.evaluation import ContentSafetyEvaluator
@@ -48,36 +48,15 @@ def get_azure_credential():
4848

4949
async def callback(
5050
messages: list[dict],
51-
stream: bool = False,
52-
session_state: Any = None,
53-
context: Optional[dict[str, Any]] = None,
5451
target_url: str = "http://127.0.0.1:8000/chat",
5552
):
5653
messages_list = messages["messages"]
57-
latest_message = messages_list[-1]
58-
query = latest_message["content"]
54+
query = messages_list[-1]["content"]
5955
headers = {"Content-Type": "application/json"}
6056
body = {
6157
"messages": [{"content": query, "role": "user"}],
62-
"stream": stream,
63-
"context": {
64-
"overrides": {
65-
"top": 3,
66-
"temperature": 0.3,
67-
"minimum_reranker_score": 0,
68-
"minimum_search_score": 0,
69-
"retrieval_mode": "hybrid",
70-
"semantic_ranker": True,
71-
"semantic_captions": False,
72-
"suggest_followup_questions": False,
73-
"use_oid_security_filter": False,
74-
"use_groups_security_filter": False,
75-
"vector_fields": ["embedding"],
76-
"use_gpt4v": False,
77-
"gpt4v_input": "textAndImages",
78-
"seed": 1,
79-
}
80-
},
58+
"stream": False,
59+
"context": {"overrides": {"use_advanced_flow": True, "top": 3, "retrieval_mode": "hybrid", "temperature": 0.3}},
8160
}
8261
url = target_url
8362
r = requests.post(url, headers=headers, json=body)
@@ -86,8 +65,7 @@ async def callback(
8665
message = {"content": response["error"], "role": "assistant"}
8766
else:
8867
message = response["message"]
89-
response["messages"] = messages_list + [message]
90-
return response
68+
return {"messages": messages_list + [message]}
9169

9270

9371
async def run_simulator(target_url: str, max_simulations: int):
@@ -104,9 +82,7 @@ async def run_simulator(target_url: str, max_simulations: int):
10482

10583
outputs = await adversarial_simulator(
10684
scenario=scenario,
107-
target=lambda messages, stream=False, session_state=None, context=None: callback(
108-
messages, stream, session_state, context, target_url
109-
),
85+
target=lambda messages, stream=False, session_state=None, context=None: callback(messages, target_url),
11086
max_simulation_results=max_simulations,
11187
language=SupportedLanguages.English, # Match this to your app language
11288
randomization_seed=1, # For more consistent results, use a fixed seed
@@ -139,10 +115,9 @@ async def run_simulator(target_url: str, max_simulations: int):
139115
else:
140116
summary_scores[evaluator]["mean_score"] = 0
141117
summary_scores[evaluator]["low_rate"] = 0
118+
142119
# Save summary scores
143120
with open(root_dir / "safety_results.json", "w") as f:
144-
import json
145-
146121
json.dump(summary_scores, f, indent=2)
147122

148123

infra/core/ai/ai-environment.bicep

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ param location string
66
param hubName string
77
@description('The AI Project resource name.')
88
param projectName string
9-
//@description('The Storage Account resource ID.')
10-
//param storageAccountId string
9+
@description('The Storage Account resource ID.')
10+
param storageAccountId string = ''
1111
@description('The Application Insights resource ID.')
1212
param applicationInsightsId string = ''
1313
@description('The Azure Search resource name.')
@@ -23,7 +23,7 @@ module hub './hub.bicep' = {
2323
tags: tags
2424
name: hubName
2525
displayName: hubName
26-
//storageAccountId: storageAccountId
26+
storageAccountId: storageAccountId
2727
containerRegistryId: null
2828
applicationInsightsId: applicationInsightsId
2929
aiSearchName: searchServiceName

infra/core/ai/hub.bicep

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
param name string
33
@description('The display name of the AI Foundry Hub Resource')
44
param displayName string = name
5-
//@description('The storage account ID to use for the AI Foundry Hub Resource')
6-
//param storageAccountId string
5+
@description('The storage account ID to use for the AI Foundry Hub Resource')
6+
param storageAccountId string = ''
77

88
@description('The application insights ID to use for the AI Foundry Hub Resource')
99
param applicationInsightsId string = ''
@@ -13,7 +13,7 @@ param containerRegistryId string = ''
1313
@description('The Azure Cognitive Search service name to use for the AI Foundry Hub Resource')
1414
param aiSearchName string = ''
1515
@description('The Azure Cognitive Search service connection name to use for the AI Foundry Hub Resource')
16-
param aiSearchConnectionName string
16+
param aiSearchConnectionName string = ''
1717

1818

1919
@description('The SKU name to use for the AI Foundry Hub Resource')
@@ -42,7 +42,7 @@ resource hub 'Microsoft.MachineLearningServices/workspaces@2024-07-01-preview' =
4242
}
4343
properties: {
4444
friendlyName: displayName
45-
//storageAccount: storageAccountId
45+
storageAccount: !empty(storageAccountId) ? storageAccountId : null
4646
applicationInsights: !empty(applicationInsightsId) ? applicationInsightsId : null
4747
containerRegistry: !empty(containerRegistryId) ? containerRegistryId : null
4848
hbiWorkspace: false

0 commit comments

Comments
 (0)