From ae3469575b90f75fd17873bb70a56a23acc259bd Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:40:21 +0100 Subject: [PATCH 1/8] update assistant decortators for table storage optional params --- azure/functions/decorators/openai.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/azure/functions/decorators/openai.py b/azure/functions/decorators/openai.py index df459c1c..38fe1192 100644 --- a/azure/functions/decorators/openai.py +++ b/azure/functions/decorators/openai.py @@ -77,10 +77,14 @@ def __init__(self, name: str, id: str, timestamp_utc: str, + chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", + collection_name: Optional[str] = "SampleChatState", data_type: Optional[DataType] = None, **kwargs): self.id = id self.timestamp_utc = timestamp_utc + self.chat_storage_connection_setting = chat_storage_connection_setting + self.collection_name = collection_name super().__init__(name=name, data_type=data_type) @@ -165,12 +169,16 @@ def __init__(self, name: str, id: str, user_message: str, model: Optional[str] = None, + chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", + collection_name: Optional[str] = "SampleChatState", data_type: Optional[DataType] = None, **kwargs): self.name = name self.id = id self.user_message = user_message self.model = model + self.chat_storage_connection_setting = chat_storage_connection_setting + self.collection_name = collection_name super().__init__(name=name, data_type=data_type) From f02fc5c8bb5e8e21a35b73241b899a6f7e2f2689 Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:11:25 +0100 Subject: [PATCH 2/8] update functionapp and tests --- azure/functions/decorators/function_app.py | 18 ++++++++++++++++++ tests/decorators/test_openai.py | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/azure/functions/decorators/function_app.py b/azure/functions/decorators/function_app.py index 773bf5da..86838c4e 100644 --- a/azure/functions/decorators/function_app.py +++ b/azure/functions/decorators/function_app.py @@ -3266,6 +3266,8 @@ def assistant_query_input(self, arg_name: str, id: str, timestamp_utc: str, + chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", + collection_name: Optional[str] = "SampleChatState", data_type: Optional[ Union[DataType, str]] = None, **kwargs) \ @@ -3278,6 +3280,11 @@ def assistant_query_input(self, :param timestamp_utc: the timestamp of the earliest message in the chat history to fetch. The timestamp should be in ISO 8601 format - for example, 2023-08-01T00:00:00Z. + :param chat_storage_connection_setting: The configuration section name + for the table settings for assistant chat storage. The default value is + "AzureWebJobsStorage". + :param collection_name: The table collection name for assistant chat + storage. The default value is "SampleChatState". :param id: The ID of the Assistant to query. :param data_type: Defines how Functions runtime should treat the parameter value @@ -3295,6 +3302,8 @@ def decorator(): name=arg_name, id=id, timestamp_utc=timestamp_utc, + chat_storage_connection_setting=chat_storage_connection_setting, + collection_name=collection_name, data_type=parse_singular_param_to_enum(data_type, DataType), **kwargs)) @@ -3308,6 +3317,8 @@ def assistant_post_input(self, arg_name: str, id: str, user_message: str, model: Optional[str] = None, + chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", + collection_name: Optional[str] = "SampleChatState", data_type: Optional[ Union[DataType, str]] = None, **kwargs) \ @@ -3321,6 +3332,11 @@ def assistant_post_input(self, arg_name: str, :param user_message: The user message that user has entered for assistant to respond to. :param model: The OpenAI chat model to use. + :param chat_storage_connection_setting: The configuration section name + for the table settings for assistant chat storage. The default value is + "AzureWebJobsStorage". + :param collection_name: The table collection name for assistant chat + storage. The default value is "SampleChatState". :param data_type: Defines how Functions runtime should treat the parameter value :param kwargs: Keyword arguments for specifying additional binding @@ -3338,6 +3354,8 @@ def decorator(): id=id, user_message=user_message, model=model, + chat_storage_connection_setting=chat_storage_connection_setting, + collection_name=collection_name, data_type=parse_singular_param_to_enum(data_type, DataType), **kwargs)) diff --git a/tests/decorators/test_openai.py b/tests/decorators/test_openai.py index f2ebdaca..410b13a9 100644 --- a/tests/decorators/test_openai.py +++ b/tests/decorators/test_openai.py @@ -57,6 +57,8 @@ def test_text_completion_input_valid_creation(self): def test_assistant_query_input_valid_creation(self): input = AssistantQueryInput(name="test", timestamp_utc="timestamp_utc", + chat_storage_connection_setting="AzureWebJobsStorage", + collection_name="SampleChatState", data_type=DataType.UNDEFINED, id="test_id", type="assistantQueryInput", @@ -66,6 +68,8 @@ def test_assistant_query_input_valid_creation(self): self.assertEqual(input.get_dict_repr(), {"name": "test", "timestampUtc": "timestamp_utc", + "chat_storage_connection_setting": "AzureWebJobsStorage", + "collection_name": "SampleChatState", "dataType": DataType.UNDEFINED, "direction": BindingDirection.IN, "type": "assistantQuery", @@ -111,6 +115,8 @@ def test_assistant_post_input_valid_creation(self): input = AssistantPostInput(name="test", id="test_id", model="test_model", + chat_storage_connection_setting="AzureWebJobsStorage", + collection_name="SampleChatState", user_message="test_message", data_type=DataType.UNDEFINED, dummy_field="dummy") @@ -120,6 +126,8 @@ def test_assistant_post_input_valid_creation(self): {"name": "test", "id": "test_id", "model": "test_model", + "chat_storage_connection_setting": "AzureWebJobsStorage", + "collection_name": "SampleChatState", "userMessage": "test_message", "dataType": DataType.UNDEFINED, "direction": BindingDirection.IN, From c33ba6413e511727f2f452af8f6b71d6d1216e1b Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:27:29 +0100 Subject: [PATCH 3/8] remove underscores --- tests/decorators/test_openai.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/decorators/test_openai.py b/tests/decorators/test_openai.py index 410b13a9..5d0e4c1c 100644 --- a/tests/decorators/test_openai.py +++ b/tests/decorators/test_openai.py @@ -68,8 +68,8 @@ def test_assistant_query_input_valid_creation(self): self.assertEqual(input.get_dict_repr(), {"name": "test", "timestampUtc": "timestamp_utc", - "chat_storage_connection_setting": "AzureWebJobsStorage", - "collection_name": "SampleChatState", + "chatstorageconnectionsetting": "AzureWebJobsStorage", + "collectionname": "SampleChatState", "dataType": DataType.UNDEFINED, "direction": BindingDirection.IN, "type": "assistantQuery", @@ -126,8 +126,8 @@ def test_assistant_post_input_valid_creation(self): {"name": "test", "id": "test_id", "model": "test_model", - "chat_storage_connection_setting": "AzureWebJobsStorage", - "collection_name": "SampleChatState", + "chatstorageconnectionsetting": "AzureWebJobsStorage", + "collectionname": "SampleChatState", "userMessage": "test_message", "dataType": DataType.UNDEFINED, "direction": BindingDirection.IN, From d126708c1f4f4720cb7074155f67bc9756621cd8 Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:41:34 +0100 Subject: [PATCH 4/8] fix casing --- tests/decorators/test_openai.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/decorators/test_openai.py b/tests/decorators/test_openai.py index 5d0e4c1c..b596eb95 100644 --- a/tests/decorators/test_openai.py +++ b/tests/decorators/test_openai.py @@ -68,8 +68,8 @@ def test_assistant_query_input_valid_creation(self): self.assertEqual(input.get_dict_repr(), {"name": "test", "timestampUtc": "timestamp_utc", - "chatstorageconnectionsetting": "AzureWebJobsStorage", - "collectionname": "SampleChatState", + "chatStorageConnectionSetting": "AzureWebJobsStorage", + "collectioName": "SampleChatState", "dataType": DataType.UNDEFINED, "direction": BindingDirection.IN, "type": "assistantQuery", @@ -126,8 +126,8 @@ def test_assistant_post_input_valid_creation(self): {"name": "test", "id": "test_id", "model": "test_model", - "chatstorageconnectionsetting": "AzureWebJobsStorage", - "collectionname": "SampleChatState", + "chatStorageConnectionSetting": "AzureWebJobsStorage", + "collectioName": "SampleChatState", "userMessage": "test_message", "dataType": DataType.UNDEFINED, "direction": BindingDirection.IN, From f42dce4026b0676a7ddd83d45d86716dd1e3a2f6 Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Tue, 24 Sep 2024 10:29:24 +0100 Subject: [PATCH 5/8] correct typo --- tests/decorators/test_openai.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/decorators/test_openai.py b/tests/decorators/test_openai.py index b596eb95..c3b2e575 100644 --- a/tests/decorators/test_openai.py +++ b/tests/decorators/test_openai.py @@ -69,7 +69,7 @@ def test_assistant_query_input_valid_creation(self): {"name": "test", "timestampUtc": "timestamp_utc", "chatStorageConnectionSetting": "AzureWebJobsStorage", - "collectioName": "SampleChatState", + "collectionName": "SampleChatState", "dataType": DataType.UNDEFINED, "direction": BindingDirection.IN, "type": "assistantQuery", @@ -127,7 +127,7 @@ def test_assistant_post_input_valid_creation(self): "id": "test_id", "model": "test_model", "chatStorageConnectionSetting": "AzureWebJobsStorage", - "collectioName": "SampleChatState", + "collectionName": "SampleChatState", "userMessage": "test_message", "dataType": DataType.UNDEFINED, "direction": BindingDirection.IN, From 053e21a3f413fdc71379e74c5add73f75061f5b2 Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Tue, 24 Sep 2024 11:46:04 +0100 Subject: [PATCH 6/8] resolve linting issues --- azure/functions/decorators/function_app.py | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/azure/functions/decorators/function_app.py b/azure/functions/decorators/function_app.py index 86838c4e..f999db06 100644 --- a/azure/functions/decorators/function_app.py +++ b/azure/functions/decorators/function_app.py @@ -80,8 +80,8 @@ def __str__(self): return self.get_function_json() def __call__(self, *args, **kwargs): - """This would allow the Function object to be directly callable and runnable - directly using the interpreter locally. + """This would allow the Function object to be directly callable + and runnable directly using the interpreter locally. Example: @app.route(route="http_trigger") @@ -332,8 +332,8 @@ def decorator(): return wrap def _get_durable_blueprint(self): - """Attempt to import the Durable Functions SDK from which DF decorators are - implemented. + """Attempt to import the Durable Functions SDK from which DF + decorators are implemented. """ try: @@ -3266,8 +3266,8 @@ def assistant_query_input(self, arg_name: str, id: str, timestamp_utc: str, - chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", - collection_name: Optional[str] = "SampleChatState", + chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", # noqa: E501 + collection_name: Optional[str] = "SampleChatState", # noqa: E501 data_type: Optional[ Union[DataType, str]] = None, **kwargs) \ @@ -3280,10 +3280,10 @@ def assistant_query_input(self, :param timestamp_utc: the timestamp of the earliest message in the chat history to fetch. The timestamp should be in ISO 8601 format - for example, 2023-08-01T00:00:00Z. - :param chat_storage_connection_setting: The configuration section name - for the table settings for assistant chat storage. The default value is + :param chat_storage_connection_setting: The configuration section name + for the table settings for assistant chat storage. The default value is "AzureWebJobsStorage". - :param collection_name: The table collection name for assistant chat + :param collection_name: The table collection name for assistant chat storage. The default value is "SampleChatState". :param id: The ID of the Assistant to query. :param data_type: Defines how Functions runtime should treat the @@ -3302,7 +3302,7 @@ def decorator(): name=arg_name, id=id, timestamp_utc=timestamp_utc, - chat_storage_connection_setting=chat_storage_connection_setting, + chat_storage_connection_setting=chat_storage_connection_setting, # noqa: E501 collection_name=collection_name, data_type=parse_singular_param_to_enum(data_type, DataType), @@ -3317,8 +3317,8 @@ def assistant_post_input(self, arg_name: str, id: str, user_message: str, model: Optional[str] = None, - chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", - collection_name: Optional[str] = "SampleChatState", + chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", # noqa: E501 + collection_name: Optional[str] = "SampleChatState", # noqa: E501 data_type: Optional[ Union[DataType, str]] = None, **kwargs) \ @@ -3332,10 +3332,10 @@ def assistant_post_input(self, arg_name: str, :param user_message: The user message that user has entered for assistant to respond to. :param model: The OpenAI chat model to use. - :param chat_storage_connection_setting: The configuration section name - for the table settings for assistant chat storage. The default value is + :param chat_storage_connection_setting: The configuration section name + for the table settings for assistant chat storage. The default value is "AzureWebJobsStorage". - :param collection_name: The table collection name for assistant chat + :param collection_name: The table collection name for assistant chat storage. The default value is "SampleChatState". :param data_type: Defines how Functions runtime should treat the parameter value @@ -3354,7 +3354,7 @@ def decorator(): id=id, user_message=user_message, model=model, - chat_storage_connection_setting=chat_storage_connection_setting, + chat_storage_connection_setting=chat_storage_connection_setting, # noqa: E501 collection_name=collection_name, data_type=parse_singular_param_to_enum(data_type, DataType), From 005c2d0a47c8d1beb022e9a90e1fe2ee3006352c Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Tue, 24 Sep 2024 11:50:52 +0100 Subject: [PATCH 7/8] fix linting issues in two more files --- azure/functions/decorators/openai.py | 4 ++-- tests/decorators/test_openai.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/azure/functions/decorators/openai.py b/azure/functions/decorators/openai.py index 38fe1192..ff3da54e 100644 --- a/azure/functions/decorators/openai.py +++ b/azure/functions/decorators/openai.py @@ -77,7 +77,7 @@ def __init__(self, name: str, id: str, timestamp_utc: str, - chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", + chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", # noqa: E501 collection_name: Optional[str] = "SampleChatState", data_type: Optional[DataType] = None, **kwargs): @@ -169,7 +169,7 @@ def __init__(self, name: str, id: str, user_message: str, model: Optional[str] = None, - chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", + chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", # noqa: E501 collection_name: Optional[str] = "SampleChatState", data_type: Optional[DataType] = None, **kwargs): diff --git a/tests/decorators/test_openai.py b/tests/decorators/test_openai.py index c3b2e575..886e46ca 100644 --- a/tests/decorators/test_openai.py +++ b/tests/decorators/test_openai.py @@ -57,7 +57,7 @@ def test_text_completion_input_valid_creation(self): def test_assistant_query_input_valid_creation(self): input = AssistantQueryInput(name="test", timestamp_utc="timestamp_utc", - chat_storage_connection_setting="AzureWebJobsStorage", + chat_storage_connection_setting="AzureWebJobsStorage", # noqa: E501 collection_name="SampleChatState", data_type=DataType.UNDEFINED, id="test_id", @@ -68,7 +68,7 @@ def test_assistant_query_input_valid_creation(self): self.assertEqual(input.get_dict_repr(), {"name": "test", "timestampUtc": "timestamp_utc", - "chatStorageConnectionSetting": "AzureWebJobsStorage", + "chatStorageConnectionSetting": "AzureWebJobsStorage", # noqa: E501 "collectionName": "SampleChatState", "dataType": DataType.UNDEFINED, "direction": BindingDirection.IN, @@ -115,7 +115,7 @@ def test_assistant_post_input_valid_creation(self): input = AssistantPostInput(name="test", id="test_id", model="test_model", - chat_storage_connection_setting="AzureWebJobsStorage", + chat_storage_connection_setting="AzureWebJobsStorage", # noqa: E501 collection_name="SampleChatState", user_message="test_message", data_type=DataType.UNDEFINED, @@ -126,7 +126,7 @@ def test_assistant_post_input_valid_creation(self): {"name": "test", "id": "test_id", "model": "test_model", - "chatStorageConnectionSetting": "AzureWebJobsStorage", + "chatStorageConnectionSetting": "AzureWebJobsStorage", # noqa: E501 "collectionName": "SampleChatState", "userMessage": "test_message", "dataType": DataType.UNDEFINED, From 6167c2c1e8a7e87697e1daf56061396a831e5f37 Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Wed, 2 Oct 2024 11:35:05 +0100 Subject: [PATCH 8/8] update default collection name to ChatState --- azure/functions/decorators/function_app.py | 8 ++++---- azure/functions/decorators/openai.py | 4 ++-- tests/decorators/test_openai.py | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/azure/functions/decorators/function_app.py b/azure/functions/decorators/function_app.py index f999db06..1378b2cb 100644 --- a/azure/functions/decorators/function_app.py +++ b/azure/functions/decorators/function_app.py @@ -3267,7 +3267,7 @@ def assistant_query_input(self, id: str, timestamp_utc: str, chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", # noqa: E501 - collection_name: Optional[str] = "SampleChatState", # noqa: E501 + collection_name: Optional[str] = "ChatState", # noqa: E501 data_type: Optional[ Union[DataType, str]] = None, **kwargs) \ @@ -3284,7 +3284,7 @@ def assistant_query_input(self, for the table settings for assistant chat storage. The default value is "AzureWebJobsStorage". :param collection_name: The table collection name for assistant chat - storage. The default value is "SampleChatState". + storage. The default value is "ChatState". :param id: The ID of the Assistant to query. :param data_type: Defines how Functions runtime should treat the parameter value @@ -3318,7 +3318,7 @@ def assistant_post_input(self, arg_name: str, user_message: str, model: Optional[str] = None, chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", # noqa: E501 - collection_name: Optional[str] = "SampleChatState", # noqa: E501 + collection_name: Optional[str] = "ChatState", # noqa: E501 data_type: Optional[ Union[DataType, str]] = None, **kwargs) \ @@ -3336,7 +3336,7 @@ def assistant_post_input(self, arg_name: str, for the table settings for assistant chat storage. The default value is "AzureWebJobsStorage". :param collection_name: The table collection name for assistant chat - storage. The default value is "SampleChatState". + storage. The default value is "ChatState". :param data_type: Defines how Functions runtime should treat the parameter value :param kwargs: Keyword arguments for specifying additional binding diff --git a/azure/functions/decorators/openai.py b/azure/functions/decorators/openai.py index ff3da54e..2563a78e 100644 --- a/azure/functions/decorators/openai.py +++ b/azure/functions/decorators/openai.py @@ -78,7 +78,7 @@ def __init__(self, id: str, timestamp_utc: str, chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", # noqa: E501 - collection_name: Optional[str] = "SampleChatState", + collection_name: Optional[str] = "ChatState", data_type: Optional[DataType] = None, **kwargs): self.id = id @@ -170,7 +170,7 @@ def __init__(self, name: str, user_message: str, model: Optional[str] = None, chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", # noqa: E501 - collection_name: Optional[str] = "SampleChatState", + collection_name: Optional[str] = "ChatState", data_type: Optional[DataType] = None, **kwargs): self.name = name diff --git a/tests/decorators/test_openai.py b/tests/decorators/test_openai.py index 886e46ca..c2009c72 100644 --- a/tests/decorators/test_openai.py +++ b/tests/decorators/test_openai.py @@ -58,7 +58,7 @@ def test_assistant_query_input_valid_creation(self): input = AssistantQueryInput(name="test", timestamp_utc="timestamp_utc", chat_storage_connection_setting="AzureWebJobsStorage", # noqa: E501 - collection_name="SampleChatState", + collection_name="ChatState", data_type=DataType.UNDEFINED, id="test_id", type="assistantQueryInput", @@ -69,7 +69,7 @@ def test_assistant_query_input_valid_creation(self): {"name": "test", "timestampUtc": "timestamp_utc", "chatStorageConnectionSetting": "AzureWebJobsStorage", # noqa: E501 - "collectionName": "SampleChatState", + "collectionName": "ChatState", "dataType": DataType.UNDEFINED, "direction": BindingDirection.IN, "type": "assistantQuery", @@ -116,7 +116,7 @@ def test_assistant_post_input_valid_creation(self): id="test_id", model="test_model", chat_storage_connection_setting="AzureWebJobsStorage", # noqa: E501 - collection_name="SampleChatState", + collection_name="ChatState", user_message="test_message", data_type=DataType.UNDEFINED, dummy_field="dummy") @@ -127,7 +127,7 @@ def test_assistant_post_input_valid_creation(self): "id": "test_id", "model": "test_model", "chatStorageConnectionSetting": "AzureWebJobsStorage", # noqa: E501 - "collectionName": "SampleChatState", + "collectionName": "ChatState", "userMessage": "test_message", "dataType": DataType.UNDEFINED, "direction": BindingDirection.IN,