Skip to content

Commit 085a443

Browse files
authored
fix: update decorators for openai extension (#280)
* update decorators for openai extension * add commas * update openai file * update casing error * qa validations * fix flake8 validations * use union for acceptable type * address review comments * add deprecation information
1 parent de9f6dd commit 085a443

File tree

3 files changed

+528
-216
lines changed

3 files changed

+528
-216
lines changed

azure/functions/decorators/function_app.py

Lines changed: 103 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,6 @@ def assistant_skill_trigger(self,
16941694
function_description: str,
16951695
function_name: Optional[str] = None,
16961696
parameter_description_json: Optional[str] = None, # NoQA
1697-
model: Optional[OpenAIModels] = OpenAIModels.DefaultChatModel, # NoQA
16981697
data_type: Optional[
16991698
Union[DataType, str]] = None,
17001699
**kwargs: Any) -> Callable[..., Any]:
@@ -1723,7 +1722,6 @@ def assistant_skill_trigger(self,
17231722
:param parameter_description_json: A JSON description of the function
17241723
parameter, which is provided to the LLM.
17251724
If no description is provided, the description will be autogenerated.
1726-
:param model: The OpenAI chat model to use.
17271725
:param data_type: Defines how Functions runtime should treat the
17281726
parameter value.
17291727
:param kwargs: Keyword arguments for specifying additional binding
@@ -1741,7 +1739,6 @@ def decorator():
17411739
function_description=function_description,
17421740
function_name=function_name,
17431741
parameter_description_json=parameter_description_json,
1744-
model=model,
17451742
data_type=parse_singular_param_to_enum(data_type,
17461743
DataType),
17471744
**kwargs))
@@ -3220,10 +3217,13 @@ def decorator():
32203217
def text_completion_input(self,
32213218
arg_name: str,
32223219
prompt: str,
3223-
model: Optional[OpenAIModels] = OpenAIModels.DefaultChatModel, # NoQA
3220+
chat_model: Optional
3221+
[Union[str, OpenAIModels]]
3222+
= OpenAIModels.DefaultChatModel,
32243223
temperature: Optional[str] = "0.5",
32253224
top_p: Optional[str] = None,
32263225
max_tokens: Optional[str] = "100",
3226+
is_reasoning_model: Optional[bool] = False,
32273227
data_type: Optional[Union[DataType, str]] = None,
32283228
**kwargs) \
32293229
-> Callable[..., Any]:
@@ -3243,7 +3243,10 @@ def text_completion_input(self,
32433243
:param arg_name: The name of binding parameter in the function code.
32443244
:param prompt: The prompt to generate completions for, encoded as a
32453245
string.
3246-
:param model: the ID of the model to use.
3246+
:param model: @deprecated. Use chat_model instead. The model parameter
3247+
is unused and will be removed in future versions.
3248+
:param chat_model: The deployment name or model name of OpenAI Chat
3249+
Completion API. The default value is "gpt-3.5-turbo".
32473250
:param temperature: The sampling temperature to use, between 0 and 2.
32483251
Higher values like 0.8 will make the output more random, while lower
32493252
values like 0.2 will make it more focused and deterministic.
@@ -3255,7 +3258,10 @@ def text_completion_input(self,
32553258
:param max_tokens: The maximum number of tokens to generate in the
32563259
completion. The token count of your prompt plus max_tokens cannot
32573260
exceed the model's context length. Most models have a context length of
3258-
2048 tokens (except for the newest models, which support 4096).
3261+
2048 tokens (except for the newest models, which support 4096)
3262+
:param is_reasoning_model: Whether the configured chat completion model
3263+
is a reasoning model or not. Properties max_tokens and temperature are not
3264+
supported for reasoning models.
32593265
:param data_type: Defines how Functions runtime should treat the
32603266
parameter value
32613267
:param kwargs: Keyword arguments for specifying additional binding
@@ -3271,10 +3277,11 @@ def decorator():
32713277
binding=TextCompletionInput(
32723278
name=arg_name,
32733279
prompt=prompt,
3274-
model=model,
3280+
chat_model=chat_model,
32753281
temperature=temperature,
32763282
top_p=top_p,
32773283
max_tokens=max_tokens,
3284+
is_reasoning_model=is_reasoning_model,
32783285
data_type=parse_singular_param_to_enum(data_type,
32793286
DataType),
32803287
**kwargs))
@@ -3371,9 +3378,15 @@ def decorator():
33713378
def assistant_post_input(self, arg_name: str,
33723379
id: str,
33733380
user_message: str,
3374-
model: Optional[str] = None,
3381+
chat_model: Optional
3382+
[Union[str, OpenAIModels]]
3383+
= OpenAIModels.DefaultChatModel,
33753384
chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", # noqa: E501
3376-
collection_name: Optional[str] = "ChatState", # noqa: E501
3385+
collection_name: Optional[str] = "ChatState", # noqa: E501
3386+
temperature: Optional[str] = "0.5",
3387+
top_p: Optional[str] = None,
3388+
max_tokens: Optional[str] = "100",
3389+
is_reasoning_model: Optional[bool] = False,
33773390
data_type: Optional[
33783391
Union[DataType, str]] = None,
33793392
**kwargs) \
@@ -3386,12 +3399,30 @@ def assistant_post_input(self, arg_name: str,
33863399
:param id: The ID of the assistant to update.
33873400
:param user_message: The user message that user has entered for
33883401
assistant to respond to.
3389-
:param model: The OpenAI chat model to use.
3402+
:param model: @deprecated. Use chat_model instead. The model parameter
3403+
is unused and will be removed in future versions.
3404+
:param chat_model: The deployment name or model name of OpenAI Chat
3405+
Completion API. The default value is "gpt-3.5-turbo".
33903406
:param chat_storage_connection_setting: The configuration section name
33913407
for the table settings for assistant chat storage. The default value is
33923408
"AzureWebJobsStorage".
33933409
:param collection_name: The table collection name for assistant chat
33943410
storage. The default value is "ChatState".
3411+
:param temperature: The sampling temperature to use, between 0 and 2.
3412+
Higher values like 0.8 will make the output more random, while lower
3413+
values like 0.2 will make it more focused and deterministic.
3414+
:param top_p: An alternative to sampling with temperature, called
3415+
nucleus sampling, where the model considers the results of the tokens
3416+
with top_p probability mass. So 0.1 means only the tokens comprising
3417+
the top 10% probability mass are considered. It's generally recommend
3418+
to use this or temperature
3419+
:param max_tokens: The maximum number of tokens to generate in the
3420+
completion. The token count of your prompt plus max_tokens cannot
3421+
exceed the model's context length. Most models have a context length of
3422+
2048 tokens (except for the newest models, which support 4096)
3423+
:param is_reasoning_model: Whether the configured chat completion model
3424+
is a reasoning model or not. Properties max_tokens and temperature are
3425+
not supported for reasoning models.
33953426
:param data_type: Defines how Functions runtime should treat the
33963427
parameter value
33973428
:param kwargs: Keyword arguments for specifying additional binding
@@ -3408,9 +3439,13 @@ def decorator():
34083439
name=arg_name,
34093440
id=id,
34103441
user_message=user_message,
3411-
model=model,
3442+
chat_model=chat_model,
34123443
chat_storage_connection_setting=chat_storage_connection_setting, # noqa: E501
34133444
collection_name=collection_name,
3445+
temperature=temperature,
3446+
top_p=top_p,
3447+
max_tokens=max_tokens,
3448+
is_reasoning_model=is_reasoning_model,
34143449
data_type=parse_singular_param_to_enum(data_type,
34153450
DataType),
34163451
**kwargs))
@@ -3424,7 +3459,9 @@ def embeddings_input(self,
34243459
arg_name: str,
34253460
input: str,
34263461
input_type: InputType,
3427-
model: Optional[str] = None,
3462+
embeddings_model: Optional
3463+
[Union[str, OpenAIModels]]
3464+
= OpenAIModels.DefaultEmbeddingsModel,
34283465
max_chunk_length: Optional[int] = 8 * 1024,
34293466
max_overlap: Optional[int] = 128,
34303467
data_type: Optional[
@@ -3441,7 +3478,10 @@ def embeddings_input(self,
34413478
:param input: The input source containing the data to generate
34423479
embeddings for.
34433480
:param input_type: The type of the input.
3444-
:param model: The ID of the model to use.
3481+
:param model: @deprecated. Use embeddings_model instead. The model
3482+
parameter is unused and will be removed in future versions.
3483+
:param embeddings_model: The deployment name or model name for OpenAI
3484+
Embeddings. The default value is "text-embedding-ada-002".
34453485
:param max_chunk_length: The maximum number of characters to chunk the
34463486
input into. Default value: 8 * 1024
34473487
:param max_overlap: The maximum number of characters to overlap
@@ -3462,7 +3502,7 @@ def decorator():
34623502
name=arg_name,
34633503
input=input,
34643504
input_type=input_type,
3465-
model=model,
3505+
embeddings_model=embeddings_model,
34663506
max_chunk_length=max_chunk_length,
34673507
max_overlap=max_overlap,
34683508
data_type=parse_singular_param_to_enum(data_type,
@@ -3476,13 +3516,21 @@ def decorator():
34763516

34773517
def semantic_search_input(self,
34783518
arg_name: str,
3479-
connection_name: str,
3519+
search_connection_name: str,
34803520
collection: str,
34813521
query: Optional[str] = None,
3482-
embeddings_model: Optional[OpenAIModels] = OpenAIModels.DefaultEmbeddingsModel, # NoQA
3483-
chat_model: Optional[OpenAIModels] = OpenAIModels.DefaultChatModel, # NoQA
3522+
embeddings_model: Optional
3523+
[Union[str, OpenAIModels]]
3524+
= OpenAIModels.DefaultEmbeddingsModel,
3525+
chat_model: Optional
3526+
[Union[str, OpenAIModels]]
3527+
= OpenAIModels.DefaultChatModel,
34843528
system_prompt: Optional[str] = semantic_search_system_prompt, # NoQA
34853529
max_knowledge_count: Optional[int] = 1,
3530+
temperature: Optional[str] = "0.5",
3531+
top_p: Optional[str] = None,
3532+
max_tokens: Optional[str] = "100",
3533+
is_reasoning_model: Optional[bool] = False,
34863534
data_type: Optional[
34873535
Union[DataType, str]] = None,
34883536
**kwargs) \
@@ -3499,19 +3547,34 @@ def semantic_search_input(self,
34993547
Ref: https://platform.openai.com/docs/guides/embeddings
35003548
35013549
:param arg_name: The name of binding parameter in the function code.
3502-
:param connection_name: app setting or environment variable which
3503-
contains a connection string value.
3550+
:param search_connection_name: app setting or environment variable
3551+
which contains a vector search connection setting value.
35043552
:param collection: The name of the collection or table to search or
35053553
store.
35063554
:param query: The semantic query text to use for searching.
3507-
:param embeddings_model: The ID of the model to use for embeddings.
3508-
The default value is "text-embedding-ada-002".
3509-
:param chat_model: The name of the Large Language Model to invoke for
3510-
chat responses. The default value is "gpt-3.5-turbo".
3555+
:param embeddings_model: The deployment name or model name for OpenAI
3556+
Embeddings. The default value is "text-embedding-ada-002".
3557+
:param chat_model: The deployment name or model name of OpenAI Chat
3558+
Completion API. The default value is "gpt-3.5-turbo".
35113559
:param system_prompt: Optional. The system prompt to use for prompting
35123560
the large language model.
35133561
:param max_knowledge_count: Optional. The number of knowledge items to
35143562
inject into the SystemPrompt. Default value: 1
3563+
:param temperature: The sampling temperature to use, between 0 and 2.
3564+
Higher values like 0.8 will make the output more random, while lower
3565+
values like 0.2 will make it more focused and deterministic.
3566+
:param top_p: An alternative to sampling with temperature, called
3567+
nucleus sampling, where the model considers the results of the tokens
3568+
with top_p probability mass. So 0.1 means only the tokens comprising
3569+
the top 10% probability mass are considered. It's generally recommend
3570+
to use this or temperature
3571+
:param max_tokens: The maximum number of tokens to generate in the
3572+
completion. The token count of your prompt plus max_tokens cannot
3573+
exceed the model's context length. Most models have a context length of
3574+
2048 tokens (except for the newest models, which support 4096)
3575+
:param is_reasoning_model: Whether the configured chat completion model
3576+
is a reasoning model or not. Properties max_tokens and temperature are
3577+
not supported for reasoning models.
35153578
:param data_type: Optional. Defines how Functions runtime should treat
35163579
the parameter value. Default value: None
35173580
:param kwargs: Keyword arguments for specifying additional binding
@@ -3526,13 +3589,17 @@ def decorator():
35263589
fb.add_binding(
35273590
binding=SemanticSearchInput(
35283591
name=arg_name,
3529-
connection_name=connection_name,
3592+
search_connection_name=search_connection_name,
35303593
collection=collection,
35313594
query=query,
35323595
embeddings_model=embeddings_model,
35333596
chat_model=chat_model,
35343597
system_prompt=system_prompt,
35353598
max_knowledge_count=max_knowledge_count,
3599+
temperature=temperature,
3600+
top_p=top_p,
3601+
max_tokens=max_tokens,
3602+
is_reasoning_model=is_reasoning_model,
35363603
data_type=parse_singular_param_to_enum(data_type,
35373604
DataType),
35383605
**kwargs))
@@ -3546,9 +3613,11 @@ def embeddings_store_output(self,
35463613
arg_name: str,
35473614
input: str,
35483615
input_type: InputType,
3549-
connection_name: str,
3616+
store_connection_name: str,
35503617
collection: str,
3551-
model: Optional[OpenAIModels] = OpenAIModels.DefaultEmbeddingsModel, # NoQA
3618+
embeddings_model: Optional
3619+
[Union[str, OpenAIModels]]
3620+
= OpenAIModels.DefaultEmbeddingsModel,
35523621
max_chunk_length: Optional[int] = 8 * 1024,
35533622
max_overlap: Optional[int] = 128,
35543623
data_type: Optional[
@@ -3568,10 +3637,13 @@ def embeddings_store_output(self,
35683637
:param arg_name: The name of binding parameter in the function code.
35693638
:param input: The input to generate embeddings for.
35703639
:param input_type: The type of the input.
3571-
:param connection_name: The name of an app setting or environment
3572-
variable which contains a connection string value
3640+
:param store_connection_name: The name of an app setting or environment
3641+
variable which contains a vectore store connection setting value
35733642
:param collection: The collection or table to search.
3574-
:param model: The ID of the model to use.
3643+
:param model: @deprecated. Use embeddings_model instead. The model
3644+
parameter is unused and will be removed in future versions.
3645+
:param embeddings_model: The deployment name or model name for OpenAI
3646+
Embeddings. The default value is "text-embedding-ada-002".
35753647
:param max_chunk_length: The maximum number of characters to chunk the
35763648
input into.
35773649
:param max_overlap: The maximum number of characters to overlap between
@@ -3592,9 +3664,9 @@ def decorator():
35923664
name=arg_name,
35933665
input=input,
35943666
input_type=input_type,
3595-
connection_name=connection_name,
3667+
store_connection_name=store_connection_name,
35963668
collection=collection,
3597-
model=model,
3669+
embeddings_model=embeddings_model,
35983670
max_chunk_length=max_chunk_length,
35993671
max_overlap=max_overlap,
36003672
data_type=parse_singular_param_to_enum(data_type,

0 commit comments

Comments
 (0)