Skip to content

Commit

Permalink
Resolve pytest error, simplify image retrieval converter
Browse files Browse the repository at this point in the history
  • Loading branch information
djwhatle committed Nov 14, 2024
1 parent 6ad7578 commit d769886
Showing 1 changed file with 9 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,21 @@ def check_config(self, config: InputsConfig) -> None:
raise GenAIPerfException(
f"The --streaming option is not supported for {config.output_format.to_lowercase()}."
)
else:
raise GenAIPerfException(
f"Output format {config.output_format} is not supported"
)

def convert(
self, generic_dataset: GenericDataset, config: InputsConfig
) -> Dict[Any, Any]:
request_body: Dict[str, Any] = {"data": []}

for file_data in generic_dataset.files_data.values():
for index, row in enumerate(file_data.rows):
payload = {
"input": [
{"type": "image_url", "url": img} for img in row.images
]
}
for _, row in enumerate(file_data.rows):
payload = {
"input": [{"type": "image_url", "url": img} for img in row.images]
}
request_body["data"].append({"payload": [payload]})

return request_body

def _create_payload(self, row: DataRow, config: InputsConfig) -> Dict[Any, Any]:
content = self._retrieve_content(row, config)

payload = {"input": content}
return payload

def _retrieve_content(
self, row: DataRow, config: InputsConfig
) -> Union[str, List[Dict[Any, Any]]]:
content: Union[str, List[Dict[Any, Any]]] = ""
if config.output_format == OutputFormat.IMAGE_RETRIEVAL:
content = self._add_multi_modal_content(row)
else:
raise GenAIPerfException(
f"Output format {config.output_format} is not supported"
)
return content

def _add_multi_modal_content(self, entry: DataRow) -> List[Dict[Any, Any]]:
content: List[Dict[Any, Any]] = []
for image in entry.images:
content.append({"type": "image_url", "url": image})
return content

0 comments on commit d769886

Please sign in to comment.