litellm icon indicating copy to clipboard operation
litellm copied to clipboard

Update ollama.py for image handling

Open rick-github opened this issue 10 months ago • 3 comments

ollama wants plain base64 jpeg/png images, and some clients send dataURI and/or webp. Remove prefixes and convert all non-jpeg/png images to jpeg.

Fixes https://github.com/BerriAI/litellm/issues/1427, https://github.com/BerriAI/litellm/issues/2661

rick-github avatar Apr 07 '24 11:04 rick-github

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 28, 2024 3:00pm

vercel[bot] avatar Apr 07 '24 11:04 vercel[bot]

Hi Jakob,

base64 encoded data shouldn't contain commas, it's restricted to the character set [A-Za-z0-9/+=]: https://en.wikipedia.org/wiki/Base64

On Thu, 11 Apr 2024 at 05:10, Jakob @.***> wrote:

I think this implementation is flawed since you're doing image.split(",") for the comma you're expecting at the beginning, but the base64 encoded data itself can also contain commas.

— Reply to this email directly, view it on GitHub https://github.com/BerriAI/litellm/pull/2888#issuecomment-2048855410, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSBEJVKJCF77L263ZUULTTY4X5LTAVCNFSM6AAAAABF3HOAX6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBYHA2TKNBRGA . You are receiving this because you authored the thread.Message ID: @.***>

rick-github avatar Apr 11 '24 07:04 rick-github

Yeah realized that afterwards and deleted my comment :) sorry about that. I was confusing "," with "/"

jakobdylanc avatar Apr 11 '24 08:04 jakobdylanc

@rick-github thanks for this - can you add a test with a mock call for this to test_completions.py we've had a couple regressions with merged ollama pr's recently.

place to add test - https://github.com/BerriAI/litellm/blob/b29994a0ae0fc496f182167a8c8d4a1b689712fd/litellm/tests/test_completion.py#L4

Example of a mock call - https://github.com/BerriAI/litellm/blob/b29994a0ae0fc496f182167a8c8d4a1b689712fd/litellm/tests/test_completion.py#L1314

krrishdholakia avatar May 27 '24 16:05 krrishdholakia

Done.

rick-github avatar May 28 '24 14:05 rick-github

Thanks @rick-github just share a screenshot of it passing testing for your test + tests in test_ollama.py and we should be good to merge!

Thank you again for your awesome work here

krrishdholakia avatar May 28 '24 15:05 krrishdholakia

Screenshot from 2024-05-28 18-01-24

rick-github avatar May 28 '24 16:05 rick-github

Screenshot from 2024-05-28 18-06-23

rick-github avatar May 28 '24 16:05 rick-github

LGTM!

krrishdholakia avatar May 28 '24 17:05 krrishdholakia