Skip to content

Commit 1d61b25

Browse files
yifengloulangfun authors
authored andcommitted
Support Youtube URL input for Gemini API.
https://ai.google.dev/gemini-api/docs/vision?lang=python#youtube PiperOrigin-RevId: 736936780
1 parent b682999 commit 1d61b25

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

langfun/core/llms/gemini.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,16 @@ def _content_from_message(self, prompt: lf.Message) -> dict[str, Any]:
608608
modalities = [modalities]
609609
for modality in modalities:
610610
if modality.is_text:
611-
parts.append({'text': modality.to_text()})
611+
# Add YouTube video into the context window.
612+
# https://ai.google.dev/gemini-api/docs/vision?lang=python#youtube
613+
if modality.mime_type == 'text/html' and modality.uri.startswith(
614+
'https://www.youtube.com/watch?v='
615+
):
616+
parts.append({
617+
'fileData': {'mimeType': 'video/*', 'fileUri': modality.uri}
618+
})
619+
else:
620+
parts.append({'text': modality.to_text()})
612621
else:
613622
parts.append({
614623
'inlineData': {

0 commit comments

Comments
 (0)