forked from phoenix-oss/llama-stack-mirror
fix ImageContentItem to take base64 string as image.data (#909)
# What does this PR do? - Discussion in https://github.com/meta-llama/llama-stack/pull/906#discussion_r1936260819 - image.data should accept base64 string as input instead of binary bytes, change prompt_adapter to account for that. ## Test Plan ``` pytest -v tests/client-sdk/inference/test_inference.py ``` with test in https://github.com/meta-llama/llama-stack/pull/906 ## Sources Please link relevant resources if necessary. ## Before submitting - [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case). - [ ] Ran pre-commit to handle lint / formatting issues. - [ ] Read the [contributor guideline](https://github.com/meta-llama/llama-stack/blob/main/CONTRIBUTING.md), Pull Request section? - [ ] Updated relevant documentation. - [ ] Wrote necessary unit or integration tests.
This commit is contained in:
parent
7fe2592795
commit
94051cfe9e
5 changed files with 85 additions and 31 deletions
|
@ -135,7 +135,8 @@ async def interleaved_content_convert_to_raw(
|
|||
else:
|
||||
raise ValueError("Unsupported URL type")
|
||||
elif image.data:
|
||||
data = image.data
|
||||
# data is a base64 encoded string, decode it to bytes for RawMediaItem
|
||||
data = base64.b64decode(image.data)
|
||||
else:
|
||||
raise ValueError("No data or URL provided")
|
||||
|
||||
|
@ -184,8 +185,10 @@ async def localize_image_content(media: ImageContentItem) -> Tuple[bytes, str]:
|
|||
|
||||
return content, format
|
||||
else:
|
||||
pil_image = PIL_Image.open(io.BytesIO(image.data))
|
||||
return image.data, pil_image.format
|
||||
# data is a base64 encoded string, decode it to bytes first
|
||||
data_bytes = base64.b64decode(image.data)
|
||||
pil_image = PIL_Image.open(io.BytesIO(data_bytes))
|
||||
return data_bytes, pil_image.format
|
||||
|
||||
|
||||
async def convert_image_content_to_url(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue