Skip to content

Commit fa8caa3

Browse files
committed
update decorators for openai extension
1 parent de9f6dd commit fa8caa3

File tree

2 files changed

+101
-42
lines changed

2 files changed

+101
-42
lines changed

azure/functions/decorators/function_app.py

Lines changed: 74 additions & 27 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,11 @@ 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[OpenAIModels] = OpenAIModels.DefaultChatModel, # NoQA
32243221
temperature: Optional[str] = "0.5",
32253222
top_p: Optional[str] = None,
32263223
max_tokens: Optional[str] = "100",
3224+
is_reasoning_model: Optional[bool] = False,
32273225
data_type: Optional[Union[DataType, str]] = None,
32283226
**kwargs) \
32293227
-> Callable[..., Any]:
@@ -3255,7 +3253,10 @@ def text_completion_input(self,
32553253
:param max_tokens: The maximum number of tokens to generate in the
32563254
completion. The token count of your prompt plus max_tokens cannot
32573255
exceed the model's context length. Most models have a context length of
3258-
2048 tokens (except for the newest models, which support 4096).
3256+
2048 tokens (except for the newest models, which support 4096)
3257+
:param is_reasoning_model: Whether the configured chat completion model
3258+
is a reasoning model or not. Properties max_tokens and temperature are not
3259+
supported for reasoning models.
32593260
:param data_type: Defines how Functions runtime should treat the
32603261
parameter value
32613262
:param kwargs: Keyword arguments for specifying additional binding
@@ -3271,10 +3272,11 @@ def decorator():
32713272
binding=TextCompletionInput(
32723273
name=arg_name,
32733274
prompt=prompt,
3274-
model=model,
3275+
chat_model=chat_model,
32753276
temperature=temperature,
32763277
top_p=top_p,
32773278
max_tokens=max_tokens,
3279+
is_reasoning_model=is_reasoning_model,
32783280
data_type=parse_singular_param_to_enum(data_type,
32793281
DataType),
32803282
**kwargs))
@@ -3371,9 +3373,13 @@ def decorator():
33713373
def assistant_post_input(self, arg_name: str,
33723374
id: str,
33733375
user_message: str,
3374-
model: Optional[str] = None,
3376+
chat_model: Optional[str] = OpenAIModels.DefaultChatModel,
33753377
chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", # noqa: E501
3376-
collection_name: Optional[str] = "ChatState", # noqa: E501
3378+
collection_name: Optional[str] = "ChatState", # noqa: E501
3379+
temperature: Optional[str] = "0.5",
3380+
top_p: Optional[str] = None,
3381+
max_tokens: Optional[str] = "100",
3382+
is_reasoning_model: Optional[bool] = False,
33773383
data_type: Optional[
33783384
Union[DataType, str]] = None,
33793385
**kwargs) \
@@ -3386,12 +3392,27 @@ def assistant_post_input(self, arg_name: str,
33863392
:param id: The ID of the assistant to update.
33873393
:param user_message: The user message that user has entered for
33883394
assistant to respond to.
3389-
:param model: The OpenAI chat model to use.
3395+
:param chat_model: The deployment name or model name of OpenAI Chat Completion API.
33903396
:param chat_storage_connection_setting: The configuration section name
33913397
for the table settings for assistant chat storage. The default value is
33923398
"AzureWebJobsStorage".
33933399
:param collection_name: The table collection name for assistant chat
33943400
storage. The default value is "ChatState".
3401+
:param temperature: The sampling temperature to use, between 0 and 2.
3402+
Higher values like 0.8 will make the output more random, while lower
3403+
values like 0.2 will make it more focused and deterministic.
3404+
:param top_p: An alternative to sampling with temperature, called
3405+
nucleus sampling, where the model considers the results of the tokens
3406+
with top_p probability mass. So 0.1 means only the tokens comprising
3407+
the top 10% probability mass are considered. It's generally recommend
3408+
to use this or temperature
3409+
:param max_tokens: The maximum number of tokens to generate in the
3410+
completion. The token count of your prompt plus max_tokens cannot
3411+
exceed the model's context length. Most models have a context length of
3412+
2048 tokens (except for the newest models, which support 4096)
3413+
:param is_reasoning_model: Whether the configured chat completion model
3414+
is a reasoning model or not. Properties max_tokens and temperature are not
3415+
supported for reasoning models.
33953416
:param data_type: Defines how Functions runtime should treat the
33963417
parameter value
33973418
:param kwargs: Keyword arguments for specifying additional binding
@@ -3408,9 +3429,13 @@ def decorator():
34083429
name=arg_name,
34093430
id=id,
34103431
user_message=user_message,
3411-
model=model,
3432+
chat_model=chat_model,
34123433
chat_storage_connection_setting=chat_storage_connection_setting, # noqa: E501
34133434
collection_name=collection_name,
3435+
temperature=temperature,
3436+
top_p=top_p,
3437+
max_tokens=max_tokens,
3438+
is_reasoning_model=is_reasoning_model,
34143439
data_type=parse_singular_param_to_enum(data_type,
34153440
DataType),
34163441
**kwargs))
@@ -3424,7 +3449,7 @@ def embeddings_input(self,
34243449
arg_name: str,
34253450
input: str,
34263451
input_type: InputType,
3427-
model: Optional[str] = None,
3452+
embeddings_model: Optional[str] = OpenAIModels.DefaultEmbeddingsModel,
34283453
max_chunk_length: Optional[int] = 8 * 1024,
34293454
max_overlap: Optional[int] = 128,
34303455
data_type: Optional[
@@ -3441,7 +3466,7 @@ def embeddings_input(self,
34413466
:param input: The input source containing the data to generate
34423467
embeddings for.
34433468
:param input_type: The type of the input.
3444-
:param model: The ID of the model to use.
3469+
:param embeddings_model: The deployment name or model name for OpenAI Embeddings.
34453470
:param max_chunk_length: The maximum number of characters to chunk the
34463471
input into. Default value: 8 * 1024
34473472
:param max_overlap: The maximum number of characters to overlap
@@ -3462,7 +3487,7 @@ def decorator():
34623487
name=arg_name,
34633488
input=input,
34643489
input_type=input_type,
3465-
model=model,
3490+
embeddings_model=embeddings_model,
34663491
max_chunk_length=max_chunk_length,
34673492
max_overlap=max_overlap,
34683493
data_type=parse_singular_param_to_enum(data_type,
@@ -3476,13 +3501,17 @@ def decorator():
34763501

34773502
def semantic_search_input(self,
34783503
arg_name: str,
3479-
connection_name: str,
3504+
search_connection_name: str,
34803505
collection: str,
34813506
query: Optional[str] = None,
34823507
embeddings_model: Optional[OpenAIModels] = OpenAIModels.DefaultEmbeddingsModel, # NoQA
34833508
chat_model: Optional[OpenAIModels] = OpenAIModels.DefaultChatModel, # NoQA
34843509
system_prompt: Optional[str] = semantic_search_system_prompt, # NoQA
34853510
max_knowledge_count: Optional[int] = 1,
3511+
temperature: Optional[str] = "0.5",
3512+
top_p: Optional[str] = None,
3513+
max_tokens: Optional[str] = "100",
3514+
is_reasoning_model: Optional[bool] = False,
34863515
data_type: Optional[
34873516
Union[DataType, str]] = None,
34883517
**kwargs) \
@@ -3499,19 +3528,33 @@ def semantic_search_input(self,
34993528
Ref: https://platform.openai.com/docs/guides/embeddings
35003529
35013530
: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.
3531+
:param search_connection_name: app setting or environment variable which
3532+
contains a vector search connection setting value.
35043533
:param collection: The name of the collection or table to search or
35053534
store.
35063535
:param query: The semantic query text to use for searching.
3507-
:param embeddings_model: The ID of the model to use for embeddings.
3536+
:param embeddings_model: The deployment name or model name for OpenAI Embeddings.
35083537
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".
3538+
:param chat_model: The deployment name or model name of OpenAI Chat Completion API.
35113539
:param system_prompt: Optional. The system prompt to use for prompting
35123540
the large language model.
35133541
:param max_knowledge_count: Optional. The number of knowledge items to
35143542
inject into the SystemPrompt. Default value: 1
3543+
:param temperature: The sampling temperature to use, between 0 and 2.
3544+
Higher values like 0.8 will make the output more random, while lower
3545+
values like 0.2 will make it more focused and deterministic.
3546+
:param top_p: An alternative to sampling with temperature, called
3547+
nucleus sampling, where the model considers the results of the tokens
3548+
with top_p probability mass. So 0.1 means only the tokens comprising
3549+
the top 10% probability mass are considered. It's generally recommend
3550+
to use this or temperature
3551+
:param max_tokens: The maximum number of tokens to generate in the
3552+
completion. The token count of your prompt plus max_tokens cannot
3553+
exceed the model's context length. Most models have a context length of
3554+
2048 tokens (except for the newest models, which support 4096)
3555+
:param is_reasoning_model: Whether the configured chat completion model
3556+
is a reasoning model or not. Properties max_tokens and temperature are not
3557+
supported for reasoning models.
35153558
:param data_type: Optional. Defines how Functions runtime should treat
35163559
the parameter value. Default value: None
35173560
:param kwargs: Keyword arguments for specifying additional binding
@@ -3526,13 +3569,17 @@ def decorator():
35263569
fb.add_binding(
35273570
binding=SemanticSearchInput(
35283571
name=arg_name,
3529-
connection_name=connection_name,
3572+
search_connection_name=search_connection_name,
35303573
collection=collection,
35313574
query=query,
35323575
embeddings_model=embeddings_model,
35333576
chat_model=chat_model,
35343577
system_prompt=system_prompt,
35353578
max_knowledge_count=max_knowledge_count,
3579+
temperature=temperature,
3580+
top_p=top_p,
3581+
max_tokens=max_tokens,
3582+
is_reasoning_model=is_reasoning_model,
35363583
data_type=parse_singular_param_to_enum(data_type,
35373584
DataType),
35383585
**kwargs))
@@ -3546,9 +3593,9 @@ def embeddings_store_output(self,
35463593
arg_name: str,
35473594
input: str,
35483595
input_type: InputType,
3549-
connection_name: str,
3596+
store_connection_name: str,
35503597
collection: str,
3551-
model: Optional[OpenAIModels] = OpenAIModels.DefaultEmbeddingsModel, # NoQA
3598+
embeddings_model: Optional[OpenAIModels] = OpenAIModels.DefaultEmbeddingsModel, # NoQA
35523599
max_chunk_length: Optional[int] = 8 * 1024,
35533600
max_overlap: Optional[int] = 128,
35543601
data_type: Optional[
@@ -3568,10 +3615,10 @@ def embeddings_store_output(self,
35683615
:param arg_name: The name of binding parameter in the function code.
35693616
:param input: The input to generate embeddings for.
35703617
: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
3618+
:param store_connection_name: The name of an app setting or environment
3619+
variable which contains a vectore store connection setting value
35733620
:param collection: The collection or table to search.
3574-
:param model: The ID of the model to use.
3621+
:param embeddings_model: The deployment name or model name for OpenAI Embeddings.
35753622
:param max_chunk_length: The maximum number of characters to chunk the
35763623
input into.
35773624
:param max_overlap: The maximum number of characters to overlap between
@@ -3592,9 +3639,9 @@ def decorator():
35923639
name=arg_name,
35933640
input=input,
35943641
input_type=input_type,
3595-
connection_name=connection_name,
3642+
store_connection_name=store_connection_name,
35963643
collection=collection,
3597-
model=model,
3644+
embeddings_model=embeddings_model,
35983645
max_chunk_length=max_chunk_length,
35993646
max_overlap=max_overlap,
36003647
data_type=parse_singular_param_to_enum(data_type,

0 commit comments

Comments
 (0)