|
1 | 1 | # <deploy>
|
2 | 2 | import os
|
3 | 3 | from dotenv import load_dotenv
|
| 4 | + |
4 | 5 | load_dotenv()
|
5 | 6 |
|
6 | 7 | from azure.ai.ml import MLClient
|
7 | 8 | from azure.identity import DefaultAzureCredential
|
8 |
| -from azure.ai.ml.entities import ManagedOnlineEndpoint, ManagedOnlineDeployment, Model, Environment, BuildContext |
| 9 | +from azure.ai.ml.entities import ( |
| 10 | + ManagedOnlineEndpoint, |
| 11 | + ManagedOnlineDeployment, |
| 12 | + Model, |
| 13 | + Environment, |
| 14 | + BuildContext, |
| 15 | +) |
9 | 16 |
|
10 |
| -client = MLClient(DefaultAzureCredential(), os.getenv("AZURE_SUBSCRIPTION_ID"), os.getenv("AZURE_RESOURCE_GROUP"), os.getenv("AZUREAI_PROJECT_NAME")) |
11 |
| -endpoint_name = "tutorial-endpoint" |
| 17 | +client = MLClient( |
| 18 | + DefaultAzureCredential(), |
| 19 | + os.getenv("AZURE_SUBSCRIPTION_ID"), |
| 20 | + os.getenv("AZURE_RESOURCE_GROUP"), |
| 21 | + os.getenv("AZUREAI_PROJECT_NAME"), |
| 22 | +) |
| 23 | +endpoint_name = "tutorial-endpoint" |
12 | 24 | deployment_name = "tutorial-deployment"
|
13 | 25 |
|
14 | 26 | endpoint = ManagedOnlineEndpoint(
|
15 | 27 | name=endpoint_name,
|
16 | 28 | properties={
|
17 |
| - "enforce_access_to_default_secret_stores": "enabled" # for secret injection support |
| 29 | + "enforce_access_to_default_secret_stores": "enabled" # for secret injection support |
18 | 30 | },
|
19 |
| - auth_mode="aad_token" # using aad auth instead of key-based auth |
| 31 | + auth_mode="aad_token", # using aad auth instead of key-based auth |
20 | 32 | )
|
21 | 33 |
|
22 | 34 | # Get the directory of the current script
|
|
29 | 41 | endpoint_name=endpoint_name,
|
30 | 42 | model=Model(
|
31 | 43 | name="copilot_flow_model",
|
32 |
| - path=copilot_path, # path to promptflow folder |
33 |
| - properties=[ # this enables the chat interface in the endpoint test tab |
| 44 | + path=copilot_path, # path to promptflow folder |
| 45 | + properties=[ # this enables the chat interface in the endpoint test tab |
34 | 46 | ["azureml.promptflow.source_flow_id", "basic-chat"],
|
35 | 47 | ["azureml.promptflow.mode", "chat"],
|
36 | 48 | ["azureml.promptflow.chat_input", "chat_input"],
|
37 |
| - ["azureml.promptflow.chat_output", "reply"] |
38 |
| - ] |
| 49 | + ["azureml.promptflow.chat_output", "reply"], |
| 50 | + ], |
39 | 51 | ),
|
40 | 52 | environment=Environment(
|
41 | 53 | build=BuildContext(
|
|
50 | 62 | "path": "/health",
|
51 | 63 | "port": 8080,
|
52 | 64 | },
|
53 |
| - "scoring_route":{ |
| 65 | + "scoring_route": { |
54 | 66 | "path": "/score",
|
55 | 67 | "port": 8080,
|
56 | 68 | },
|
|
60 | 72 | instance_count=1,
|
61 | 73 | environment_variables={
|
62 | 74 | "PRT_CONFIG_OVERRIDE": f"deployment.subscription_id={client.subscription_id},deployment.resource_group={client.resource_group_name},deployment.workspace_name={client.workspace_name},deployment.endpoint_name={endpoint_name},deployment.deployment_name={deployment_name}",
|
63 |
| - 'AZURE_OPENAI_ENDPOINT': os.getenv('AZURE_OPENAI_ENDPOINT'), |
64 |
| - 'AZURE_SEARCH_ENDPOINT': os.getenv('AZURE_SEARCH_ENDPOINT'), |
65 |
| - 'AZURE_OPENAI_API_VERSION': os.getenv('AZURE_OPENAI_API_VERSION'), |
66 |
| - 'AZURE_OPENAI_CHAT_DEPLOYMENT': os.getenv('AZURE_OPENAI_CHAT_DEPLOYMENT'), |
67 |
| - 'AZURE_OPENAI_EVALUATION_DEPLOYMENT': os.getenv('AZURE_OPENAI_EVALUATION_DEPLOYMENT'), |
68 |
| - 'AZURE_OPENAI_EMBEDDING_DEPLOYMENT': os.getenv('AZURE_OPENAI_EMBEDDING_DEPLOYMENT'), |
69 |
| - 'AZUREAI_SEARCH_INDEX_NAME': os.getenv('AZUREAI_SEARCH_INDEX_NAME') |
70 |
| - } |
| 75 | + "AZURE_OPENAI_ENDPOINT": os.getenv("AZURE_OPENAI_ENDPOINT"), |
| 76 | + "AZURE_SEARCH_ENDPOINT": os.getenv("AZURE_SEARCH_ENDPOINT"), |
| 77 | + "AZURE_OPENAI_API_VERSION": os.getenv("AZURE_OPENAI_API_VERSION"), |
| 78 | + "AZURE_OPENAI_CHAT_DEPLOYMENT": os.getenv("AZURE_OPENAI_CHAT_DEPLOYMENT"), |
| 79 | + "AZURE_OPENAI_EVALUATION_DEPLOYMENT": os.getenv( |
| 80 | + "AZURE_OPENAI_EVALUATION_DEPLOYMENT" |
| 81 | + ), |
| 82 | + "AZURE_OPENAI_EMBEDDING_DEPLOYMENT": os.getenv( |
| 83 | + "AZURE_OPENAI_EMBEDDING_DEPLOYMENT" |
| 84 | + ), |
| 85 | + "AZUREAI_SEARCH_INDEX_NAME": os.getenv("AZUREAI_SEARCH_INDEX_NAME"), |
| 86 | + }, |
71 | 87 | )
|
72 | 88 |
|
73 | 89 | # 1. create endpoint
|
74 |
| -created_endpoint = client.begin_create_or_update(endpoint).result() # result() means we wait on this to complete |
| 90 | +created_endpoint = client.begin_create_or_update( |
| 91 | + endpoint |
| 92 | +).result() # result() means we wait on this to complete |
75 | 93 |
|
76 | 94 | # 2. create deployment
|
77 | 95 | created_deployment = client.begin_create_or_update(deployment).result()
|
78 | 96 |
|
79 | 97 | # 3. update endpoint traffic for the deployment
|
80 |
| -endpoint.traffic = {deployment_name: 100} # 100% of traffic |
| 98 | +endpoint.traffic = {deployment_name: 100} # 100% of traffic |
81 | 99 | client.begin_create_or_update(endpoint).result()
|
82 | 100 | # </deploy>
|
83 | 101 |
|
84 | 102 | # <report>
|
85 |
| -def get_ai_studio_url_for_deploy(client: MLClient, endpoint_name: str, deployment_name) -> str: |
| 103 | +def get_ai_studio_url_for_deploy( |
| 104 | + client: MLClient, endpoint_name: str, deployment_name |
| 105 | +) -> str: |
86 | 106 | studio_base_url = "https://ai.azure.com"
|
87 |
| - deployment_url = ( |
88 |
| - f"{studio_base_url}/projectdeployments/realtime/{endpoint_name}/{deployment_name}/detail?wsid=/subscriptions/{client.subscription_id}/resourceGroups/{client.resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{client.workspace_name}&deploymentName={deployment_name}" |
89 |
| - ) |
| 107 | + deployment_url = f"{studio_base_url}/projectdeployments/realtime/{endpoint_name}/{deployment_name}/detail?wsid=/subscriptions/{client.subscription_id}/resourceGroups/{client.resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{client.workspace_name}&deploymentName={deployment_name}" |
90 | 108 |
|
91 | 109 | return deployment_url
|
92 | 110 |
|
| 111 | + |
93 | 112 | print("\n ~~~Deployment details~~~")
|
94 | 113 | print(f"Your online endpoint name is: {endpoint_name}")
|
95 | 114 | print(f"Your deployment name is: {deployment_name}")
|
96 | 115 |
|
97 | 116 | print("\n ~~~Test in the Azure AI Studio~~~")
|
98 | 117 | print("\n Follow this link to your deployment in the Azure AI Studio:")
|
99 |
| -print(get_ai_studio_url_for_deploy(client=client, endpoint_name=endpoint_name, deployment_name=deployment_name)) |
| 118 | +print( |
| 119 | + get_ai_studio_url_for_deploy( |
| 120 | + client=client, endpoint_name=endpoint_name, deployment_name=deployment_name |
| 121 | + ) |
| 122 | +) |
100 | 123 | # </report>
|
0 commit comments