-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rag): Support rag retriever evaluation (#1291)
- Loading branch information
Showing
34 changed files
with
1,452 additions
and
67 deletions.
There are no files selected for viewing
This file contains 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
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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
Empty file.
This file contains 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,118 @@ | ||
from typing import AsyncIterator | ||
|
||
import pytest | ||
|
||
from dbgpt.core.awel import ( | ||
DAG, | ||
InputSource, | ||
MapOperator, | ||
StreamifyAbsOperator, | ||
TransformStreamAbsOperator, | ||
) | ||
from dbgpt.core.awel.trigger.iterator_trigger import IteratorTrigger | ||
|
||
|
||
class NumberProducerOperator(StreamifyAbsOperator[int, int]): | ||
"""Create a stream of numbers from 0 to `n-1`""" | ||
|
||
async def streamify(self, n: int) -> AsyncIterator[int]: | ||
for i in range(n): | ||
yield i | ||
|
||
|
||
class MyStreamingOperator(TransformStreamAbsOperator[int, int]): | ||
async def transform_stream(self, data: AsyncIterator[int]) -> AsyncIterator[int]: | ||
async for i in data: | ||
yield i * i | ||
|
||
|
||
async def _check_stream_results(stream_results, expected_len): | ||
assert len(stream_results) == expected_len | ||
for _, result in stream_results: | ||
i = 0 | ||
async for num in result: | ||
assert num == i * i | ||
i += 1 | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_single_data(): | ||
with DAG("test_single_data"): | ||
trigger_task = IteratorTrigger(data=2) | ||
task = MapOperator(lambda x: x * x) | ||
trigger_task >> task | ||
results = await trigger_task.trigger() | ||
assert len(results) == 1 | ||
assert results[0][1] == 4 | ||
|
||
with DAG("test_single_data_stream"): | ||
trigger_task = IteratorTrigger(data=2, streaming_call=True) | ||
number_task = NumberProducerOperator() | ||
task = MyStreamingOperator() | ||
trigger_task >> number_task >> task | ||
stream_results = await trigger_task.trigger() | ||
await _check_stream_results(stream_results, 1) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_list_data(): | ||
with DAG("test_list_data"): | ||
trigger_task = IteratorTrigger(data=[0, 1, 2, 3]) | ||
task = MapOperator(lambda x: x * x) | ||
trigger_task >> task | ||
results = await trigger_task.trigger() | ||
assert len(results) == 4 | ||
assert results == [(0, 0), (1, 1), (2, 4), (3, 9)] | ||
|
||
with DAG("test_list_data_stream"): | ||
trigger_task = IteratorTrigger(data=[0, 1, 2, 3], streaming_call=True) | ||
number_task = NumberProducerOperator() | ||
task = MyStreamingOperator() | ||
trigger_task >> number_task >> task | ||
stream_results = await trigger_task.trigger() | ||
await _check_stream_results(stream_results, 4) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_async_iterator_data(): | ||
async def async_iter(): | ||
for i in range(4): | ||
yield i | ||
|
||
with DAG("test_async_iterator_data"): | ||
trigger_task = IteratorTrigger(data=async_iter()) | ||
task = MapOperator(lambda x: x * x) | ||
trigger_task >> task | ||
results = await trigger_task.trigger() | ||
assert len(results) == 4 | ||
assert results == [(0, 0), (1, 1), (2, 4), (3, 9)] | ||
|
||
with DAG("test_async_iterator_data_stream"): | ||
trigger_task = IteratorTrigger(data=async_iter(), streaming_call=True) | ||
number_task = NumberProducerOperator() | ||
task = MyStreamingOperator() | ||
trigger_task >> number_task >> task | ||
stream_results = await trigger_task.trigger() | ||
await _check_stream_results(stream_results, 4) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_input_source_data(): | ||
with DAG("test_input_source_data"): | ||
trigger_task = IteratorTrigger(data=InputSource.from_iterable([0, 1, 2, 3])) | ||
task = MapOperator(lambda x: x * x) | ||
trigger_task >> task | ||
results = await trigger_task.trigger() | ||
assert len(results) == 4 | ||
assert results == [(0, 0), (1, 1), (2, 4), (3, 9)] | ||
|
||
with DAG("test_input_source_data_stream"): | ||
trigger_task = IteratorTrigger( | ||
data=InputSource.from_iterable([0, 1, 2, 3]), | ||
streaming_call=True, | ||
) | ||
number_task = NumberProducerOperator() | ||
task = MyStreamingOperator() | ||
trigger_task >> number_task >> task | ||
stream_results = await trigger_task.trigger() | ||
await _check_stream_results(stream_results, 4) |
This file contains 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 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
Oops, something went wrong.