Skip to content

Commit e981117

Browse files
authored
aiConnectionName param added (#283)
1 parent 6a95bb8 commit e981117

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

azure/functions/decorators/function_app.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3217,6 +3217,7 @@ def decorator():
32173217
def text_completion_input(self,
32183218
arg_name: str,
32193219
prompt: str,
3220+
ai_connection_name: Optional[str] = "",
32203221
chat_model: Optional
32213222
[Union[str, OpenAIModels]]
32223223
= OpenAIModels.DefaultChatModel,
@@ -3243,6 +3244,14 @@ def text_completion_input(self,
32433244
:param arg_name: The name of binding parameter in the function code.
32443245
:param prompt: The prompt to generate completions for, encoded as a
32453246
string.
3247+
:param ai_connection_name: The name of the configuration section for
3248+
AI service connectivity settings. For Azure OpenAI: If specified, looks
3249+
for "Endpoint" and/or "Key" values in this configuration section. If
3250+
not specified or the section doesn't exist, falls back to environment
3251+
variables: AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_KEY. For
3252+
user-assigned managed identity authentication, this property is
3253+
required. For OpenAI service (non-Azure), set the OPENAI_API_KEY
3254+
environment variable.
32463255
:param model: @deprecated. Use chat_model instead. The model parameter
32473256
is unused and will be removed in future versions.
32483257
:param chat_model: The deployment name or model name of OpenAI Chat
@@ -3277,6 +3286,7 @@ def decorator():
32773286
binding=TextCompletionInput(
32783287
name=arg_name,
32793288
prompt=prompt,
3289+
ai_connection_name=ai_connection_name,
32803290
chat_model=chat_model,
32813291
temperature=temperature,
32823292
top_p=top_p,
@@ -3378,6 +3388,7 @@ def decorator():
33783388
def assistant_post_input(self, arg_name: str,
33793389
id: str,
33803390
user_message: str,
3391+
ai_connection_name: Optional[str] = "",
33813392
chat_model: Optional
33823393
[Union[str, OpenAIModels]]
33833394
= OpenAIModels.DefaultChatModel,
@@ -3399,6 +3410,14 @@ def assistant_post_input(self, arg_name: str,
33993410
:param id: The ID of the assistant to update.
34003411
:param user_message: The user message that user has entered for
34013412
assistant to respond to.
3413+
:param ai_connection_name: The name of the configuration section for
3414+
AI service connectivity settings. For Azure OpenAI: If specified, looks
3415+
for "Endpoint" and/or "Key" values in this configuration section. If
3416+
not specified or the section doesn't exist, falls back to environment
3417+
variables: AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_KEY. For
3418+
user-assigned managed identity authentication, this property is
3419+
required. For OpenAI service (non-Azure), set the OPENAI_API_KEY
3420+
environment variable.
34023421
:param model: @deprecated. Use chat_model instead. The model parameter
34033422
is unused and will be removed in future versions.
34043423
:param chat_model: The deployment name or model name of OpenAI Chat
@@ -3439,6 +3458,7 @@ def decorator():
34393458
name=arg_name,
34403459
id=id,
34413460
user_message=user_message,
3461+
ai_connection_name=ai_connection_name,
34423462
chat_model=chat_model,
34433463
chat_storage_connection_setting=chat_storage_connection_setting, # noqa: E501
34443464
collection_name=collection_name,
@@ -3459,6 +3479,7 @@ def embeddings_input(self,
34593479
arg_name: str,
34603480
input: str,
34613481
input_type: InputType,
3482+
ai_connection_name: Optional[str] = "",
34623483
embeddings_model: Optional
34633484
[Union[str, OpenAIModels]]
34643485
= OpenAIModels.DefaultEmbeddingsModel,
@@ -3478,6 +3499,14 @@ def embeddings_input(self,
34783499
:param input: The input source containing the data to generate
34793500
embeddings for.
34803501
:param input_type: The type of the input.
3502+
:param ai_connection_name: The name of the configuration section for
3503+
AI service connectivity settings. For Azure OpenAI: If specified, looks
3504+
for "Endpoint" and/or "Key" values in this configuration section. If
3505+
not specified or the section doesn't exist, falls back to environment
3506+
variables: AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_KEY. For
3507+
user-assigned managed identity authentication, this property is
3508+
required. For OpenAI service (non-Azure), set the OPENAI_API_KEY
3509+
environment variable.
34813510
:param model: @deprecated. Use embeddings_model instead. The model
34823511
parameter is unused and will be removed in future versions.
34833512
:param embeddings_model: The deployment name or model name for OpenAI
@@ -3502,6 +3531,7 @@ def decorator():
35023531
name=arg_name,
35033532
input=input,
35043533
input_type=input_type,
3534+
ai_connection_name=ai_connection_name,
35053535
embeddings_model=embeddings_model,
35063536
max_chunk_length=max_chunk_length,
35073537
max_overlap=max_overlap,
@@ -3519,6 +3549,7 @@ def semantic_search_input(self,
35193549
search_connection_name: str,
35203550
collection: str,
35213551
query: Optional[str] = None,
3552+
ai_connection_name: Optional[str] = "",
35223553
embeddings_model: Optional
35233554
[Union[str, OpenAIModels]]
35243555
= OpenAIModels.DefaultEmbeddingsModel,
@@ -3552,6 +3583,14 @@ def semantic_search_input(self,
35523583
:param collection: The name of the collection or table to search or
35533584
store.
35543585
:param query: The semantic query text to use for searching.
3586+
:param ai_connection_name: The name of the configuration section for
3587+
AI service connectivity settings. For Azure OpenAI: If specified, looks
3588+
for "Endpoint" and/or "Key" values in this configuration section. If
3589+
not specified or the section doesn't exist, falls back to environment
3590+
variables: AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_KEY. For
3591+
user-assigned managed identity authentication, this property is
3592+
required. For OpenAI service (non-Azure), set the OPENAI_API_KEY
3593+
environment variable.
35553594
:param embeddings_model: The deployment name or model name for OpenAI
35563595
Embeddings. The default value is "text-embedding-ada-002".
35573596
:param chat_model: The deployment name or model name of OpenAI Chat
@@ -3592,6 +3631,7 @@ def decorator():
35923631
search_connection_name=search_connection_name,
35933632
collection=collection,
35943633
query=query,
3634+
ai_connection_name=ai_connection_name,
35953635
embeddings_model=embeddings_model,
35963636
chat_model=chat_model,
35973637
system_prompt=system_prompt,
@@ -3615,6 +3655,7 @@ def embeddings_store_output(self,
36153655
input_type: InputType,
36163656
store_connection_name: str,
36173657
collection: str,
3658+
ai_connection_name: Optional[str] = "",
36183659
embeddings_model: Optional
36193660
[Union[str, OpenAIModels]]
36203661
= OpenAIModels.DefaultEmbeddingsModel,
@@ -3640,6 +3681,14 @@ def embeddings_store_output(self,
36403681
:param store_connection_name: The name of an app setting or environment
36413682
variable which contains a vectore store connection setting value
36423683
:param collection: The collection or table to search.
3684+
:param ai_connection_name: The name of the configuration section for
3685+
AI service connectivity settings. For Azure OpenAI: If specified, looks
3686+
for "Endpoint" and/or "Key" values in this configuration section. If
3687+
not specified or the section doesn't exist, falls back to environment
3688+
variables: AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_KEY. For
3689+
user-assigned managed identity authentication, this property is
3690+
required. For OpenAI service (non-Azure), set the OPENAI_API_KEY
3691+
environment variable.
36433692
:param model: @deprecated. Use embeddings_model instead. The model
36443693
parameter is unused and will be removed in future versions.
36453694
:param embeddings_model: The deployment name or model name for OpenAI
@@ -3666,6 +3715,7 @@ def decorator():
36663715
input_type=input_type,
36673716
store_connection_name=store_connection_name,
36683717
collection=collection,
3718+
ai_connection_name=ai_connection_name,
36693719
embeddings_model=embeddings_model,
36703720
max_chunk_length=max_chunk_length,
36713721
max_overlap=max_overlap,

azure/functions/decorators/openai.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def get_binding_name() -> str:
5151
def __init__(self,
5252
name: str,
5353
prompt: str,
54+
ai_connection_name: Optional[str] = "",
5455
chat_model: Optional
5556
[Union[str, OpenAIModels]]
5657
= OpenAIModels.DefaultChatModel,
@@ -61,6 +62,7 @@ def __init__(self,
6162
data_type: Optional[DataType] = None,
6263
**kwargs):
6364
self.prompt = prompt
65+
self.ai_connection_name = ai_connection_name
6466
self.chat_model = chat_model
6567
self.temperature = temperature
6668
self.top_p = top_p
@@ -100,6 +102,7 @@ def __init__(self,
100102
name: str,
101103
input: str,
102104
input_type: InputType,
105+
ai_connection_name: Optional[str] = "",
103106
embeddings_model: Optional
104107
[Union[str, OpenAIModels]]
105108
= OpenAIModels.DefaultEmbeddingsModel,
@@ -110,6 +113,7 @@ def __init__(self,
110113
self.name = name
111114
self.input = input
112115
self.input_type = input_type
116+
self.ai_connection_name = ai_connection_name
113117
self.embeddings_model = embeddings_model
114118
self.max_chunk_length = max_chunk_length
115119
self.max_overlap = max_overlap
@@ -144,6 +148,7 @@ def __init__(self,
144148
search_connection_name: str,
145149
collection: str,
146150
query: Optional[str] = None,
151+
ai_connection_name: Optional[str] = "",
147152
embeddings_model: Optional
148153
[Union[str, OpenAIModels]]
149154
= OpenAIModels.DefaultEmbeddingsModel,
@@ -162,6 +167,7 @@ def __init__(self,
162167
self.search_connection_name = search_connection_name
163168
self.collection = collection
164169
self.query = query
170+
self.ai_connection_name = ai_connection_name
165171
self.embeddings_model = embeddings_model
166172
self.chat_model = chat_model
167173
self.system_prompt = system_prompt
@@ -182,6 +188,7 @@ def get_binding_name():
182188
def __init__(self, name: str,
183189
id: str,
184190
user_message: str,
191+
ai_connection_name: Optional[str] = "",
185192
chat_model: Optional
186193
[Union[str, OpenAIModels]]
187194
= OpenAIModels.DefaultChatModel,
@@ -196,6 +203,7 @@ def __init__(self, name: str,
196203
self.name = name
197204
self.id = id
198205
self.user_message = user_message
206+
self.ai_connection_name = ai_connection_name
199207
self.chat_model = chat_model
200208
self.chat_storage_connection_setting = chat_storage_connection_setting
201209
self.collection_name = collection_name
@@ -218,6 +226,7 @@ def __init__(self,
218226
input_type: InputType,
219227
store_connection_name: str,
220228
collection: str,
229+
ai_connection_name: Optional[str] = "",
221230
embeddings_model: Optional
222231
[Union[str, OpenAIModels]]
223232
= OpenAIModels.DefaultEmbeddingsModel,
@@ -230,6 +239,7 @@ def __init__(self,
230239
self.input_type = input_type
231240
self.store_connection_name = store_connection_name
232241
self.collection = collection
242+
self.ai_connection_name = ai_connection_name
233243
self.embeddings_model = embeddings_model
234244
self.max_chunk_length = max_chunk_length
235245
self.max_overlap = max_overlap

tests/decorators/test_openai.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def test_text_completion_input_valid_creation(self):
5050
is_reasoning_model=False,
5151
data_type=DataType.UNDEFINED,
5252
chat_model=OpenAIModels.DefaultChatModel,
53+
ai_connection_name="test_connection",
5354
dummy_field="dummy",
5455
)
5556
self.assertEqual(input.get_binding_name(), "textCompletion")
@@ -66,6 +67,7 @@ def test_text_completion_input_valid_creation(self):
6667
"direction": BindingDirection.IN,
6768
"chatModel": OpenAIModels.DefaultChatModel,
6869
"isReasoningModel": False,
70+
"aiConnectionName": "test_connection",
6971
},
7072
)
7173

@@ -78,6 +80,7 @@ def test_text_completion_input_with_string_chat_model(self):
7880
is_reasoning_model=True,
7981
data_type=DataType.UNDEFINED,
8082
chat_model="gpt-4o",
83+
ai_connection_name="test_connection",
8184
dummy_field="dummy",
8285
)
8386
self.assertEqual(input.get_binding_name(), "textCompletion")
@@ -94,6 +97,7 @@ def test_text_completion_input_with_string_chat_model(self):
9497
"direction": BindingDirection.IN,
9598
"chatModel": "gpt-4o",
9699
"isReasoningModel": True,
100+
"aiConnectionName": "test_connection",
97101
},
98102
)
99103

@@ -133,6 +137,7 @@ def test_embeddings_input_valid_creation(self):
133137
embeddings_model="test_model",
134138
max_overlap=1,
135139
max_chunk_length=1,
140+
ai_connection_name="test_connection",
136141
dummy_field="dummy",
137142
)
138143
self.assertEqual(input.get_binding_name(), "embeddings")
@@ -148,6 +153,7 @@ def test_embeddings_input_valid_creation(self):
148153
"maxOverlap": 1,
149154
"maxChunkLength": 1,
150155
"direction": BindingDirection.IN,
156+
"aiConnectionName": "test_connection",
151157
"dummyField": "dummy",
152158
},
153159
)
@@ -161,6 +167,7 @@ def test_embeddings_input_with_enum_embeddings_model(self):
161167
embeddings_model=OpenAIModels.DefaultEmbeddingsModel,
162168
max_overlap=1,
163169
max_chunk_length=1,
170+
ai_connection_name="test_connection",
164171
dummy_field="dummy",
165172
)
166173
self.assertEqual(input.get_binding_name(), "embeddings")
@@ -176,6 +183,7 @@ def test_embeddings_input_with_enum_embeddings_model(self):
176183
"maxOverlap": 1,
177184
"maxChunkLength": 1,
178185
"direction": BindingDirection.IN,
186+
"aiConnectionName": "test_connection",
179187
"dummyField": "dummy",
180188
},
181189
)
@@ -206,6 +214,7 @@ def test_assistant_post_input_valid_creation(self):
206214
temperature="1",
207215
max_tokens="1",
208216
is_reasoning_model=False,
217+
ai_connection_name="test_connection",
209218
data_type=DataType.UNDEFINED,
210219
dummy_field="dummy",
211220
)
@@ -222,6 +231,7 @@ def test_assistant_post_input_valid_creation(self):
222231
"temperature": "1",
223232
"maxTokens": "1",
224233
"isReasoningModel": False,
234+
"aiConnectionName": "test_connection",
225235
"dataType": DataType.UNDEFINED,
226236
"direction": BindingDirection.IN,
227237
"dummyField": "dummy",
@@ -240,6 +250,7 @@ def test_assistant_post_input_with_enum_chat_model(self):
240250
temperature="1",
241251
max_tokens="1",
242252
is_reasoning_model=False,
253+
ai_connection_name="test_connection",
243254
data_type=DataType.UNDEFINED,
244255
dummy_field="dummy",
245256
)
@@ -256,6 +267,7 @@ def test_assistant_post_input_with_enum_chat_model(self):
256267
"temperature": "1",
257268
"maxTokens": "1",
258269
"isReasoningModel": False,
270+
"aiConnectionName": "test_connection",
259271
"dataType": DataType.UNDEFINED,
260272
"direction": BindingDirection.IN,
261273
"dummyField": "dummy",
@@ -277,6 +289,7 @@ def test_semantic_search_input_valid_creation(self):
277289
temperature="1",
278290
max_tokens="1",
279291
is_reasoning_model=False,
292+
ai_connection_name="test_connection",
280293
dummy_field="dummy_field",
281294
)
282295
self.assertEqual(input.get_binding_name(), "semanticSearch")
@@ -297,6 +310,7 @@ def test_semantic_search_input_valid_creation(self):
297310
"temperature": "1",
298311
"maxTokens": "1",
299312
"isReasoningModel": False,
313+
"aiConnectionName": "test_connection",
300314
"query": "test_query",
301315
},
302316
)
@@ -315,6 +329,7 @@ def test_semantic_search_input_with_string_models(self):
315329
temperature="1",
316330
max_tokens="1",
317331
is_reasoning_model=True,
332+
ai_connection_name="test_connection",
318333
dummy_field="dummy_field",
319334
)
320335
self.assertEqual(input.get_binding_name(), "semanticSearch")
@@ -335,6 +350,7 @@ def test_semantic_search_input_with_string_models(self):
335350
"temperature": "1",
336351
"maxTokens": "1",
337352
"isReasoningModel": True,
353+
"aiConnectionName": "test_connection",
338354
"query": "test_query",
339355
},
340356
)
@@ -350,6 +366,7 @@ def test_embeddings_store_output_valid_creation(self):
350366
max_chunk_length=1,
351367
collection="test_collection",
352368
embeddings_model=OpenAIModels.DefaultEmbeddingsModel, # noqa: E501
369+
ai_connection_name="test_connection",
353370
dummy_field="dummy_field",
354371
)
355372
self.assertEqual(output.get_binding_name(), "embeddingsStore")
@@ -368,6 +385,7 @@ def test_embeddings_store_output_valid_creation(self):
368385
"maxOverlap": 1,
369386
"maxChunkLength": 1,
370387
"type": "embeddingsStore",
388+
"aiConnectionName": "test_connection",
371389
},
372390
)
373391

@@ -382,6 +400,7 @@ def test_embeddings_store_output_with_string_embeddings_model(self):
382400
max_chunk_length=1,
383401
collection="test_collection",
384402
embeddings_model="text-embedding-3-small",
403+
ai_connection_name="test_connection",
385404
dummy_field="dummy_field",
386405
)
387406
self.assertEqual(output.get_binding_name(), "embeddingsStore")
@@ -400,5 +419,6 @@ def test_embeddings_store_output_with_string_embeddings_model(self):
400419
"maxOverlap": 1,
401420
"maxChunkLength": 1,
402421
"type": "embeddingsStore",
422+
"aiConnectionName": "test_connection",
403423
},
404424
)

0 commit comments

Comments
 (0)