@@ -68,13 +68,13 @@ def deploy_flow(endpoint_name, deployment_name):
68
68
"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 } " ,
69
69
# the following is enabled by secret injection
70
70
# make sure your environment variables here match the environment variables your code depends on
71
- 'AZURE_OPENAI_ENDPOINT' : os .getenv ( 'AZURE_OPENAI_ENDPOINT' ) ,
72
- 'AZURE_SEARCH_ENDPOINT' : os .getenv ( 'AZURE_SEARCH_ENDPOINT' ) ,
73
- 'AZURE_OPENAI_API_VERSION' : os .getenv ( 'AZURE_OPENAI_API_VERSION' ) ,
74
- 'AZURE_OPENAI_CHAT_DEPLOYMENT' : os .getenv ( 'AZURE_OPENAI_CHAT_DEPLOYMENT' ) ,
75
- 'AZURE_OPENAI_EVALUATION_DEPLOYMENT' : os .getenv ( 'AZURE_OPENAI_EVALUATION_DEPLOYMENT' ) ,
76
- 'AZURE_OPENAI_EMBEDDING_DEPLOYMENT' : os .getenv ( 'AZURE_OPENAI_EMBEDDING_DEPLOYMENT' ) ,
77
- 'AZUREAI_SEARCH_INDEX_NAME' : os .getenv ( 'AZUREAI_SEARCH_INDEX_NAME' )
71
+ 'AZURE_OPENAI_ENDPOINT' : os .environ [ 'AZURE_OPENAI_ENDPOINT' ] ,
72
+ 'AZURE_SEARCH_ENDPOINT' : os .environ [ 'AZURE_SEARCH_ENDPOINT' ] ,
73
+ 'AZURE_OPENAI_API_VERSION' : os .environ [ 'AZURE_OPENAI_API_VERSION' ] ,
74
+ 'AZURE_OPENAI_CHAT_DEPLOYMENT' : os .environ [ 'AZURE_OPENAI_CHAT_DEPLOYMENT' ] ,
75
+ 'AZURE_OPENAI_EVALUATION_DEPLOYMENT' : os .environ [ 'AZURE_OPENAI_EVALUATION_DEPLOYMENT' ] ,
76
+ 'AZURE_OPENAI_EMBEDDING_DEPLOYMENT' : os .environ [ 'AZURE_OPENAI_EMBEDDING_DEPLOYMENT' ] ,
77
+ 'AZUREAI_SEARCH_INDEX_NAME' : os .environ [ 'AZUREAI_SEARCH_INDEX_NAME' ]
78
78
}
79
79
)
80
80
@@ -90,20 +90,23 @@ def deploy_flow(endpoint_name, deployment_name):
90
90
91
91
# 4. provide endpoint access to Azure Open AI resource
92
92
create_role_assignment (
93
- scope = f"/subscriptions/{ os .getenv ( "AZURE_SUBSCRIPTION_ID" ) } /resourceGroups/{ os .getenv ( "AZURE_RESOURCE_GROUP" ) } /providers/Microsoft.CognitiveServices/accounts/{ os .getenv ( "AZURE_OPENAI_CONNECTION_NAME" ) } " ,
93
+ scope = f"/subscriptions/{ os .environ [ "AZURE_SUBSCRIPTION_ID" ] } /resourceGroups/{ os .environ [ "AZURE_RESOURCE_GROUP" ] } /providers/Microsoft.CognitiveServices/accounts/{ os .environ [ "AZURE_OPENAI_CONNECTION_NAME" ] } " ,
94
94
role_name = "Cognitive Services OpenAI User" ,
95
- principal_id = endpoint .identity .principal_id )
95
+ principal_id = endpoint .identity .principal_id
96
+ )
96
97
97
98
# 5. provide endpoint access to Azure AI Search resource
98
99
create_role_assignment (
99
- scope = f"/subscriptions/{ os .getenv ( "AZURE_SUBSCRIPTION_ID" ) } /resourceGroups/{ os .getenv ( "AZURE_RESOURCE_GROUP" ) } /providers/Microsoft.Search/searchServices/{ os .getenv ( "AZURE_SEARCH_CONNECTION_NAME" ) } " ,
100
+ scope = f"/subscriptions/{ os .environ [ "AZURE_SUBSCRIPTION_ID" ] } /resourceGroups/{ os .environ [ "AZURE_RESOURCE_GROUP" ] } /providers/Microsoft.Search/searchServices/{ os .environ [ "AZURE_SEARCH_CONNECTION_NAME" ] } " ,
100
101
role_name = "Search Index Data Contributor" ,
101
- principal_id = endpoint .identity .principal_id )
102
+ principal_id = endpoint .identity .principal_id
103
+ )
102
104
103
105
output_deployment_details (
104
106
client = client ,
105
107
endpoint_name = endpoint_name ,
106
- deployment_name = deployment_name )
108
+ deployment_name = deployment_name
109
+ )
107
110
108
111
def create_role_assignment (scope , role_name , principal_id ):
109
112
@@ -113,7 +116,8 @@ def create_role_assignment(scope, role_name, principal_id):
113
116
# Instantiate the authorization management client
114
117
auth_client = AuthorizationManagementClient (
115
118
credential = credential ,
116
- subscription_id = os .getenv ("AZURE_SUBSCRIPTION_ID" ))
119
+ subscription_id = os .environ ["AZURE_SUBSCRIPTION_ID" ]
120
+ )
117
121
118
122
roles = list (auth_client .role_definitions .list (
119
123
scope ,
@@ -126,13 +130,15 @@ def create_role_assignment(scope, role_name, principal_id):
126
130
parameters = RoleAssignmentCreateParameters (
127
131
role_definition_id = role .id ,
128
132
principal_id = principal_id ,
129
- principal_type = "ServicePrincipal" )
133
+ principal_type = "ServicePrincipal"
134
+ )
130
135
131
136
# Create role assignment
132
137
role_assignment = auth_client .role_assignments .create (
133
138
scope = scope ,
134
139
role_assignment_name = uuid .uuid4 (),
135
- parameters = parameters )
140
+ parameters = parameters
141
+ )
136
142
137
143
return role_assignment
138
144
0 commit comments