-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
previous_index
field (#668)
#656 We might want to validate this by checking that the field mentioned in `previous_index` is also defined in the `consumes` section.
- Loading branch information
1 parent
1c6cb6d
commit be8c67b
Showing
23 changed files
with
224 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ produces: | |
type: int32 | ||
images_height: | ||
type: int32 | ||
# additionalFields: false | ||
|
||
args: | ||
timeout: | ||
|
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
1 change: 1 addition & 0 deletions
1
components/embedding_based_laion_retrieval/test_requirements.txt
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 @@ | ||
pytest==7.4.2 |
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,2 @@ | ||
[pytest] | ||
pythonpath = ../src |
66 changes: 66 additions & 0 deletions
66
components/embedding_based_laion_retrieval/tests/test_component.py
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,66 @@ | ||
import typing as t | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
from src.main import LAIONRetrievalComponent | ||
|
||
|
||
def test_component(monkeypatch): | ||
def mocked_client_query(embedding_input: t.List[float]) -> t.List[dict]: | ||
if embedding_input == [1, 2]: | ||
return [ | ||
{ | ||
"id": "a", | ||
"url": "http://a", | ||
}, | ||
{ | ||
"id": "b", | ||
"url": "http://b", | ||
}, | ||
] | ||
if embedding_input == [2, 3]: | ||
return [ | ||
{ | ||
"id": "c", | ||
"url": "http://c", | ||
}, | ||
{ | ||
"id": "d", | ||
"url": "http://d", | ||
}, | ||
] | ||
msg = f"Unexpected value: `embeddings_input` was {embedding_input}" | ||
raise ValueError(msg) | ||
|
||
input_dataframe = pd.DataFrame.from_dict( | ||
{ | ||
"id": ["1", "2"], | ||
"embeddings_data": [np.array([1, 2]), np.array([2, 3])], | ||
}, | ||
) | ||
|
||
expected_output_dataframe = pd.DataFrame.from_dict( | ||
{ | ||
"id": ["a", "b", "c", "d"], | ||
"url": ["http://a", "http://b", "http://c", "http://d"], | ||
"embedding_id": ["1", "1", "2", "2"], | ||
}, | ||
) | ||
expected_output_dataframe = expected_output_dataframe.set_index("id") | ||
|
||
component = LAIONRetrievalComponent( | ||
num_images=2, | ||
aesthetic_score=9, | ||
aesthetic_weight=0.5, | ||
) | ||
|
||
monkeypatch.setattr(component.client, "query", mocked_client_query) | ||
|
||
output_dataframe = component.transform(input_dataframe) | ||
|
||
pd.testing.assert_frame_equal( | ||
left=expected_output_dataframe, | ||
right=output_dataframe, | ||
check_dtype=False, | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pytest==7.4.2 |
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,2 @@ | ||
[pytest] | ||
pythonpath = ../src |
66 changes: 66 additions & 0 deletions
66
components/prompt_based_laion_retrieval/tests/test_component.py
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,66 @@ | ||
import typing as t | ||
|
||
import pandas as pd | ||
|
||
from src.main import LAIONRetrievalComponent | ||
|
||
|
||
def test_component(monkeypatch): | ||
def mocked_client_query(text: str) -> t.List[dict]: | ||
if text == "first prompt": | ||
return [ | ||
{ | ||
"id": "a", | ||
"url": "http://a", | ||
}, | ||
{ | ||
"id": "b", | ||
"url": "http://b", | ||
}, | ||
] | ||
if text == "second prompt": | ||
return [ | ||
{ | ||
"id": "c", | ||
"url": "http://c", | ||
}, | ||
{ | ||
"id": "d", | ||
"url": "http://d", | ||
}, | ||
] | ||
msg = f"Unexpected value: `text` was {text}" | ||
raise ValueError(msg) | ||
|
||
input_dataframe = pd.DataFrame.from_dict( | ||
{ | ||
"id": ["1", "2"], | ||
"prompts_text": ["first prompt", "second prompt"], | ||
}, | ||
) | ||
|
||
expected_output_dataframe = pd.DataFrame.from_dict( | ||
{ | ||
"id": ["a", "b", "c", "d"], | ||
"url": ["http://a", "http://b", "http://c", "http://d"], | ||
"prompt_id": ["1", "1", "2", "2"], | ||
}, | ||
) | ||
expected_output_dataframe = expected_output_dataframe.set_index("id") | ||
|
||
component = LAIONRetrievalComponent( | ||
num_images=2, | ||
aesthetic_score=9, | ||
aesthetic_weight=0.5, | ||
url="", | ||
) | ||
|
||
monkeypatch.setattr(component.client, "query", mocked_client_query) | ||
|
||
output_dataframe = component.transform(input_dataframe) | ||
|
||
pd.testing.assert_frame_equal( | ||
left=expected_output_dataframe, | ||
right=output_dataframe, | ||
check_dtype=False, | ||
) |
Oops, something went wrong.