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

Add media support to vertex chat_models #227

Merged
merged 1 commit into from
May 21, 2024

Conversation

wafle
Copy link
Contributor

@wafle wafle commented May 16, 2024

# Handle media type like LangChain.js
# https://github.com/langchain-ai/langchainjs/blob/e536593e2585f1dd7b0afc187de4d07cb40689ba/libs/langchain-google-common/src/utils/gemini.ts#L93-L106
if part["type"] == "media":
if "mime_type" not in part:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with snake_case for mime_type and file_uri contrary to what's happening in langchain.js as it seemed more pythonic. Do you think that's the right call?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we construct the proto Part directly? why do we need a VertexPart?
and it's probably a good idea to allow to pass gcs_uri as file_data and video_metadata too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we construct the proto Part directly?

Done.

video_metadata

Done.

pass gcs_uri

file_uri expects a GCS uri, e.g. "gs://bucket/some_video.mp4". Do you mean we should also support http uri-s here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so there's no way to send the video into a base64 uri?, instead of an GCS uri?

llm = ChatVertexAI(model_name="gemini-1.5-pro-preview-0514")
storage_client = storage.Client()
blob = storage.Blob.from_string(file_uri, client=storage_client)
media_base64 = base64.b64encode(blob.download_as_bytes()).decode()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you include a test that passes a gcs_uri, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See test_multimodal_media_file_uri.

@lkuligin lkuligin merged commit a4e9483 into langchain-ai:main May 21, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vertex AI Gemini video support
3 participants