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

refactor(chat-models)!: Make MIME Type mandatory for base64 images in prompt #269

Merged
merged 1 commit into from
Dec 15, 2023

Conversation

davidmigloz
Copy link
Owner

@davidmigloz davidmigloz commented Dec 15, 2023

To be compatible with other multimodal LLMs, the ChatMessageContentImage class now requires:

  • data: Either a base64 encoded image data or a URL (for models that support it)
  • mimeType: The IANA standard MIME type of the source data (e.g. image/png)

This is a breaking change if you were using GPT-4V.

Migration

With Base64 image

Rename url to data and specify mimeType.

Before:

final prompt = PromptValue.chat([
  ChatMessage.system(
    'You are a helpful assistant.',
  ),
  ChatMessage.human(
    ChatMessageContent.multiModal([
      ChatMessageContent.text('What fruit is this?'),
      ChatMessageContent.image(
        url: 'data:image/jpeg;base64,/9j/4AAQS...nSbsr69/Rdu1j//2Q==',
      ),
    ]),
  ),
]);

Now:

final prompt = PromptValue.chat([
  ChatMessage.system(
    'You are a helpful assistant.',
  ),
  ChatMessage.human(
    ChatMessageContent.multiModal([
      ChatMessageContent.text('What fruit is this?'),
      ChatMessageContent.image(
        mimeType: 'image/jpeg',
        data: '/9j/4AAQS...nSbsr69/Rdu1j//2Q==',
      ),
    ]),
  ),
]);

With URL

Just rename url to data.

Before:

ChatMessageContent.image(
  url: 'https://upload.wikimedia.org/wikipedia/commons/9/92/95apple.jpeg',
), 

Now:

ChatMessageContent.image(
  data: 'https://upload.wikimedia.org/wikipedia/commons/9/92/95apple.jpeg',
), 

@davidmigloz davidmigloz self-assigned this Dec 15, 2023
@davidmigloz davidmigloz added c:chat-models Chat models. p:langchain_openai langchain_openai package. labels Dec 15, 2023
@davidmigloz davidmigloz added this to the v0.3.0 milestone Dec 15, 2023
@davidmigloz davidmigloz merged commit 2fe076b into main Dec 15, 2023
1 check failed
@davidmigloz davidmigloz deleted the mime branch December 15, 2023 17:29
KennethKnudsen97 pushed a commit to KennethKnudsen97/langchain_dart that referenced this pull request Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c:chat-models Chat models. p:langchain_openai langchain_openai package.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

1 participant