module pixeltable.functions.gemini
Pixeltable UDFs that wrap various endpoints from the Google Gemini API. In order to use them, you must firstpip install google-genai and configure your Gemini credentials, as described in
the Working with Gemini tutorial.
Supports two authentication methods:
- Google AI Studio: set
GOOGLE_API_KEYorGEMINI_API_KEY(or putapi_keyin thegeminisection of the Pixeltable config file). - Vertex AI: set
GOOGLE_GENAI_USE_VERTEXAI=trueandGOOGLE_CLOUD_PROJECT(and optionallyGOOGLE_CLOUD_LOCATION), then authenticate via Application Default Credentials (e.g.gcloud auth application-default login).
func invoke_tools()
Signature
tools._invoke().
udf embed_content()
Signatures
pip install google-genai
contents(String): The string, image, audio, video, or document to embed.model(String): The Gemini model to use.config(Json | None, default:Literal(None)): Configuration for embedding generation, corresponding to keyword arguments ofgenai.types.EmbedContentConfig. For details on the parameters, see: https://googleapis.github.io/python-genai/genai.html#genai.types.EmbedContentConfig
pxt.Array[(None,), float32]: The corresponding embedding vector.
text column:
text column:
udf generate_content()
Signature
gemini.rate_limits; use the model id as the key). If no rate
limit is configured, uses a default of 600 RPM.
Requirements:
pip install google-genai
contents(pxt.Json): The input content to generate from. Can be a prompt, or a list containing images and text prompts, as described in: https://ai.google.dev/gemini-api/docs/text-generation and https://ai.google.dev/gemini-api/docs/image-generation for image generation.model(pxt.String): The name of the model to use.config(pxt.Json | None): Configuration for generation, corresponding to keyword arguments ofgenai.types.GenerateContentConfig. For details on the parameters, see: https://googleapis.github.io/python-genai/genai.html#genai.types.GenerateContentConfigtools(pxt.Json[(Json): An optional list of Pixeltable tools to use. It is also possible to specify tools manually via theconfig['tools']parameter, but at most one ofconfig['tools']ortoolsmay be used.
pxt.Json: A dictionary containing the response and other metadata.
gemini-2.5-flash
to an existing Pixeltable column tbl.prompt of the table tbl:
gemini-3.1-flash-image-preview) and extract the PIL image from the response using JSON
subscripting. Image bytes in inline_data.data are decoded into PIL images
automatically. Pass response_modalities=['IMAGE'] so the response contains a
single image part:
udf generate_images()
Signature
gemini-3.1-flash-image-preview), use generate_content
instead. Imagen requires Vertex AI mode; google-genai 2.x no longer reaches it through the Developer API.
Request throttling:
Applies the rate limit set in the config (section imagen.rate_limits; use the model id as the key). If no rate
limit is configured, uses a default of 600 RPM.
Requirements:
pip install google-genai
prompt(pxt.String): A text description of the images to generate.model(pxt.String): The model to use.config(pxt.Json | None): Configuration for generation, corresponding to keyword arguments ofgenai.types.GenerateImagesConfig. For details on the parameters, see: https://googleapis.github.io/python-genai/genai.html#genai.types.GenerateImagesConfig
pxt.Image: The generated image.
imagen-4.0-generate-001
to an existing Pixeltable column tbl.prompt of the table tbl:
udf generate_speech()
Signatures
gemini.rate_limits; use the model id as the key). If no rate
limit is configured, uses a default of 600 RPM.
Requirements:
pip install google-genai
text(String): The text to synthesize into speech.model(String): The model to use (e.g.'gemini-2.5-flash-preview-tts').voice(String): The voice profile to use. Supported voices include'Kore','Puck','Charon','Fenrir','Aoede','Leda','Orus','Zephyr', and others. See the speech generation docs for the full list. Mutually exclusive withvoices.voices(Json): A mapping from speaker alias (as used in the text) to voice name. For example,{'Alice': 'Kore', 'Bob': 'Puck'}. Mutually exclusive withvoice.config(Json | None, default:Literal(None)): Additional configuration, corresponding to keyword arguments ofgenai.types.GenerateContentConfig. Keys such asresponse_modalitiesandspeech_configare set automatically and should not be included.
pxt.Audio: An audio file (WAV, 24 kHz mono 16-bit) containing the synthesized speech.
udf generate_video()
Signature
prompt or images
must be provided. Images guide the generated video according to the prompt.
Requirements:
pip install 'google-genai>=2.22'
prompt(pxt.String | None): A text description of the video to generate.images(pxt.Json[(Image): Optional reference images to send with the prompt. Elements must not be NULL.model(Any): The model to use, such as'gemini-omni-1.1-flash'.config(Any): Fields of the Interactions API videoresponse_format. For example,{'aspect_ratio': '9:16', 'resolution': '1080p'}.typeis set to'video'automatically.deliverydefaults to'uri';'inline'returns base64 data instead. Both are saved as a local video.
pxt.Video: The generated video.
udf transcribe()
Signature
gemini.rate_limits; use the model id as the key). If no rate
limit is configured, uses a default of 600 RPM.
Requirements:
pip install google-genai
audio(pxt.Audio): The audio file to transcribe.model(pxt.String): The model to use (e.g.'gemini-2.5-flash').prompt(pxt.String): The instruction prompt sent alongside the audio. For example,'Generate a transcript of the speech.'or'Summarize the audio content.'.config(pxt.Json | None): Additional configuration, corresponding to keyword arguments ofgenai.types.GenerateContentConfig.
pxt.String: The transcribed text.