Họ các mô hình mã nguồn mở Gemma 4 của Google hiện đã có sẵn thông qua Gemini API và Google AI Studio. Được xây dựng dựa trên cùng một nghiên cứu đằng sau Gemini 3, các mô hình này mang đến khả năng suy luận nâng cao, gọi hàm gốc, hiểu biết đa phương thức và cửa sổ ngữ cảnh 256K trong một gói mã nguồn mở, được cấp phép theo Apache 2.0 mà bạn có thể chạy ở bất cứ đâu.
Hiện có hai mô hình có sẵn thông qua Gemini API:
- gemma-4-26b-a4b-it
- gemma-4-31b-it
Điều gì làm cho Gemma 4 khác biệt?
Các mô hình Gemma 4 xử lý việc gọi hàm, đầu ra JSON có cấu trúc và những lệnh hệ thống ở cấp độ mô hình chứ không phải thông qua kỹ thuật tạo prompt. Mô hình 31B dày đặc hiện đang xếp hạng #3 trong số các mô hình mã nguồn mở trên bảng xếp hạng văn bản Arena AI, với mô hình 26B MoE ở vị trí #6, cạnh tranh với các mô hình có kích thước gấp 20 lần.
Các tính năng chính:
- Cửa sổ ngữ cảnh 256K trên cả hai mô hình
- Gọi hàm gốc và đầu ra có cấu trúc
- Văn bản, hình ảnh và video đa phương thức
- Hơn 140 ngôn ngữ được đào tạo gốc
- Giấy phép Apache 2.0 cho phép sử dụng thương mại đầy đủ, không hạn chế
Bắt đầu với AI Studio
Cách nhanh nhất để thử Gemma 4 là Google AI Studio. Chọn gemma-4-26b-a4b-it hoặc gemma-4-31b-it từ trình chọn mô hình, nhập prompt và bắt đầu trò chuyện. Bạn có thể kiểm tra hướng dẫn hệ thống, điều chỉnh nhiệt độ và thử nghiệm với đầu vào đa phương thức thông qua trình duyệt. Không cần API key hoặc code.
Hoặc nhấp vào Get Code để xuất các snippet Python, JavaScript hoặc cURL từ bất kỳ cuộc hội thoại nào.
Sử dụng Gemma 4 với Gemini API
Cài đặt SDK Python:
pip install google-genaiĐặt API key của bạn làm biến môi trường. Bạn có thể tạo một key tại aistudio.google.com/apikey.
export GEMINI_API_KEY="api-key-của-bạn"Tạo văn bản
Tạo văn bản với Gemma 4:
from google import genai
client = genai.Client()
response = client.models.generate_content(
model="gemma-4-26b-a4b-it",
contents="Compare ramen and udon in 3 bullet points: broth, noodle texture, and best season to eat."
)
print(response.text)Truyền một lệnh hệ thống để thiết lập hành vi của mô hình:
from google import genai
from google.genai import types
client = genai.Client()
response = client.models.generate_content(
model="gemma-4-31b-it",
config=types.GenerateContentConfig(
system_instruction="You are a wise Kyoto tea master. Speak calmly and poetically, using nature metaphors. Keep answers under 3 sentences."
),
contents="What is the purpose of the tea ceremony?"
)
print(response.text)Hội thoại nhiều lượt
SDK cung cấp giao diện trò chuyện tự động theo dõi lịch sử hội thoại:
from google import genai
client = genai.Client()
chat = client.chats.create(model="gemma-4-26b-a4b-it")
response = chat.send_message("What are the three most famous castles in Japan?")
print(response.text)
response = chat.send_message("Which one should I visit in spring for cherry blossoms?")
print(response.text)Hiểu hình ảnh
Truyền một hình ảnh cùng với prompt văn bản của bạn:
from google import genai
from google.genai import types
client = genai.Client()
with open("path/to/image.png", "rb") as f:
image_bytes = f.read()
response = client.models.generate_content(
model="gemma-4-26b-a4b-it",
contents=[
types.Part.from_bytes(data=image_bytes, mime_type="image/png"),
"Describe this image in 2-3 sentences as if writing a caption for a Japanese travel magazine."
]
)
print(response.text)Gọi hàm
Định nghĩa các công cụ dưới dạng khai báo hàm. Mô hình quyết định khi nào gọi chúng:
from google import genai
from google.genai import types
# Define the function declaration
get_weather = {
"name": "get_weather",
"description": "Get current weather for a given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and state, e.g. 'San Francisco, CA'",
},
},
"required": ["location"],
},
}
client = genai.Client()
tools = types.Tool(function_declarations=[get_weather])
config = types.GenerateContentConfig(tools=[tools])
response = client.models.generate_content(
model="gemma-4-26b-a4b-it",
contents="Should I bring an umbrella to Kyoto today?",
config=config,
)
# The model returns a function call instead of text
if response.candidates[0].content.parts[0].function_call:
fc = response.candidates[0].content.parts[0].function_call
print(f"Function: {fc.name}")
print(f"Arguments: {fc.args}")Google Search
Dựa trên dữ liệu web thời gian thực từ Google Search, Gemma 4 đưa ra các phản hồi:
from google import genai
from google.genai import types
client = genai.Client()
response = client.models.generate_content(
model="gemma-4-26b-a4b-it",
contents="What are the dates for cherry blossom season in Tokyo this year?",
config=types.GenerateContentConfig(
tools=[{"google_search":{}}]
),
)
print(response.text)
# Access grounding metadata for citations
for chunk in response.candidates[0].grounding_metadata.grounding_chunks:
print(f"Source: {chunk.web.title} — {chunk.web.uri}")
Hướng dẫn AI
Học IT










AI
Hàm Excel