Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: claude 3.5 vision not work #6396

Open
faye1225 opened this issue Oct 23, 2024 · 0 comments
Open

[Bug]: claude 3.5 vision not work #6396

faye1225 opened this issue Oct 23, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@faye1225
Copy link

What happened?

I followed the documentation to deploy litellm locally and imported Claude 3.5. Ordinary conversations are running smoothly, but the vision feature is not working.
image

chat:

client = anthropic.Anthropic(api_key='sk-xxxx',base_url='http://127.0.0.1:4000')

message = client.messages.create(
    model="claude-3-5-sonnet-20240620",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Whats in this image?"},
            ],
        }
    ],
)

'''
output: 
# Message(id='chatcmpl-eb17fb44-99cc-450c-9c5b-ea13dda4e9bf', content=[TextBlock(text="I apologize, but I don't see #  any image attached to this conversation. Could you please upload an image or provide a link to the image you'd like me to analyze? Once you do that, I'll be happy to describe what I see in the image for you.", type='text')], model='claude-3-5-sonnet-20240620', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=Usage(input_tokens=14, output_tokens=59))
'''

vision 1:

def encode_image(image_path):
    with open(image_path, "rb") as image_file:
        return base64.b64encode(image_file.read()).decode("utf-8")

base64_image = encode_image("./logo.jpg")

client = anthropic.Anthropic(api_key='sk-xxx',base_url='http://127.0.0.1:4000')

message = client.messages.create(
    model="claude-3-5-sonnet-20240620",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Whats in this image?"},
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "data:image/jpeg;base64," + base64_image
                    },
                },
            ],
        }
    ],
)

'''
output: 
Message(id='chatcmpl-e5e015d6-cd62-45a7-9982-3dcb7c996bf3', content=[TextBlock(text="I apologize, but I don't see any image attached to your message. Could you please upload an image and then ask me about it? Once an image is provided, I'll be happy to describe what I see in it.", type='text')], model='claude-3-5-sonnet-20240620', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=Usage(input_tokens=14, output_tokens=50))
'''

vision 2:

# https://docs.anthropic.com/en/docs/build-with-claude/vision#how-to-use-vision

client = anthropic.Anthropic(api_key='sk-xxx',base_url='http://127.0.0.1:4000')

message = client.messages.create(
    model="claude-3-5-sonnet-20240620",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": [
                  {
                    "type": "image",
                    "source": {
                        "type": "base64",
                        "media_type": image1_media_type,
                        "data": image1_data,
                    },
                },
                {
                    "type": "text",
                    "text": "Describe this image."
                }
            ],
        }
    ],
)
'''
output: 
BadRequestError
Error code: 400 - {'error': {'message': "litellm.BadRequestError: AnthropicError - Client error '400 Bad Request' for url 'https://api.anthropic.com/v1/messages'\nFor more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400\nReceived Model Group=claude-3-5-sonnet-20240620\nAvailable Model Group Fallbacks=None", 'type': None, 'param': None, 'code': '400'}
'''

Relevant log output

No response

Twitter / LinkedIn details

No response

@faye1225 faye1225 added the bug Something isn't working label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant