Skip to content

Commit a4c07f6

Browse files
authored
fix: assistant_post_input and assistant_query_input decorator params updated to configure custom table storage (#244)
* update assistant decortators for table storage optional params * update functionapp and tests * remove underscores * fix casing * correct typo * resolve linting issues * fix linting issues in two more files * update default collection name to ChatState
1 parent 6356f6f commit a4c07f6

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

azure/functions/decorators/function_app.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def __str__(self):
8080
return self.get_function_json()
8181

8282
def __call__(self, *args, **kwargs):
83-
"""This would allow the Function object to be directly callable and runnable
84-
directly using the interpreter locally.
83+
"""This would allow the Function object to be directly callable
84+
and runnable directly using the interpreter locally.
8585
8686
Example:
8787
@app.route(route="http_trigger")
@@ -332,8 +332,8 @@ def decorator():
332332
return wrap
333333

334334
def _get_durable_blueprint(self):
335-
"""Attempt to import the Durable Functions SDK from which DF decorators are
336-
implemented.
335+
"""Attempt to import the Durable Functions SDK from which DF
336+
decorators are implemented.
337337
"""
338338

339339
try:
@@ -3266,6 +3266,8 @@ def assistant_query_input(self,
32663266
arg_name: str,
32673267
id: str,
32683268
timestamp_utc: str,
3269+
chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", # noqa: E501
3270+
collection_name: Optional[str] = "ChatState", # noqa: E501
32693271
data_type: Optional[
32703272
Union[DataType, str]] = None,
32713273
**kwargs) \
@@ -3278,6 +3280,11 @@ def assistant_query_input(self,
32783280
:param timestamp_utc: the timestamp of the earliest message in the chat
32793281
history to fetch. The timestamp should be in ISO 8601 format - for
32803282
example, 2023-08-01T00:00:00Z.
3283+
:param chat_storage_connection_setting: The configuration section name
3284+
for the table settings for assistant chat storage. The default value is
3285+
"AzureWebJobsStorage".
3286+
:param collection_name: The table collection name for assistant chat
3287+
storage. The default value is "ChatState".
32813288
:param id: The ID of the Assistant to query.
32823289
:param data_type: Defines how Functions runtime should treat the
32833290
parameter value
@@ -3295,6 +3302,8 @@ def decorator():
32953302
name=arg_name,
32963303
id=id,
32973304
timestamp_utc=timestamp_utc,
3305+
chat_storage_connection_setting=chat_storage_connection_setting, # noqa: E501
3306+
collection_name=collection_name,
32983307
data_type=parse_singular_param_to_enum(data_type,
32993308
DataType),
33003309
**kwargs))
@@ -3308,6 +3317,8 @@ def assistant_post_input(self, arg_name: str,
33083317
id: str,
33093318
user_message: str,
33103319
model: Optional[str] = None,
3320+
chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", # noqa: E501
3321+
collection_name: Optional[str] = "ChatState", # noqa: E501
33113322
data_type: Optional[
33123323
Union[DataType, str]] = None,
33133324
**kwargs) \
@@ -3321,6 +3332,11 @@ def assistant_post_input(self, arg_name: str,
33213332
:param user_message: The user message that user has entered for
33223333
assistant to respond to.
33233334
:param model: The OpenAI chat model to use.
3335+
:param chat_storage_connection_setting: The configuration section name
3336+
for the table settings for assistant chat storage. The default value is
3337+
"AzureWebJobsStorage".
3338+
:param collection_name: The table collection name for assistant chat
3339+
storage. The default value is "ChatState".
33243340
:param data_type: Defines how Functions runtime should treat the
33253341
parameter value
33263342
:param kwargs: Keyword arguments for specifying additional binding
@@ -3338,6 +3354,8 @@ def decorator():
33383354
id=id,
33393355
user_message=user_message,
33403356
model=model,
3357+
chat_storage_connection_setting=chat_storage_connection_setting, # noqa: E501
3358+
collection_name=collection_name,
33413359
data_type=parse_singular_param_to_enum(data_type,
33423360
DataType),
33433361
**kwargs))

azure/functions/decorators/openai.py

+8
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,14 @@ def __init__(self,
7777
name: str,
7878
id: str,
7979
timestamp_utc: str,
80+
chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", # noqa: E501
81+
collection_name: Optional[str] = "ChatState",
8082
data_type: Optional[DataType] = None,
8183
**kwargs):
8284
self.id = id
8385
self.timestamp_utc = timestamp_utc
86+
self.chat_storage_connection_setting = chat_storage_connection_setting
87+
self.collection_name = collection_name
8488
super().__init__(name=name, data_type=data_type)
8589

8690

@@ -165,12 +169,16 @@ def __init__(self, name: str,
165169
id: str,
166170
user_message: str,
167171
model: Optional[str] = None,
172+
chat_storage_connection_setting: Optional[str] = "AzureWebJobsStorage", # noqa: E501
173+
collection_name: Optional[str] = "ChatState",
168174
data_type: Optional[DataType] = None,
169175
**kwargs):
170176
self.name = name
171177
self.id = id
172178
self.user_message = user_message
173179
self.model = model
180+
self.chat_storage_connection_setting = chat_storage_connection_setting
181+
self.collection_name = collection_name
174182
super().__init__(name=name, data_type=data_type)
175183

176184

tests/decorators/test_openai.py

+8
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def test_text_completion_input_valid_creation(self):
5757
def test_assistant_query_input_valid_creation(self):
5858
input = AssistantQueryInput(name="test",
5959
timestamp_utc="timestamp_utc",
60+
chat_storage_connection_setting="AzureWebJobsStorage", # noqa: E501
61+
collection_name="ChatState",
6062
data_type=DataType.UNDEFINED,
6163
id="test_id",
6264
type="assistantQueryInput",
@@ -66,6 +68,8 @@ def test_assistant_query_input_valid_creation(self):
6668
self.assertEqual(input.get_dict_repr(),
6769
{"name": "test",
6870
"timestampUtc": "timestamp_utc",
71+
"chatStorageConnectionSetting": "AzureWebJobsStorage", # noqa: E501
72+
"collectionName": "ChatState",
6973
"dataType": DataType.UNDEFINED,
7074
"direction": BindingDirection.IN,
7175
"type": "assistantQuery",
@@ -111,6 +115,8 @@ def test_assistant_post_input_valid_creation(self):
111115
input = AssistantPostInput(name="test",
112116
id="test_id",
113117
model="test_model",
118+
chat_storage_connection_setting="AzureWebJobsStorage", # noqa: E501
119+
collection_name="ChatState",
114120
user_message="test_message",
115121
data_type=DataType.UNDEFINED,
116122
dummy_field="dummy")
@@ -120,6 +126,8 @@ def test_assistant_post_input_valid_creation(self):
120126
{"name": "test",
121127
"id": "test_id",
122128
"model": "test_model",
129+
"chatStorageConnectionSetting": "AzureWebJobsStorage", # noqa: E501
130+
"collectionName": "ChatState",
123131
"userMessage": "test_message",
124132
"dataType": DataType.UNDEFINED,
125133
"direction": BindingDirection.IN,

0 commit comments

Comments
 (0)