Skip to content

Commit dd67a01

Browse files
committed
merge fix
2 parents 9afeb5f + 458af33 commit dd67a01

File tree

20 files changed

+1289
-66
lines changed

20 files changed

+1289
-66
lines changed

sdk/cosmos/azure-cosmos/azure/cosmos/_change_feed/change_feed_state.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,7 @@ def from_initial_state(
383383

384384
feed_range: Optional[FeedRangeInternal] = None
385385
if change_feed_state_context.get("feedRange"):
386-
feed_range_str = base64.b64decode(change_feed_state_context["feedRange"]).decode('utf-8')
387-
feed_range_json = json.loads(feed_range_str)
388-
feed_range = FeedRangeInternalEpk.from_json(feed_range_json)
386+
feed_range = FeedRangeInternalEpk.from_json(change_feed_state_context["feedRange"])
389387
elif change_feed_state_context.get("partitionKey"):
390388
if change_feed_state_context.get("partitionKeyFeedRange"):
391389
feed_range =\

sdk/cosmos/azure-cosmos/azure/cosmos/aio/_container.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"""
2424
import warnings
2525
from datetime import datetime
26-
from typing import Any, Dict, Mapping, Optional, Sequence, Type, Union, List, Tuple, cast, overload
26+
from typing import Any, Dict, Mapping, Optional, Sequence, Type, Union, List, Tuple, cast, overload, Iterable
2727
from typing_extensions import Literal
2828

2929
from azure.core import MatchConditions
@@ -534,15 +534,15 @@ def query_items_change_feed(
534534
def query_items_change_feed(
535535
self,
536536
*,
537-
feed_range: str,
537+
feed_range: Dict[str, Any],
538538
max_item_count: Optional[int] = None,
539539
start_time: Optional[Union[datetime, Literal["Now", "Beginning"]]] = None,
540540
priority: Optional[Literal["High", "Low"]] = None,
541541
**kwargs: Any
542542
) -> AsyncItemPaged[Dict[str, Any]]:
543543
"""Get a sorted list of items that were changed, in the order in which they were modified.
544544
545-
:keyword str feed_range: The feed range that is used to define the scope.
545+
:keyword Dict[str, Any] feed_range: The feed range that is used to define the scope.
546546
:keyword int max_item_count: Max number of items to be returned in the enumeration operation.
547547
:keyword start_time: The start time to start processing chang feed items.
548548
Beginning: Processing the change feed items from the beginning of the change feed.
@@ -620,7 +620,7 @@ def query_items_change_feed( # pylint: disable=unused-argument
620620
"""Get a sorted list of items that were changed, in the order in which they were modified.
621621
622622
:keyword str continuation: The continuation token retrieved from previous response.
623-
:keyword str feed_range: The feed range that is used to define the scope.
623+
:keyword Dict[str, Any] feed_range: The feed range that is used to define the scope.
624624
:keyword partition_key: The partition key that is used to define the scope
625625
(logical partition or a subset of a container)
626626
:type partition_key: Union[str, int, float, bool, List[Union[str, int, float, bool]]]
@@ -1296,13 +1296,17 @@ async def read_feed_ranges(
12961296
*,
12971297
force_refresh: Optional[bool] = False,
12981298
**kwargs: Any
1299-
) -> List[str]:
1299+
) -> Iterable[Dict[str, Any]]:
13001300
""" Obtains a list of feed ranges that can be used to parallelize feed operations.
13011301
13021302
:keyword bool force_refresh:
13031303
Flag to indicate whether obtain the list of feed ranges directly from cache or refresh the cache.
13041304
:returns: A list representing the feed ranges in base64 encoded string
1305-
:rtype: List[str]
1305+
:rtype: Iterable[Dict[str, Any]]
1306+
1307+
.. note::
1308+
For each feed range, even through a Dict has been returned, but in the future, the structure may change.
1309+
Please just treat it as opaque and do not take any dependent on it.
13061310
13071311
"""
13081312
if force_refresh is True:
@@ -1315,5 +1319,7 @@ async def read_feed_ranges(
13151319
[Range("", "FF", True, False)],
13161320
**kwargs)
13171321

1318-
return [FeedRangeInternalEpk(Range.PartitionKeyRangeToRange(partitionKeyRange)).__str__()
1322+
feed_ranges = [FeedRangeInternalEpk(Range.PartitionKeyRangeToRange(partitionKeyRange)).to_dict()
13191323
for partitionKeyRange in partition_key_ranges]
1324+
1325+
return (feed_range for feed_range in feed_ranges)

sdk/cosmos/azure-cosmos/azure/cosmos/container.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"""
2424
import warnings
2525
from datetime import datetime
26-
from typing import Any, Dict, List, Optional, Sequence, Union, Tuple, Mapping, Type, cast, overload
26+
from typing import Any, Dict, List, Optional, Sequence, Union, Tuple, Mapping, Type, cast, overload, Iterable
2727
from typing_extensions import Literal
2828

2929
from azure.core import MatchConditions
@@ -354,7 +354,7 @@ def query_items_change_feed(
354354
def query_items_change_feed(
355355
self,
356356
*,
357-
feed_range: str,
357+
feed_range: Dict[str, Any],
358358
max_item_count: Optional[int] = None,
359359
start_time: Optional[Union[datetime, Literal["Now", "Beginning"]]] = None,
360360
priority: Optional[Literal["High", "Low"]] = None,
@@ -363,7 +363,7 @@ def query_items_change_feed(
363363

364364
"""Get a sorted list of items that were changed, in the order in which they were modified.
365365
366-
:keyword str feed_range: The feed range that is used to define the scope.
366+
:keyword Dict[str, Any] feed_range: The feed range that is used to define the scope.
367367
:keyword int max_item_count: Max number of items to be returned in the enumeration operation.
368368
:keyword start_time: The start time to start processing chang feed items.
369369
Beginning: Processing the change feed items from the beginning of the change feed.
@@ -440,7 +440,7 @@ def query_items_change_feed(
440440
"""Get a sorted list of items that were changed, in the order in which they were modified.
441441
442442
:keyword str continuation: The continuation token retrieved from previous response.
443-
:keyword str feed_range: The feed range that is used to define the scope.
443+
:keyword Dict[str, Any] feed_range: The feed range that is used to define the scope.
444444
:keyword partition_key: The partition key that is used to define the scope
445445
(logical partition or a subset of a container)
446446
:type partition_key: Union[str, int, float, bool, List[Union[str, int, float, bool]]]
@@ -1365,14 +1365,18 @@ def read_feed_ranges(
13651365
self,
13661366
*,
13671367
force_refresh: Optional[bool] = False,
1368-
**kwargs: Any) -> List[str]:
1368+
**kwargs: Any) -> Iterable[Dict[str, Any]]:
13691369

13701370
""" Obtains a list of feed ranges that can be used to parallelize feed operations.
13711371
13721372
:keyword bool force_refresh:
13731373
Flag to indicate whether obtain the list of feed ranges directly from cache or refresh the cache.
13741374
:returns: A list representing the feed ranges in base64 encoded string
1375-
:rtype: List[str]
1375+
:rtype: Iterable[Dict[str, Any]]
1376+
1377+
.. note::
1378+
For each feed range, even through a Dict has been returned, but in the future, the structure may change.
1379+
Please just treat it as opaque and do not take any dependent on it.
13761380
13771381
"""
13781382
if force_refresh is True:
@@ -1384,5 +1388,6 @@ def read_feed_ranges(
13841388
[Range("", "FF", True, False)], # default to full range
13851389
**kwargs)
13861390

1387-
return [FeedRangeInternalEpk(Range.PartitionKeyRangeToRange(partitionKeyRange)).__str__()
1391+
feed_ranges = [FeedRangeInternalEpk(Range.PartitionKeyRangeToRange(partitionKeyRange)).to_dict()
13881392
for partitionKeyRange in partition_key_ranges]
1393+
return (feed_range for feed_range in feed_ranges)

sdk/cosmos/azure-cosmos/samples/examples.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,11 @@
259259

260260
# Get the feed ranges list from container.
261261
# [START read_feed_ranges]
262-
container.read_feed_ranges()
262+
feed_ranges = list(container.read_feed_ranges())
263263
# [END read_feed_ranges]
264264

265265
# Query a sorted list of items that were changed for one feed range
266266
# [START query_items_change_feed]
267-
feed_ranges = container.read_feed_ranges()
268267
for item in container.query_items_change_feed(feed_range=feed_ranges[0]):
269268
print(json.dumps(item, indent=True))
270269
# [END query_items_change_feed]

sdk/cosmos/azure-cosmos/samples/examples_async.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,13 @@ async def examples_async():
265265

266266
# Get the feed ranges list from container.
267267
# [START read_feed_ranges]
268-
await container.read_feed_ranges()
268+
feed_ranges = list(await container.read_feed_ranges())
269269
# [END read_feed_ranges]
270270

271271
# Query a sorted list of items that were changed for one feed range.
272272
# The asynchronous client returns asynchronous iterators for its query methods;
273273
# as such, we iterate over it by using an async for loop
274274
# [START query_items_change_feed]
275-
feed_ranges = await container.read_feed_ranges()
276275
async for item in container.query_items_change_feed(feed_range=feed_ranges[0]):
277276
print(json.dumps(item, indent=True))
278277
# [END query_items_change_feed]

sdk/cosmos/azure-cosmos/test/test_change_feed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class TestChangeFeed:
3838
def test_get_feed_ranges(self, setup):
3939
created_collection = setup["created_db"].create_container("get_feed_ranges_" + str(uuid.uuid4()),
4040
PartitionKey(path="/pk"))
41-
result = created_collection.read_feed_ranges()
41+
result = list(created_collection.read_feed_ranges())
4242
assert len(result) == 1
4343

4444
@pytest.mark.parametrize("change_feed_filter_param", ["partitionKey", "partitionKeyRangeId", "feedRange"])
@@ -56,7 +56,7 @@ def test_query_change_feed_with_different_filter(self, change_feed_filter_param,
5656
elif change_feed_filter_param == "partitionKeyRangeId":
5757
filter_param = {"partition_key_range_id": "0"}
5858
elif change_feed_filter_param == "feedRange":
59-
feed_ranges = created_collection.read_feed_ranges()
59+
feed_ranges = list(created_collection.read_feed_ranges())
6060
assert len(feed_ranges) == 1
6161
filter_param = {"feed_range": feed_ranges[0]}
6262
else:

sdk/cosmos/azure-cosmos/test/test_change_feed_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class TestChangeFeedAsync:
4242
async def test_get_feed_ranges(self, setup):
4343
created_collection = await setup["created_db"].create_container("get_feed_ranges_" + str(uuid.uuid4()),
4444
PartitionKey(path="/pk"))
45-
result = await created_collection.read_feed_ranges()
45+
result = list(await created_collection.read_feed_ranges())
4646
assert len(result) == 1
4747

4848
@pytest.mark.parametrize("change_feed_filter_param", ["partitionKey", "partitionKeyRangeId", "feedRange"])
@@ -57,7 +57,7 @@ async def test_query_change_feed_with_different_filter_async(self, change_feed_f
5757
elif change_feed_filter_param == "partitionKeyRangeId":
5858
filter_param = {"partition_key_range_id": "0"}
5959
elif change_feed_filter_param == "feedRange":
60-
feed_ranges = await created_collection.read_feed_ranges()
60+
feed_ranges = list(await created_collection.read_feed_ranges())
6161
assert len(feed_ranges) == 1
6262
filter_param = {"feed_range": feed_ranges[0]}
6363
else:

sdk/evaluation/azure-ai-evaluation/CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@
33
## 1.0.0b5 (Unreleased)
44

55
### Features Added
6+
- Groundedness detection in Non Adversarial Simulator via query/context pairs
7+
```python
8+
import importlib.resources as pkg_resources
9+
package = "azure.ai.evaluation.simulator._data_sources"
10+
resource_name = "grounding.json"
11+
custom_simulator = Simulator(model_config=model_config)
12+
conversation_turns = []
13+
with pkg_resources.path(package, resource_name) as grounding_file:
14+
with open(grounding_file, "r") as file:
15+
data = json.load(file)
16+
for item in data:
17+
conversation_turns.append([item])
18+
outputs = asyncio.run(custom_simulator(
19+
target=callback,
20+
conversation_turns=conversation_turns,
21+
max_conversation_turns=1,
22+
))
23+
```
624
- Adding evaluator for multimodal use cases
725

826
### Breaking Changes

sdk/evaluation/azure-ai-evaluation/MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ include azure/__init__.py
44
include azure/ai/__init__.py
55
include azure/ai/evaluation/py.typed
66
recursive-include azure/ai/evaluation *.prompty
7+
include azure/ai/evaluation/simulator/_data_sources/grounding.json
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ---------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# ---------------------------------------------------------

0 commit comments

Comments
 (0)