Logo Google Genai Media

Google Genai Media

Cộng đồng
mainza-ai
google-genai-media

Hướng dẫn tích hợp đầy đủ các dịch vụ tạo nội dung AI đa phương tiện mới nhất của Google: Imagen 4 (tạo, chỉnh sửa và phóng to ảnh), Veo 3/3.1 (tạo video, chuyển ảnh thành video, kéo dài video), Lyria 2 (tạo nhạc) và khả năng tạo ảnh đa phương thức của Gemini — tất cả thông qua Google Gen AI SDK thống nhất (google-genai). Dùng kỹ năng này bất cứ khi nào người dùng muốn tạo, chỉnh sửa hoặc biến đổi hình ảnh hay video bằng Google AI, làm việc với API đa phương tiện của Vertex AI, xây dựng quy trình tạo nội dung, tích hợp Imagen hoặc Veo vào ứng dụng, hoặc hỏi về khả năng tạo ảnh/video của Gemini. Luôn dùng cho các tác vụ gồm: chuyển văn bản thành ảnh, chuyển văn bản thành video, chuyển ảnh thành video, kéo dài video, inpainting, outpainting, chỉnh sửa nền, chuyển đổi phong cách, phóng to ảnh, tạo nhạc bằng AI hoặc tạo watermark SynthID qua dịch vụ của Google.

Tổng quan

Nhà phát hànhmainza-ai
Kho mãmilimovideo
Tên kỹ nănggoogle-genai-media
Sao
87
Bản fork
19
Tệp đi kèm
Chỉ có hướng dẫn
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Hướng dẫn có đủ mọi thứ cần thiết

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được mainza-ai công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Google Genai Media trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/mainza-ai/milimovideo/tree/main/skills/skills/google-ai
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/mainza-ai/milimovideo.git /tmp/milimovideo
mkdir -p .claude/skills
cp -r /tmp/milimovideo/skills/skills/google-ai .claude/skills/google-genai-media
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Google Genai Media trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Google Genai Media ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Google Genai Media với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Google GenAI Media Services — Full Integration Guide

Last verified: February 2026
SDK: google-genai (unified, replaces legacy google-generativeai which EOL'd Nov 2025)
Docs: https://googleapis.github.io/python-genai/ | https://docs.cloud.google.com/vertex-ai/generative-ai/docs/models


1. SDK Setup (Always Start Here)

Installation

bash
pip install google-genai            # Core SDK
pip install google-genai[aiohttp]   # For async support
pip install pillow                  # For image display/saving

⚠️ Never use google-generativeai (legacy, EOL November 30, 2025). Always use google-genai.

Client Initialization

Gemini Developer API (AI Studio — easiest for prototyping):

python
from google import genai

# Option A: pass key directly
client = genai.Client(api_key="GEMINI_API_KEY")

# Option B: use env var (recommended)
# export GEMINI_API_KEY=your_key
client = genai.Client()

Vertex AI (enterprise, required for image editing & upscaling):

python
from google import genai
from google.genai.types import HttpOptions

# Option A: code-level
client = genai.Client(
    vertexai=True,
    project="your-gcp-project-id",
    location="us-central1"
)

# Option B: env vars (recommended for CI/CD)
# export GOOGLE_GENAI_USE_VERTEXAI=true
# export GOOGLE_CLOUD_PROJECT=your-project-id
# export GOOGLE_CLOUD_LOCATION=us-central1
client = genai.Client(http_options=HttpOptions(api_version="v1"))

Authentication for Vertex AI:

bash
gcloud auth application-default login
# OR for service accounts:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json

2. Recommended Models (as of Feb 2026)

Image Generation

Model IDUse Case
imagen-4.0-generate-001✅ GA — best quality text-to-image
imagen-4.0-ultra-generate-001✅ GA — highest fidelity, slower
imagen-4.0-fast-generate-001✅ GA — fast generation, simpler prompts
imagen-3.0-generate-002Stable fallback if Imagen 4 unavailable

Image Editing (Vertex AI only)

Model IDUse Case
imagen-3.0-capability-001Inpainting, outpainting, background edit
imagen-product-recontext-preview-06-30Product image background replacement

Video Generation

Model IDUse Case
veo-3.1-generate-preview✅ Best quality, advanced controls
veo-3.1-fast-generate-previewFast generation, lower latency
veo-3.0-generate-001GA stable high-fidelity
veo-3.0-fast-generate-001GA fast video
veo-2.0-generate-001Stable fallback; also supports style images

Gemini Multimodal Image Generation

Model IDUse Case
gemini-2.5-flash-imageFast image gen+edit via chat
gemini-3-pro-image-previewHighest quality via chat

Music Generation (Vertex AI)

Model IDUse Case
lyria-002GA — text-to-music, studio-grade

3. Image Generation with Imagen 4

Text-to-Image (Basic)

python
from google import genai
from google.genai import types

client = genai.Client()  # or Vertex AI client

response = client.models.generate_images(
    model="imagen-4.0-generate-001",
    prompt="A golden retriever puppy playing in autumn leaves, soft morning light",
    config=types.GenerateImagesConfig(
        number_of_images=4,           # 1–4
        aspect_ratio="16:9",          # "1:1", "9:16", "4:3", "3:4", "16:9"
        output_mime_type="image/jpeg",
        include_rai_reason=True,      # include safety filter reason if blocked
        person_generation="allow_adult",  # "allow_all", "allow_adult", "dont_allow"
        safety_filter_level="block_medium_and_above",
        enhance_prompt=True,          # auto-enhance prompt quality
    ),
)

for i, img in enumerate(response.generated_images):
    img.image.save(f"output_{i}.jpg")
    # or img.image.show() to display inline

Save Image to File (PIL)

python
from PIL import Image
from io import BytesIO
import base64

# If response returns bytes:
pil_image = Image.open(BytesIO(response.generated_images[0].image._image_bytes))
pil_image.save("output.png")

Image Upscaling (Vertex AI only)

python
# Must use Vertex AI client
response_upscaled = client.models.upscale_image(
    model="imagen-4.0-upscale-preview",
    image=response.generated_images[0].image,
    upscale_factor="x2",   # "x2" or "x4"
    config=types.UpscaleImageConfig(
        include_rai_reason=True,
        output_mime_type="image/jpeg",
    ),
)
response_upscaled.generated_images[0].image.save("upscaled.jpg")

4. Image Editing with Imagen (Vertex AI Only)

All editing operations require a Vertex AI client and imagen-3.0-capability-001.

Inpainting — Insert into Masked Region

python
from google.genai.types import RawReferenceImage, MaskReferenceImage

# Load source image
with open("source.jpg", "rb") as f:
    image_bytes = f.read()

raw_ref = RawReferenceImage(
    reference_id=1,
    reference_image=types.Image(image_bytes=image_bytes, mime_type="image/jpeg"),
)

mask_ref = MaskReferenceImage(
    reference_id=2,
    config=types.MaskReferenceConfig(
        mask_mode="MASK_MODE_BACKGROUND",   # auto-mask background
        mask_dilation=0,
    ),
)

response = client.models.edit_image(
    model="imagen-3.0-capability-001",
    prompt="Replace background with a tropical beach at sunset",
    reference_images=[raw_ref, mask_ref],
    config=types.EditImageConfig(
        edit_mode="EDIT_MODE_INPAINT_INSERTION",
        number_of_images=2,
        include_rai_reason=True,
        output_mime_type="image/jpeg",
    ),
)
response.generated_images[0].image.save("edited.jpg")

Mask Modes

mask_modeBehavior
MASK_MODE_BACKGROUNDAuto-mask the background
MASK_MODE_FOREGROUNDAuto-mask the foreground subject
MASK_MODE_SEMANTICMask by semantic segment (e.g., "sky")
MASK_MODE_USER_PROVIDEDUse your own binary mask image

Edit Modes

edit_modeBehavior
EDIT_MODE_INPAINT_INSERTIONGenerate content inside the mask
EDIT_MODE_INPAINT_REMOVALRemove masked content, fill naturally
EDIT_MODE_OUTPAINTExtend image beyond borders
EDIT_MODE_BGSWAPFull background replacement
EDIT_MODE_PRODUCT_IMAGEProduct recontext (background scenes)

5. Video Generation with Veo

⚠️ Cost warning: Veo is significantly more expensive than image generation. Always check current pricing at https://cloud.google.com/vertex-ai/generative-ai/pricing before running in production.

Video generation is asynchronous — submit a job, then poll until complete.

Text-to-Video (Basic)

python
import time
from google import genai
from google.genai import types

client = genai.Client(vertexai=True, project="your-project", location="us-central1")

# Submit generation job
operation = client.models.generate_videos(
    model="veo-3.0-generate-001",
    prompt="A time-lapse of a city skyline from dawn to dusk, cinematic 4K quality",
    config=types.GenerateVideosConfig(
        number_of_videos=1,
        duration_seconds=8,        # 5–8 seconds typically
        aspect_ratio="16:9",       # "16:9" or "9:16"
        resolution="1080p",        # "720p" or "1080p" (Veo 3 preview)
        enhance_prompt=True,
        output_gcs_uri="gs://your-bucket/video-outputs/",  # optional GCS output
    ),
)

# Poll until done
while not operation.done:
    time.sleep(20)
    operation = client.operations.get(operation)

# Access result
video = operation.response.generated_videos[0].video
video.save("output.mp4")

Image-to-Video

python
import base64

with open("start_frame.jpg", "rb") as f:
    image_b64 = base64.b64encode(f.read()).decode()

operation = client.models.generate_videos(
    model="veo-3.1-generate-preview",
    prompt="The cat slowly turns its head and yawns",
    image=types.Image(
        image_bytes=base64.b64decode(image_b64),
        mime_type="image/jpeg",
    ),
    config=types.GenerateVideosConfig(
        number_of_videos=1,
        duration_seconds=6,
        aspect_ratio="16:9",
    ),
)

while not operation.done:
    time.sleep(20)
    operation = client.operations.get(operation)

operation.response.generated_videos[0].video.save("animated.mp4")

Video Extension (Veo 2 — Vertex AI)

python
# Extend an existing video by providing it as input
video_input = types.Video(uri="gs://your-bucket/existing-video.mp4")

operation = client.models.generate_videos(
    model="veo-2.0-generate-001",
    prompt="Continue the scene as the character walks into the building",
    video=video_input,
    config=types.GenerateVideosConfig(
        number_of_videos=1,
        duration_seconds=5,
    ),
)

Advanced Video Controls (Veo 3.1)

python
# First frame + last frame control
operation = client.models.generate_videos(
    model="veo-3.1-generate-preview",
    prompt="Camera pushes through the forest canopy",
    config=types.GenerateVideosConfig(
        number_of_videos=1,
        duration_seconds=8,
        # Reference images for first/last frame control
        reference_images=[
            types.ReferenceImage(
                reference_id=1,
                reference_image=first_frame_image,
                config=types.ReferenceImageConfig(
                    reference_type="REFERENCE_TYPE_FIRST_FRAME"
                ),
            ),
            types.ReferenceImage(
                reference_id=2,
                reference_image=last_frame_image,
                config=types.ReferenceImageConfig(
                    reference_type="REFERENCE_TYPE_LAST_FRAME"
                ),
            ),
        ],
    ),
)

Note: Style images with referenceImages.style require veo-2.0-generate-exp — Veo 3.1 does NOT support style reference images.


6. Gemini Multimodal Image Generation (Chat-based)

Gemini image models allow iterative edit-in-conversation workflows.

python
from google import genai
from PIL import Image
from io import BytesIO

client = genai.Client()

# Create a chat session for iterative editing
chat = client.chats.create(model="gemini-2.5-flash-image")

# Generate initial image
response = chat.send_message(
    "Create a photorealistic image of a cozy coffee shop interior at night, warm lighting"
)

# Parse response parts (text + image)
for part in response.candidates[0].content.parts:
    if part.text:
        print(part.text)
    elif part.inline_data:
        img = part.as_image()
        img.save("coffee_shop.png")

# Iteratively edit
response2 = chat.send_message("Add a cat sleeping on one of the chairs")
for part in response2.candidates[0].content.parts:
    if part.inline_data:
        part.as_image().save("coffee_shop_v2.png")

7. Async Usage

python
import asyncio
from google import genai
from google.genai import types

async def generate_async():
    client = genai.Client()  # uses aiohttp if installed
    
    response = await client.aio.models.generate_images(
        model="imagen-4.0-generate-001",
        prompt="A futuristic city at dusk",
        config=types.GenerateImagesConfig(number_of_images=2),
    )
    return response.generated_images

asyncio.run(generate_async())

8. GCS Output Pattern (Production)

For production workflows, always write outputs to GCS rather than returning bytes:

python
operation = client.models.generate_videos(
    model="veo-3.0-generate-001",
    prompt="...",
    config=types.GenerateVideosConfig(
        output_gcs_uri="gs://your-bucket/outputs/",
        number_of_videos=2,
    ),
)

# Response contains GCS URIs
for video in operation.response.generated_videos:
    print(video.video.uri)  # e.g., gs://your-bucket/outputs/sample_0.mp4

9. Safety & Content Filters

All Google media models include automatic SynthID digital watermarking in every output.

Safety Filter Levels (Imagen)

python
config=types.GenerateImagesConfig(
    safety_filter_level="block_medium_and_above",  # default
    # Options: "block_low_and_above" (strictest), "block_medium_and_above", "block_only_high"
    person_generation="allow_adult",
    # Options: "allow_all", "allow_adult", "dont_allow"
)

Checking RAI Refusals

python
for img in response.generated_images:
    if img.rai_filtered_reason:
        print(f"Blocked: {img.rai_filtered_reason}")
    else:
        img.image.save("output.jpg")

10. Error Handling

python
from google.genai.errors import APIError, ClientError

try:
    response = client.models.generate_images(
        model="imagen-4.0-generate-001",
        prompt=user_prompt,
        config=types.GenerateImagesConfig(number_of_images=1),
    )
except ClientError as e:
    print(f"Client error (bad request): {e.status_code} — {e.message}")
except APIError as e:
    print(f"API error: {e.status_code} — {e.message}")

11. Quick-Reference Cheatsheet

TaskModelAPI
Text → Image (quality)imagen-4.0-generate-001client.models.generate_images()
Text → Image (fast)imagen-4.0-fast-generate-001client.models.generate_images()
Upscale image 2x/4ximagen-4.0-upscale-previewclient.models.upscale_image()
Inpaint / background swapimagen-3.0-capability-001client.models.edit_image()
Text → Video (quality)veo-3.0-generate-001client.models.generate_videos()
Text → Video (fast)veo-3.0-fast-generate-001client.models.generate_videos()
Image → Videoveo-3.1-generate-previewclient.models.generate_videos()
Video extensionveo-2.0-generate-001client.models.generate_videos()
Iterative image chatgemini-2.5-flash-imageclient.chats.create()
Text → Musiclyria-002 (Vertex only)Vertex AI Studio / REST API

12. Key Gotchas

  • Image editing and upscaling require Vertex AI — they are not available on the Gemini Developer API (AI Studio).
  • Video generation is async — always poll with client.operations.get() in a loop.
  • Veo 3.1 does not support style reference images — use veo-2.0-generate-exp for that feature.
  • imagen-4.0-fast-generate-001 may produce poor results on complex prompts — set enhance_prompt=False or switch to the standard model.
  • Do not use google-generativeai — it reached end-of-life November 30, 2025.
  • Veo is expensive — always confirm pricing before running bulk jobs: https://cloud.google.com/vertex-ai/generative-ai/pricing
  • GCS output is recommended for video — returning video bytes inline can cause timeouts for long generations.
  • Supported video durations: typically 5–8 seconds; check per model documentation.
  • Location matters: Most Imagen/Veo models are only available in us-central1.

13. References

Câu hỏi thường gặp

Kỹ năng AI Google Genai Media làm được gì?

Hướng dẫn tích hợp đầy đủ các dịch vụ tạo nội dung AI đa phương tiện mới nhất của Google: Imagen 4 (tạo, chỉnh sửa và phóng to ảnh), Veo 3/3.1 (tạo video, chuyển ảnh thành video, kéo dài video), Lyria 2 (tạo nhạc) và khả năng tạo ảnh đa phương thức của Gemini — tất cả thông qua Google Gen AI SDK thống nhất (google-genai). Dùng kỹ năng này bất cứ khi nào người dùng muốn tạo, chỉnh sửa hoặc biến đổi hình ảnh hay video bằng Google AI, làm việc với API đa phương tiện của Vertex AI, xây dựng quy trình tạo nội dung, tích hợp Imagen hoặc Veo vào ứng dụng, hoặc hỏi về khả năng tạo ảnh/video của Gem...

Vì sao nên dùng Google Genai Media trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Google Genai Media là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Google Genai Media trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/mainza-ai/milimovideo/tree/main/skills/skills/google-ai. TypingMind đọc tệp SKILL.md rồi cài đặt kỹ năng để bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Google Genai Media?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Google Genai Media với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Google Genai Media với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Google Genai Media có miễn phí không?

Kỹ năng này được mainza-ai phát hành trên GitHub. Hãy xem điều khoản giấy phép trong kho mã. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇