-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Enable Memory Store operations on AIProjectClient (continuing Paul's work) #43999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,808
−432
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
ab77791
Rename `items_property` to `items_property` in emitted code
dargilco 0422663
Patch model and sync operations
dargilco f51db46
Fix sync operations patch
dargilco 9d5efa6
Add async operations and classes
dargilco 119b0c9
Rename file
dargilco 302aea0
Fix missing import of Tuple
dargilco 95d72ea
Merge branch 'main' into dargilco/memory-store
dargilco e430b88
Add env variables for Memory Store samples
dargilco 498734b
Merge branch 'dargilco/memory-store' of https://github.com/Azure/azur…
dargilco 32f2f01
Updates to sample_agent_memory.py
dargilco 5d5d925
Move/rename samples
dargilco b4eb822
Fix import in async memory operations. Add async MemorySearchTool sample
dargilco 04affee
Merge branch 'main' into dargilco/memory-store
dargilco 3426033
Update changelog and package readme
dargilco 1300023
Fix MyPy errors
dargilco 3805ebb
Fix quality gates
dargilco 4e2235e
Minor updates to CRUD sample. Add async CRUD sample
dargilco deb35ee
Add default options to MemoryStoreDefaultDefinition to workaround ser…
dargilco 97a9d20
Sample updates
dargilco e4d1a53
Fix bug in sync patched code. Add async basic sample
dargilco 430dd3c
Run `black --config ../../../eng/black-pyproject.toml .`
dargilco 9476ba4
Add advanced aasync sample by CoPilot. Have not run it yet
dargilco 416fc72
Upate README.md
dargilco b8b59b5
Fix code snippet in README.md
dargilco 58c30a8
Fix typo in README.md
dargilco 9d80501
Address Copilot code review comments
dargilco 3f3a529
Merge branch 'main' into dargilco/memory-store
dargilco d739ee5
Add failed to finished state.
bojunehsu 42c0fcc
Merge branch 'main' into dargilco/memory-store
dargilco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
230 changes: 230 additions & 0 deletions
230
sdk/ai/azure-ai-projects/azure/ai/projects/aio/operations/_patch_memories_async.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,230 @@ | ||
| # pylint: disable=line-too-long,useless-suppression | ||
| # ------------------------------------ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| # ------------------------------------ | ||
| """Customize generated code here. | ||
|
|
||
| Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize | ||
| """ | ||
| from typing import Union, Optional, Any, List, overload, IO, cast | ||
| from azure.core.tracing.decorator_async import distributed_trace_async | ||
| from azure.core.polling import AsyncNoPolling | ||
| from azure.core.utils import case_insensitive_dict | ||
| from ... import models as _models | ||
| from ...models import ( | ||
| MemoryStoreOperationUsage, | ||
| MemoryStoreOperationUsageInputTokensDetails, | ||
| MemoryStoreOperationUsageOutputTokensDetails, | ||
| MemoryStoreUpdateCompletedResult, | ||
| AsyncUpdateMemoriesLROPoller, | ||
| AsyncUpdateMemoriesLROPollingMethod, | ||
| ) | ||
| from ._operations import JSON, _Unset, ClsType, MemoryStoresOperations as GenerateMemoryStoresOperations | ||
| from ..._validation import api_version_validation | ||
| from ..._utils.model_base import _deserialize | ||
|
|
||
|
|
||
| class MemoryStoresOperations(GenerateMemoryStoresOperations): | ||
|
|
||
| @overload | ||
| async def begin_update_memories( | ||
| self, | ||
| name: str, | ||
| *, | ||
| scope: str, | ||
| content_type: str = "application/json", | ||
| items: Optional[List[_models.ItemParam]] = None, | ||
| previous_update_id: Optional[str] = None, | ||
| update_delay: Optional[int] = None, | ||
| **kwargs: Any, | ||
| ) -> AsyncUpdateMemoriesLROPoller: | ||
| """Update memory store with conversation memories. | ||
|
|
||
| :param name: The name of the memory store to update. Required. | ||
| :type name: str | ||
| :keyword scope: The namespace that logically groups and isolates memories, such as a user ID. | ||
| Required. | ||
| :paramtype scope: str | ||
| :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. | ||
| Default value is "application/json". | ||
| :paramtype content_type: str | ||
| :keyword items: Conversation items from which to extract memories. Default value is None. | ||
| :paramtype items: list[~azure.ai.projects.models.ItemParam] | ||
| :keyword previous_update_id: The unique ID of the previous update request, enabling incremental | ||
| memory updates from where the last operation left off. Default value is None. | ||
| :paramtype previous_update_id: str | ||
| :keyword update_delay: Timeout period before processing the memory update in seconds. | ||
| If a new update request is received during this period, it will cancel the current request and | ||
| reset the timeout. | ||
| Set to 0 to immediately trigger the update without delay. | ||
| Defaults to 300 (5 minutes). Default value is None. | ||
| :paramtype update_delay: int | ||
| :return: An instance of AsyncUpdateMemoriesLROPoller that returns MemoryStoreUpdateCompletedResult. The | ||
| MemoryStoreUpdateCompletedResult is compatible with MutableMapping | ||
| :rtype: | ||
| ~azure.ai.projects.models.AsyncUpdateMemoriesLROPoller | ||
| :raises ~azure.core.exceptions.HttpResponseError: | ||
| """ | ||
|
|
||
| @overload | ||
| async def begin_update_memories( | ||
| self, name: str, body: JSON, *, content_type: str = "application/json", **kwargs: Any | ||
| ) -> AsyncUpdateMemoriesLROPoller: | ||
| """Update memory store with conversation memories. | ||
|
|
||
| :param name: The name of the memory store to update. Required. | ||
| :type name: str | ||
| :param body: Required. | ||
| :type body: JSON | ||
| :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. | ||
| Default value is "application/json". | ||
| :paramtype content_type: str | ||
| :return: An instance of AsyncUpdateMemoriesLROPoller that returns MemoryStoreUpdateCompletedResult. The | ||
| MemoryStoreUpdateCompletedResult is compatible with MutableMapping | ||
| :rtype: | ||
| ~azure.ai.projects.models.AsyncUpdateMemoriesLROPoller | ||
| :raises ~azure.core.exceptions.HttpResponseError: | ||
| """ | ||
|
|
||
| @overload | ||
| async def begin_update_memories( | ||
| self, name: str, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any | ||
| ) -> AsyncUpdateMemoriesLROPoller: | ||
| """Update memory store with conversation memories. | ||
|
|
||
| :param name: The name of the memory store to update. Required. | ||
| :type name: str | ||
| :param body: Required. | ||
| :type body: IO[bytes] | ||
| :keyword content_type: Body Parameter content-type. Content type parameter for binary body. | ||
| Default value is "application/json". | ||
| :paramtype content_type: str | ||
| :return: An instance of AsyncUpdateMemoriesLROPoller that returns MemoryStoreUpdateCompletedResult. The | ||
| MemoryStoreUpdateCompletedResult is compatible with MutableMapping | ||
| :rtype: | ||
| ~azure.ai.projects.models.AsyncUpdateMemoriesLROPoller | ||
| :raises ~azure.core.exceptions.HttpResponseError: | ||
| """ | ||
|
|
||
| @distributed_trace_async | ||
| @api_version_validation( | ||
| method_added_on="2025-11-15-preview", | ||
| params_added_on={"2025-11-15-preview": ["api_version", "name", "content_type", "accept"]}, | ||
| api_versions_list=["2025-11-15-preview"], | ||
| ) | ||
| async def begin_update_memories( | ||
| self, | ||
| name: str, | ||
| body: Union[JSON, IO[bytes]] = _Unset, | ||
| *, | ||
| scope: str = _Unset, | ||
| items: Optional[List[_models.ItemParam]] = None, | ||
| previous_update_id: Optional[str] = None, | ||
| update_delay: Optional[int] = None, | ||
| **kwargs: Any, | ||
| ) -> AsyncUpdateMemoriesLROPoller: | ||
| """Update memory store with conversation memories. | ||
|
|
||
| :param name: The name of the memory store to update. Required. | ||
| :type name: str | ||
| :param body: Is either a JSON type or a IO[bytes] type. Required. | ||
| :type body: JSON or IO[bytes] | ||
| :keyword scope: The namespace that logically groups and isolates memories, such as a user ID. | ||
| Required. | ||
| :paramtype scope: str | ||
| :keyword items: Conversation items from which to extract memories. Default value is None. | ||
| :paramtype items: list[~azure.ai.projects.models.ItemParam] | ||
| :keyword previous_update_id: The unique ID of the previous update request, enabling incremental | ||
| memory updates from where the last operation left off. Default value is None. | ||
| :paramtype previous_update_id: str | ||
| :keyword update_delay: Timeout period before processing the memory update in seconds. | ||
| If a new update request is received during this period, it will cancel the current request and | ||
| reset the timeout. | ||
| Set to 0 to immediately trigger the update without delay. | ||
| Defaults to 300 (5 minutes). Default value is None. | ||
| :paramtype update_delay: int | ||
| :return: An instance of AsyncLROPoller that returns MemoryStoreUpdateCompletedResult. The | ||
| MemoryStoreUpdateCompletedResult is compatible with MutableMapping | ||
| :rtype: | ||
| ~azure.ai.projects.models.AsyncUpdateMemoriesLROPoller | ||
| :raises ~azure.core.exceptions.HttpResponseError: | ||
| """ | ||
| _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) | ||
| _params = kwargs.pop("params", {}) or {} | ||
|
|
||
| content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) | ||
| cls: ClsType[_models.MemoryStoreUpdateCompletedResult] = kwargs.pop("cls", None) | ||
| polling: Union[bool, AsyncUpdateMemoriesLROPollingMethod] = kwargs.pop("polling", True) | ||
| lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) | ||
| cont_token: Optional[str] = kwargs.pop("continuation_token", None) | ||
| if cont_token is None: | ||
| raw_result = await self._update_memories_initial( | ||
| name=name, | ||
| body=body, | ||
| scope=scope, | ||
| items=items, | ||
| previous_update_id=previous_update_id, | ||
| update_delay=update_delay, | ||
| content_type=content_type, | ||
| cls=lambda x, y, z: x, | ||
| headers=_headers, | ||
| params=_params, | ||
| **kwargs, | ||
| ) | ||
| await raw_result.http_response.read() # type: ignore | ||
|
|
||
| raw_result.http_response.status_code = 202 # type: ignore | ||
| raw_result.http_response.headers["Operation-Location"] = ( # type: ignore | ||
| f"{self._config.endpoint}/memory_stores/{name}/updates/{raw_result.http_response.json().get('update_id')}?api-version=2025-11-15-preview" # type: ignore | ||
| ) | ||
|
|
||
| kwargs.pop("error_map", None) | ||
|
|
||
| def get_long_running_output(pipeline_response): | ||
| response_headers = {} | ||
| response = pipeline_response.http_response | ||
| response_headers["Operation-Location"] = self._deserialize( | ||
| "str", response.headers.get("Operation-Location") | ||
| ) | ||
|
|
||
| deserialized = _deserialize(MemoryStoreUpdateCompletedResult, response.json().get("result", None)) | ||
| if deserialized is None: | ||
| usage = MemoryStoreOperationUsage( | ||
| embedding_tokens=0, | ||
| input_tokens=0, | ||
| input_tokens_details=MemoryStoreOperationUsageInputTokensDetails(cached_tokens=0), | ||
| output_tokens=0, | ||
| output_tokens_details=MemoryStoreOperationUsageOutputTokensDetails(reasoning_tokens=0), | ||
| total_tokens=0, | ||
| ) | ||
| deserialized = MemoryStoreUpdateCompletedResult(memory_operations=[], usage=usage) | ||
| if cls: | ||
| return cls(pipeline_response, deserialized, response_headers) # type: ignore | ||
| return deserialized | ||
|
|
||
| path_format_arguments = { | ||
| "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), | ||
| } | ||
|
|
||
| if polling is True: | ||
| polling_method: AsyncUpdateMemoriesLROPollingMethod = AsyncUpdateMemoriesLROPollingMethod( | ||
| lro_delay, path_format_arguments=path_format_arguments, **kwargs | ||
| ) | ||
| elif polling is False: | ||
| polling_method = cast(AsyncUpdateMemoriesLROPollingMethod, AsyncNoPolling()) | ||
| else: | ||
| polling_method = polling | ||
| if cont_token: | ||
| return AsyncUpdateMemoriesLROPoller.from_continuation_token( | ||
| polling_method=polling_method, | ||
| continuation_token=cont_token, | ||
| client=self._client, | ||
| deserialization_callback=get_long_running_output, | ||
| ) | ||
| return AsyncUpdateMemoriesLROPoller( | ||
| self._client, | ||
| raw_result, # type: ignore[possibly-undefined] | ||
| get_long_running_output, | ||
| polling_method, # pylint: disable=possibly-used-before-assignment | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.