mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-09 19:06:51 +08:00
feat: support pinning, including, and excluding for model providers and tools (#7419)
Co-authored-by: GareArc <chen4851@purude.edu>
This commit is contained in:
@@ -2,7 +2,7 @@ from textwrap import dedent
|
||||
|
||||
import pytest
|
||||
|
||||
from core.helper.position_helper import get_position_map
|
||||
from core.helper.position_helper import get_position_map, is_filtered, pin_position_map, sort_by_position_map
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -14,7 +14,7 @@ def prepare_example_positions_yaml(tmp_path, monkeypatch) -> str:
|
||||
- second
|
||||
# - commented
|
||||
- third
|
||||
|
||||
|
||||
- 9999999999999
|
||||
- forth
|
||||
"""))
|
||||
@@ -28,9 +28,9 @@ def prepare_empty_commented_positions_yaml(tmp_path, monkeypatch) -> str:
|
||||
"""\
|
||||
# - commented1
|
||||
# - commented2
|
||||
-
|
||||
-
|
||||
|
||||
-
|
||||
-
|
||||
|
||||
"""))
|
||||
return str(tmp_path)
|
||||
|
||||
@@ -53,3 +53,79 @@ def test_position_helper_with_all_commented(prepare_empty_commented_positions_ya
|
||||
folder_path=prepare_empty_commented_positions_yaml,
|
||||
file_name='example_positions_all_commented.yaml')
|
||||
assert position_map == {}
|
||||
|
||||
|
||||
def test_excluded_position_data(prepare_example_positions_yaml):
|
||||
position_map = get_position_map(
|
||||
folder_path=prepare_example_positions_yaml,
|
||||
file_name='example_positions.yaml'
|
||||
)
|
||||
pin_list = ['forth', 'first']
|
||||
include_set = set()
|
||||
exclude_set = {'9999999999999'}
|
||||
|
||||
position_map = pin_position_map(
|
||||
original_position_map=position_map,
|
||||
pin_list=pin_list
|
||||
)
|
||||
|
||||
data = [
|
||||
"forth",
|
||||
"first",
|
||||
"second",
|
||||
"third",
|
||||
"9999999999999",
|
||||
"extra1",
|
||||
"extra2",
|
||||
]
|
||||
|
||||
# filter out the data
|
||||
data = [item for item in data if not is_filtered(include_set, exclude_set, item, lambda x: x)]
|
||||
|
||||
# sort data by position map
|
||||
sorted_data = sort_by_position_map(
|
||||
position_map=position_map,
|
||||
data=data,
|
||||
name_func=lambda x: x,
|
||||
)
|
||||
|
||||
# assert the result in the correct order
|
||||
assert sorted_data == ['forth', 'first', 'second', 'third', 'extra1', 'extra2']
|
||||
|
||||
|
||||
def test_included_position_data(prepare_example_positions_yaml):
|
||||
position_map = get_position_map(
|
||||
folder_path=prepare_example_positions_yaml,
|
||||
file_name='example_positions.yaml'
|
||||
)
|
||||
pin_list = ['forth', 'first']
|
||||
include_set = {'forth', 'first'}
|
||||
exclude_set = {}
|
||||
|
||||
position_map = pin_position_map(
|
||||
original_position_map=position_map,
|
||||
pin_list=pin_list
|
||||
)
|
||||
|
||||
data = [
|
||||
"forth",
|
||||
"first",
|
||||
"second",
|
||||
"third",
|
||||
"9999999999999",
|
||||
"extra1",
|
||||
"extra2",
|
||||
]
|
||||
|
||||
# filter out the data
|
||||
data = [item for item in data if not is_filtered(include_set, exclude_set, item, lambda x: x)]
|
||||
|
||||
# sort data by position map
|
||||
sorted_data = sort_by_position_map(
|
||||
position_map=position_map,
|
||||
data=data,
|
||||
name_func=lambda x: x,
|
||||
)
|
||||
|
||||
# assert the result in the correct order
|
||||
assert sorted_data == ['forth', 'first']
|
||||
|
||||
Reference in New Issue
Block a user