คู่มือสำหรับนักพัฒนาซอฟต์แวร์ Gemini 3

Gemini 3 เป็นตระกูลโมเดลที่ชาญฉลาดที่สุดของเราในปัจจุบัน ซึ่งสร้างขึ้นบนพื้นฐานของการให้เหตุผลที่ล้ำสมัย ออกแบบมาเพื่อทำให้ทุกไอเดียเป็นจริงด้วยการฝึกฝนเวิร์กโฟลว์แบบ Agent การเขียนโค้ดแบบอัตโนมัติ และงานแบบ Multimodal ที่ซับซ้อน คู่มือนี้ครอบคลุมฟีเจอร์หลักของกลุ่มโมเดล Gemini 3 และวิธีใช้ให้เกิดประโยชน์สูงสุด

สำรวจคอลเล็กชันแอป Gemini 3 เพื่อดูว่าโมเดลจัดการการให้เหตุผลขั้นสูง การเขียนโค้ดอัตโนมัติ และงานที่ซับซ้อนแบบมัลติโมดัลได้อย่างไร

เริ่มต้นใช้งานด้วยโค้ดเพียงไม่กี่บรรทัด

Python

from google import genai

client = genai.Client()

response = client.models.generate_content(
    model="gemini-3-pro-preview",
    contents="Find the race condition in this multi-threaded C++ snippet: [code here]",
)

print(response.text)

JavaScript

import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({});

async function run() {
  const response = await ai.models.generateContent({
    model: "gemini-3-pro-preview",
    contents: "Find the race condition in this multi-threaded C++ snippet: [code here]",
  });

  console.log(response.text);
}

run();

REST

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [{
      "parts": [{"text": "Find the race condition in this multi-threaded C++ snippet: [code here]"}]
    }]
  }'

พบกับซีรีส์ Gemini 3

Gemini 3 Pro ซึ่งเป็นโมเดลแรกในซีรีส์ใหม่นี้ เหมาะที่สุดสำหรับงานที่ซับซ้อนซึ่ง ต้องใช้ความรู้เกี่ยวกับโลกในวงกว้างและการให้เหตุผลขั้นสูงในรูปแบบต่างๆ

Gemini 3 Flash เป็นโมเดลล่าสุดในซีรีส์ 3 ที่มีความสามารถระดับ Pro ใน ความเร็วและราคาของ Flash

Nano Banana Pro (หรือที่เรียกว่า Gemini 3 Pro Image) เป็นโมเดลสร้างรูปภาพคุณภาพสูงสุดของเรา

ปัจจุบันโมเดล Gemini 3 ทั้งหมดอยู่ในการแสดงตัวอย่าง

รหัสโมเดล หน้าต่างบริบท (เข้า / ออก) การตัดข้อมูล การกำหนดราคา (อินพุต / เอาต์พุต)*
gemini-3-pro-preview 1M / 64k มกราคม 2025 $2 / $12 (<200k โทเค็น)
$4 / $18 (>200k โทเค็น)
gemini-3-flash-preview 1M / 64k มกราคม 2025 $0.50 / $3
gemini-3-pro-image-preview 65,000 / 32,000 มกราคม 2025 $2 (ป้อนข้อความ) / $0.134 (เอาต์พุตรูปภาพ)**

* ราคาต่อโทเค็น 1 ล้านรายการ เว้นแต่จะระบุไว้เป็นอย่างอื่น ** ราคาของรูปภาพจะแตกต่างกันไปตามความละเอียด ดูรายละเอียดได้ที่หน้าการกำหนดราคา

ดูขีดจำกัดโดยละเอียด ราคา และข้อมูลเพิ่มเติมได้ที่หน้าโมเดล

ฟีเจอร์ใหม่ของ API ใน Gemini 3

Gemini 3 มีพารามิเตอร์ใหม่ที่ออกแบบมาเพื่อช่วยให้นักพัฒนาแอปควบคุมเวลาในการตอบสนอง ต้นทุน และความเที่ยงตรงของโมเดลแบบมัลติโมดัลได้มากขึ้น

ระดับการคิด

โมเดลชุด Gemini 3 ใช้การคิดแบบไดนามิกโดยค่าเริ่มต้นเพื่อใช้เหตุผลผ่านพรอมต์ คุณสามารถใช้พารามิเตอร์ thinking_level ซึ่งควบคุมความลึกสูงสุดของกระบวนการให้เหตุผลภายในของโมเดลก่อนที่จะสร้างคำตอบ Gemini 3 จะถือว่าระดับเหล่านี้เป็นค่าเผื่อสัมพัทธ์สำหรับการคิดแทนที่จะเป็นการรับประกันโทเค็นที่เข้มงวด

หากไม่ได้ระบุ thinking_level ไว้ Gemini 3 จะใช้ high เป็นค่าเริ่มต้น หากต้องการให้โมเดลตอบกลับได้เร็วขึ้นและมีเวลาในการตอบสนองที่ต่ำลงเมื่อไม่จำเป็นต้องใช้การให้เหตุผลที่ซับซ้อน คุณสามารถจำกัดระดับการคิดของโมเดลไว้ที่ low ได้

ระดับความคิดของ Gemini 3 Pro และ Flash

ทั้ง Gemini 3 Pro และ Flash รองรับระดับการคิดต่อไปนี้

  • low: ลดเวลาในการตอบสนองและค่าใช้จ่าย เหมาะที่สุดสำหรับการทำตามคำสั่งง่ายๆ แชท หรือแอปพลิเคชันที่มีปริมาณงานสูง
  • high (ค่าเริ่มต้น แบบไดนามิก): เพิ่มความลึกของการให้เหตุผลสูงสุด โมเดลอาจใช้เวลานานกว่ามากในการสร้างโทเค็นแรก แต่เอาต์พุตจะได้รับการพิจารณาอย่างรอบคอบมากขึ้น

ระดับการคิดของ Gemini 3 Flash

นอกจากระดับข้างต้นแล้ว Gemini 3 Flash ยังรองรับระดับการคิดต่อไปนี้ ซึ่ง Gemini 3 Pro ยังไม่รองรับในขณะนี้

  • minimal: ตรงกับการตั้งค่า "ไม่ต้องคิด" สำหรับคำค้นหาส่วนใหญ่ โมเดลอาจคิดน้อยมากสำหรับงานการเขียนโค้ดที่ซับซ้อน ลดเวลาในการตอบสนองสำหรับแอปพลิเคชันแชทหรือแอปพลิเคชันที่มีปริมาณงานสูง

  • medium: การคิดอย่างสมดุลสำหรับงานส่วนใหญ่

Python

from google import genai
from google.genai import types

client = genai.Client()

response = client.models.generate_content(
    model="gemini-3-pro-preview",
    contents="How does AI work?",
    config=types.GenerateContentConfig(
        thinking_config=types.ThinkingConfig(thinking_level="low")
    ),
)

print(response.text)

JavaScript

import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({});

const response = await ai.models.generateContent({
    model: "gemini-3-pro-preview",
    contents: "How does AI work?",
    config: {
      thinkingConfig: {
        thinkingLevel: "low",
      }
    },
  });

console.log(response.text);

REST

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [{
      "parts": [{"text": "How does AI work?"}]
    }],
    "generationConfig": {
      "thinkingConfig": {
        "thinkingLevel": "low"
      }
    }
  }'

ความละเอียดของสื่อ

Gemini 3 มีการควบคุมการประมวลผลวิชันซิสเต็มแบบมัลติโมดัลอย่างละเอียดผ่านพารามิเตอร์ media_resolution ความละเอียดที่สูงขึ้นจะช่วยปรับปรุงความสามารถของโมเดลในการอ่านข้อความขนาดเล็กหรือระบุรายละเอียดเล็กๆ แต่จะเพิ่มการใช้โทเค็นและเวลาในการตอบสนอง พารามิเตอร์ media_resolution จะกำหนดจำนวนโทเค็นสูงสุดที่จัดสรรต่อรูปภาพอินพุตหรือเฟรมวิดีโอ

ตอนนี้คุณสามารถตั้งค่าความละเอียดเป็น media_resolution_low, media_resolution_medium, media_resolution_high หรือ media_resolution_ultra_high ต่อชิ้นสื่อแต่ละชิ้นหรือทั่วโลก (ผ่าน generation_config, ความละเอียดระดับสูงพิเศษไม่พร้อมใช้งานทั่วโลก) หากไม่ได้ระบุไว้ โมเดลจะใช้ค่าเริ่มต้นที่เหมาะสมตามประเภทสื่อ

การตั้งค่าที่แนะนำ

ประเภทสื่อ การตั้งค่าที่แนะนำ โทเค็นสูงสุด คำแนะนำในการใช้งาน
รูปภาพ media_resolution_high 1120 แนะนำสำหรับงานวิเคราะห์รูปภาพส่วนใหญ่เพื่อให้มั่นใจว่ามีคุณภาพสูงสุด
PDF media_resolution_medium 560 เหมาะสำหรับการทำความเข้าใจเอกสาร โดยปกติคุณภาพจะอิ่มตัวที่ medium การเพิ่มเป็น high แทบจะไม่ช่วยปรับปรุงผลลัพธ์ OCR สำหรับเอกสารมาตรฐาน
วิดีโอ (ทั่วไป) media_resolution_low (หรือ media_resolution_medium) 70 (ต่อเฟรม) หมายเหตุ: สำหรับวิดีโอ ระบบจะถือว่าการตั้งค่า low และ medium เหมือนกัน (70 โทเค็น) เพื่อเพิ่มประสิทธิภาพการใช้งานบริบท ซึ่งเพียงพอสำหรับงานการจดจำและการอธิบายการกระทำส่วนใหญ่
วิดีโอ (มีข้อความจำนวนมาก) media_resolution_high 280 (ต่อเฟรม) จำเป็นเฉพาะเมื่อ Use Case เกี่ยวข้องกับการอ่านข้อความหนาแน่น (OCR) หรือรายละเอียดเล็กๆ ภายในเฟรมวิดีโอ

Python

from google import genai
from google.genai import types
import base64

# The media_resolution parameter is currently only available in the v1alpha API version.
client = genai.Client(http_options={'api_version': 'v1alpha'})

response = client.models.generate_content(
    model="gemini-3-pro-preview",
    contents=[
        types.Content(
            parts=[
                types.Part(text="What is in this image?"),
                types.Part(
                    inline_data=types.Blob(
                        mime_type="image/jpeg",
                        data=base64.b64decode("..."),
                    ),
                    media_resolution={"level": "media_resolution_high"}
                )
            ]
        )
    ]
)

print(response.text)

JavaScript

import { GoogleGenAI } from "@google/genai";

// The media_resolution parameter is currently only available in the v1alpha API version.
const ai = new GoogleGenAI({ apiVersion: "v1alpha" });

async function run() {
  const response = await ai.models.generateContent({
    model: "gemini-3-pro-preview",
    contents: [
      {
        parts: [
          { text: "What is in this image?" },
          {
            inlineData: {
              mimeType: "image/jpeg",
              data: "...",
            },
            mediaResolution: {
              level: "media_resolution_high"
            }
          }
        ]
      }
    ]
  });

  console.log(response.text);
}

run();

REST

curl "https://generativelanguage.googleapis.com/v1alpha/models/gemini-3-pro-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [{
      "parts": [
        { "text": "What is in this image?" },
        {
          "inlineData": {
            "mimeType": "image/jpeg",
            "data": "..."
          },
          "mediaResolution": {
            "level": "media_resolution_high"
          }
        }
      ]
    }]
  }'

อุณหภูมิ

สำหรับ Gemini 3 เราขอแนะนำอย่างยิ่งให้คงพารามิเตอร์อุณหภูมิไว้ที่ค่าเริ่มต้น 1.0

แม้ว่าโมเดลก่อนหน้ามักจะได้รับประโยชน์จากการปรับอุณหภูมิเพื่อควบคุมความคิดสร้างสรรค์เทียบกับความแน่นอน แต่ความสามารถในการให้เหตุผลของ Gemini 3 ได้รับการเพิ่มประสิทธิภาพสำหรับการตั้งค่าเริ่มต้น การเปลี่ยนอุณหภูมิ (ตั้งค่าต่ำกว่า 1.0) อาจทำให้เกิดลักษณะการทำงานที่ไม่คาดคิด เช่น การวนซ้ำหรือประสิทธิภาพลดลง โดยเฉพาะในงานทางคณิตศาสตร์หรือการให้เหตุผลที่ซับซ้อน

ลายเซ็นความคิด

Gemini 3 ใช้ลายเซ็นความคิดเพื่อรักษาบริบทการให้เหตุผลในการเรียก API ลายเซ็นเหล่านี้คือการแสดงที่เข้ารหัสของกระบวนการคิดภายในของโมเดล คุณต้องส่งลายเซ็นเหล่านี้กลับไปยังโมเดลในคำขอของคุณตามที่ได้รับมาทุกประการเพื่อให้โมเดลยังคงความสามารถในการให้เหตุผลไว้

  • การเรียกใช้ฟังก์ชัน (เข้มงวด): API จะบังคับใช้การตรวจสอบที่เข้มงวดกับ "เทิร์นปัจจุบัน" หากไม่มีลายเซ็น ระบบจะแสดงข้อผิดพลาด 400

  • ข้อความ/แชท: ระบบไม่ได้บังคับใช้การตรวจสอบอย่างเคร่งครัด แต่การละเว้นลายเซ็นจะทำให้คุณภาพการให้เหตุผลและคำตอบของโมเดลลดลง

  • การสร้าง/แก้ไขรูปภาพ (เข้มงวด): API จะบังคับใช้การตรวจสอบอย่างเข้มงวดกับทุกส่วนของโมเดล รวมถึง thoughtSignature หากไม่มีลายเซ็น ระบบจะแสดงข้อผิดพลาด 400

การเรียกใช้ฟังก์ชัน (การตรวจสอบอย่างเข้มงวด)

เมื่อ Gemini สร้าง functionCall จะใช้ thoughtSignature เพื่อประมวลผลเอาต์พุตของเครื่องมืออย่างถูกต้องในรอบถัดไป "เทิร์นปัจจุบัน" ประกอบด้วยขั้นตอนโมเดล (functionCall) และผู้ใช้ (functionResponse) ทั้งหมดที่เกิดขึ้นนับตั้งแต่ข้อความผู้ใช้ text มาตรฐานล่าสุด

  • การเรียกใช้ฟังก์ชันเดียว: ส่วน functionCall มีลายเซ็น คุณต้องส่งคืน
  • การเรียกใช้ฟังก์ชันแบบขนาน: เฉพาะส่วน functionCall แรกในรายการเท่านั้นที่จะมีลายเซ็น คุณต้องส่งคืนชิ้นส่วนตามลำดับที่ได้รับ
  • หลายขั้นตอน (ตามลำดับ): หากโมเดลเรียกใช้เครื่องมือ รับผลลัพธ์ และเรียกใช้เครื่องมืออีกเครื่องมือหนึ่ง (ภายในเทิร์นเดียวกัน) การเรียกใช้ฟังก์ชันทั้ง 2 รายการจะมีลายเซ็น คุณต้องส่งคืนลายเซ็นที่สะสมทั้งหมดในประวัติ

ข้อความและการสตรีม

สำหรับการแชทหรือการสร้างข้อความมาตรฐาน ระบบไม่รับประกันว่าจะมีลายเซ็น

  • ไม่ใช่การสตรีม: ส่วนเนื้อหาสุดท้ายของการตอบกลับอาจมี thoughtSignature แต่อาจไม่มีเสมอไป หากได้รับอุปกรณ์คืน คุณควรส่งอุปกรณ์กลับเพื่อรักษาประสิทธิภาพที่ดีที่สุด
  • การสตรีม: หากมีการสร้างลายเซ็น ลายเซ็นอาจอยู่ในก้อนข้อมูลสุดท้ายซึ่งมีส่วนข้อความที่ว่างเปล่า ตรวจสอบว่าตัวแยกวิเคราะห์สตรีมของคุณตรวจสอบลายเซ็นแม้ว่าช่องข้อความจะว่างเปล่าก็ตาม

การสร้างและแก้ไขรูปภาพ

สำหรับ gemini-3-pro-image-preview ลายเซ็นความคิดมีความสำคัญอย่างยิ่งต่อการแก้ไขแบบสนทนา เมื่อขอให้โมเดลแก้ไขรูปภาพ โมเดลจะใช้thoughtSignatureจากรอบก่อนหน้าเพื่อทำความเข้าใจองค์ประกอบและตรรกะของรูปภาพต้นฉบับ

  • การแก้ไข: ระบบจะรับประกันลายเซ็นในส่วนแรกหลังจากความคิดของคำตอบ (text หรือ inlineData) และในส่วน inlineData ที่ตามมาทั้งหมด คุณต้องส่งคืนลายเซ็นทั้งหมดนี้เพื่อหลีกเลี่ยงข้อผิดพลาด

ตัวอย่างโค้ด

การเรียกใช้ฟังก์ชันแบบหลายขั้นตอน (ตามลำดับ)

ผู้ใช้ถามคำถามที่ต้องทำ 2 ขั้นตอนแยกกัน (ตรวจสอบเที่ยวบิน -> จองแท็กซี่) ในการสนทนาครั้งเดียว

ขั้นตอนที่ 1: เครื่องมือเที่ยวบินเรียกใช้โมเดล
โมเดลจะแสดงลายเซ็น <Sig_A>

// Model Response (Turn 1, Step 1)
  {
    "role": "model",
    "parts": [
      {
        "functionCall": { "name": "check_flight", "args": {...} },
        "thoughtSignature": "<Sig_A>" // SAVE THIS
      }
    ]
  }

ขั้นตอนที่ 2: ผู้ใช้ส่งผลการค้นหาเที่ยวบิน
เราต้องส่ง <Sig_A> กลับเพื่อรักษาลำดับความคิดของโมเดล

// User Request (Turn 1, Step 2)
[
  { "role": "user", "parts": [{ "text": "Check flight AA100..." }] },
  { 
    "role": "model", 
    "parts": [
      { 
        "functionCall": { "name": "check_flight", "args": {...} }, 
        "thoughtSignature": "<Sig_A>" // REQUIRED
      } 
    ]
  },
  { "role": "user", "parts": [{ "functionResponse": { "name": "check_flight", "response": {...} } }] }
]

ขั้นตอนที่ 3: โมเดลเรียกใช้เครื่องมือแท็กซี่
โมเดลจดจำความล่าช้าของเที่ยวบินผ่าน <Sig_A> และตัดสินใจจองแท็กซี่ ซึ่งจะสร้างลายเซ็นใหม่ <Sig_B>

// Model Response (Turn 1, Step 3)
{
  "role": "model",
  "parts": [
    {
      "functionCall": { "name": "book_taxi", "args": {...} },
      "thoughtSignature": "<Sig_B>" // SAVE THIS
    }
  ]
}

ขั้นตอนที่ 4: ผู้ใช้ส่งผลลัพธ์แท็กซี่
หากต้องการจบเทิร์น คุณต้องส่งทั้งเชนกลับมา ซึ่งได้แก่ <Sig_A> และ <Sig_B>

// User Request (Turn 1, Step 4)
[
  // ... previous history ...
  { 
    "role": "model", 
    "parts": [
       { "functionCall": { "name": "check_flight", ... }, "thoughtSignature": "<Sig_A>" } 
    ]
  },
  { "role": "user", "parts": [{ "functionResponse": {...} }] },
  { 
    "role": "model", 
    "parts": [
       { "functionCall": { "name": "book_taxi", ... }, "thoughtSignature": "<Sig_B>" } 
    ]
  },
  { "role": "user", "parts": [{ "functionResponse": {...} }] }
]

การเรียกใช้ฟังก์ชันแบบคู่ขนาน

ผู้ใช้ถามว่า "ตรวจสอบสภาพอากาศในปารีสและลอนดอน" โมเดลจะแสดงผลการเรียกใช้ฟังก์ชัน 2 รายการในคำตอบเดียว

// User Request (Sending Parallel Results)
[
  {
    "role": "user",
    "parts": [
      { "text": "Check the weather in Paris and London." }
    ]
  },
  {
    "role": "model",
    "parts": [
      // 1. First Function Call has the signature
      {
        "functionCall": { "name": "check_weather", "args": { "city": "Paris" } },
        "thoughtSignature": "<Signature_A>" 
      },
      // 2. Subsequent parallel calls DO NOT have signatures
      {
        "functionCall": { "name": "check_weather", "args": { "city": "London" } }
      } 
    ]
  },
  {
    "role": "user",
    "parts": [
      // 3. Function Responses are grouped together in the next block
      {
        "functionResponse": { "name": "check_weather", "response": { "temp": "15C" } }
      },
      {
        "functionResponse": { "name": "check_weather", "response": { "temp": "12C" } }
      }
    ]
  }
]

การให้เหตุผลแบบข้อความ/ในบริบท (ไม่มีการตรวจสอบ)

ผู้ใช้ถามคำถามที่ต้องใช้การให้เหตุผลในบริบทโดยไม่ต้องใช้เครื่องมือภายนอก แม้ว่าจะไม่ได้ตรวจสอบอย่างเข้มงวด แต่การใส่ลายเซ็นจะช่วยให้โมเดลคงห่วงโซ่การให้เหตุผลสำหรับคำถามติดตามผลได้

// User Request (Follow-up question)
[
  { 
    "role": "user", 
    "parts": [{ "text": "What are the risks of this investment?" }] 
  },
  { 
    "role": "model", 
    "parts": [
      {
        "text": "I need to calculate the risk step-by-step. First, I'll look at volatility...",
        "thoughtSignature": "<Signature_C>" // Recommended to include
      }
    ]
  },
  { 
    "role": "user", 
    "parts": [{ "text": "Summarize that in one sentence." }] 
  }
]

การสร้างและแก้ไขรูปภาพ

สำหรับการสร้างรูปภาพ ระบบจะตรวจสอบลายเซ็นอย่างเข้มงวด โดยจะปรากฏในส่วนแรก (ข้อความหรือรูปภาพ) และส่วนรูปภาพทั้งหมดที่ตามมา โดยต้องส่งคืนทั้งหมดในเทิร์นถัดไป

// Model Response (Turn 1)
{
  "role": "model",
  "parts": [
    // 1. First part ALWAYS has a signature (even if text)
    {
      "text": "I will generate a cyberpunk city...",
      "thoughtSignature": "<Signature_D>" 
    },
    // 2. ALL InlineData (Image) parts ALWAYS have signatures
    {
      "inlineData": { ... }, 
      "thoughtSignature": "<Signature_E>" 
    },
  ]
}

// User Request (Turn 2 - Requesting an Edit)
{
  "contents": [
    // History must include ALL signatures received
    {
      "role": "user",
      "parts": [{ "text": "Generate a cyberpunk city" }]
    },
    {
      "role": "model",
      "parts": [
         { "text": "...", "thoughtSignature": "<Signature_D>" },
         { "inlineData": "...", "thoughtSignature": "<Signature_E>" },
      ]
    },
    // New User Prompt
    {
      "role": "user",
      "parts": [{ "text": "Make it daytime." }]
    }
  ]
}

การย้ายข้อมูลจากรุ่นอื่นๆ

หากคุณโอนการติดตามการสนทนาจากโมเดลอื่น (เช่น Gemini 2.5) หรือแทรกการเรียกใช้ฟังก์ชันที่กำหนดเองซึ่ง Gemini 3 ไม่ได้สร้าง คุณจะไม่มีลายเซ็นที่ถูกต้อง

หากต้องการข้ามการตรวจสอบอย่างเข้มงวดในสถานการณ์ที่เฉพาะเจาะจงเหล่านี้ ให้ป้อนสตริงจำลองที่เฉพาะเจาะจงนี้ในช่อง "thoughtSignature": "context_engineering_is_the_way_to_go"

เอาต์พุตที่มีโครงสร้างด้วยเครื่องมือ

โมเดล Gemini 3 ช่วยให้คุณรวมเอาต์พุตที่มีโครงสร้างเข้ากับเครื่องมือในตัวได้ ซึ่งรวมถึงการอ้างอิงจาก Google Search, บริบท URL, การเรียกใช้โค้ด และการเรียกใช้ฟังก์ชัน

Python

from google import genai
from google.genai import types
from pydantic import BaseModel, Field
from typing import List

class MatchResult(BaseModel):
    winner: str = Field(description="The name of the winner.")
    final_match_score: str = Field(description="The final match score.")
    scorers: List[str] = Field(description="The name of the scorer.")

client = genai.Client()

response = client.models.generate_content(
    model="gemini-3-pro-preview",
    contents="Search for all details for the latest Euro.",
    config={
        "tools": [
            {"google_search": {}},
            {"url_context": {}}
        ],
        "response_mime_type": "application/json",
        "response_json_schema": MatchResult.model_json_schema(),
    },  
)

result = MatchResult.model_validate_json(response.text)
print(result)

JavaScript

import { GoogleGenAI } from "@google/genai";
import { z } from "zod";
import { zodToJsonSchema } from "zod-to-json-schema";

const ai = new GoogleGenAI({});

const matchSchema = z.object({
  winner: z.string().describe("The name of the winner."),
  final_match_score: z.string().describe("The final score."),
  scorers: z.array(z.string()).describe("The name of the scorer.")
});

async function run() {
  const response = await ai.models.generateContent({
    model: "gemini-3-pro-preview",
    contents: "Search for all details for the latest Euro.",
    config: {
      tools: [
        { googleSearch: {} },
        { urlContext: {} }
      ],
      responseMimeType: "application/json",
      responseJsonSchema: zodToJsonSchema(matchSchema),
    },
  });

  const match = matchSchema.parse(JSON.parse(response.text));
  console.log(match);
}

run();

REST

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [{
      "parts": [{"text": "Search for all details for the latest Euro."}]
    }],
    "tools": [
      {"googleSearch": {}},
      {"urlContext": {}}
    ],
    "generationConfig": {
        "responseMimeType": "application/json",
        "responseJsonSchema": {
            "type": "object",
            "properties": {
                "winner": {"type": "string", "description": "The name of the winner."},
                "final_match_score": {"type": "string", "description": "The final score."},
                "scorers": {
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "The name of the scorer."
                }
            },
            "required": ["winner", "final_match_score", "scorers"]
        }
    }
  }'

การสร้างรูปภาพ

Gemini 3 Pro Image ช่วยให้คุณสร้างและแก้ไขรูปภาพจากพรอมต์ข้อความได้ โดยใช้การให้เหตุผลเพื่อ "คิด" ผ่านพรอมต์ และสามารถดึงข้อมูลแบบเรียลไทม์ เช่น พยากรณ์อากาศหรือแผนภูมิหุ้น ก่อนที่จะใช้การอ้างอิงจาก Google Search ก่อนสร้างรูปภาพที่มีความเที่ยงตรงสูง

ความสามารถใหม่และที่ได้รับการปรับปรุง

  • การแสดงข้อความและ 4K: สร้างข้อความและไดอะแกรมที่คมชัดและอ่านง่ายด้วยความละเอียดสูงสุด 2K และ 4K
  • การสร้างที่อิงตามข้อเท็จจริง: ใช้เครื่องมือ google_search เพื่อยืนยันข้อเท็จจริงและสร้างภาพตามข้อมูลในโลกแห่งความเป็นจริง
  • การแก้ไขแบบสนทนา: การแก้ไขรูปภาพหลายรอบโดยเพียงแค่ขอให้ทำการเปลี่ยนแปลง (เช่น เปลี่ยนพื้นหลังเป็นภาพพระอาทิตย์ตก") เวิร์กโฟลว์นี้ใช้ลายเซ็นความคิดเพื่อรักษาบริบทภาพระหว่างการเลี้ยว

ดูรายละเอียดทั้งหมดเกี่ยวกับสัดส่วนการแสดง เวิร์กโฟลว์การแก้ไข และตัวเลือกการกำหนดค่าได้ที่คู่มือการสร้างรูปภาพ

Python

from google import genai
from google.genai import types

client = genai.Client()

response = client.models.generate_content(
    model="gemini-3-pro-image-preview",
    contents="Generate an infographic of the current weather in Tokyo.",
    config=types.GenerateContentConfig(
        tools=[{"google_search": {}}],
        image_config=types.ImageConfig(
            aspect_ratio="16:9",
            image_size="4K"
        )
    )
)

image_parts = [part for part in response.parts if part.inline_data]

if image_parts:
    image = image_parts[0].as_image()
    image.save('weather_tokyo.png')
    image.show()

JavaScript

import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";

const ai = new GoogleGenAI({});

async function run() {
  const response = await ai.models.generateContent({
    model: "gemini-3-pro-image-preview",
    contents: "Generate a visualization of the current weather in Tokyo.",
    config: {
      tools: [{ googleSearch: {} }],
      imageConfig: {
        aspectRatio: "16:9",
        imageSize: "4K"
      }
    }
  });

  for (const part of response.candidates[0].content.parts) {
    if (part.inlineData) {
      const imageData = part.inlineData.data;
      const buffer = Buffer.from(imageData, "base64");
      fs.writeFileSync("weather_tokyo.png", buffer);
    }
  }
}

run();

REST

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [{
      "parts": [{"text": "Generate a visualization of the current weather in Tokyo."}]
    }],
    "tools": [{"googleSearch": {}}],
    "generationConfig": {
        "imageConfig": {
          "aspectRatio": "16:9",
          "imageSize": "4K"
      }
    }
  }'

ตัวอย่างคำตอบ

สภาพอากาศ โตเกียว

การตอบกลับฟังก์ชันหลายรูปแบบ

การเรียกใช้ฟังก์ชันแบบมัลติโมดัล ช่วยให้ผู้ใช้ได้รับการตอบกลับฟังก์ชันที่มี ออบเจ็กต์มัลติโมดัล ซึ่งช่วยให้ใช้ความสามารถในการเรียกใช้ฟังก์ชัน ของโมเดลได้ดียิ่งขึ้น การเรียกใช้ฟังก์ชันมาตรฐานรองรับเฉพาะการตอบกลับฟังก์ชันที่เป็นข้อความ เท่านั้น

Python

from google import genai
from google.genai import types

import requests

client = genai.Client()

# This is a manual, two turn multimodal function calling workflow:

# 1. Define the function tool
get_image_declaration = types.FunctionDeclaration(
  name="get_image",
  description="Retrieves the image file reference for a specific order item.",
  parameters={
      "type": "object",
      "properties": {
          "item_name": {
              "type": "string",
              "description": "The name or description of the item ordered (e.g., 'instrument')."
          }
      },
      "required": ["item_name"],
  },
)
tool_config = types.Tool(function_declarations=[get_image_declaration])

# 2. Send a message that triggers the tool
prompt = "Show me the instrument I ordered last month."
response_1 = client.models.generate_content(
  model="gemini-3-flash-preview",
  contents=[prompt],
  config=types.GenerateContentConfig(
      tools=[tool_config],
  )
)

# 3. Handle the function call
function_call = response_1.function_calls[0]
requested_item = function_call.args["item_name"]
print(f"Model wants to call: {function_call.name}")

# Execute your tool (e.g., call an API)
# (This is a mock response for the example)
print(f"Calling external tool for: {requested_item}")

function_response_data = {
  "image_ref": {"$ref": "instrument.jpg"},
}
image_path = "https://goo.gle/instrument-img"
image_bytes = requests.get(image_path).content
function_response_multimodal_data = types.FunctionResponsePart(
  inline_data=types.FunctionResponseBlob(
    mime_type="image/jpeg",
    display_name="instrument.jpg",
    data=image_bytes,
  )
)

# 4. Send the tool's result back
# Append this turn's messages to history for a final response.
history = [
  types.Content(role="user", parts=[types.Part(text=prompt)]),
  response_1.candidates[0].content,
  types.Content(
    role="tool",
    parts=[
        types.Part.from_function_response(
          name=function_call.name,
          response=function_response_data,
          parts=[function_response_multimodal_data]
        )
    ],
  )
]

response_2 = client.models.generate_content(
  model="gemini-3-flash-preview",
  contents=history,
  config=types.GenerateContentConfig(
      tools=[tool_config],
      thinking_config=types.ThinkingConfig(include_thoughts=True)
  ),
)

print(f"\nFinal model response: {response_2.text}")

JavaScript

import { GoogleGenAI, Type } from '@google/genai';

const client = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });

// This is a manual, two turn multimodal function calling workflow:
// 1. Define the function tool
const getImageDeclaration = {
  name: 'get_image',
  description: 'Retrieves the image file reference for a specific order item.',
  parameters: {
    type: Type.OBJECT,
    properties: {
      item_name: {
        type: Type.STRING,
        description: "The name or description of the item ordered (e.g., 'instrument').",
      },
    },
    required: ['item_name'],
  },
};

const toolConfig = {
  functionDeclarations: [getImageDeclaration],
};

// 2. Send a message that triggers the tool
const prompt = 'Show me the instrument I ordered last month.';
const response1 = await client.models.generateContent({
  model: 'gemini-3-flash-preview',
  contents: prompt,
  config: {
    tools: [toolConfig],
  },
});

// 3. Handle the function call
const functionCall = response1.functionCalls[0];
const requestedItem = functionCall.args.item_name;
console.log(`Model wants to call: ${functionCall.name}`);

// Execute your tool (e.g., call an API)
// (This is a mock response for the example)
console.log(`Calling external tool for: ${requestedItem}`);

const functionResponseData = {
  image_ref: { $ref: 'instrument.jpg' },
};

const imageUrl = "https://goo.gle/instrument-img";
const response = await fetch(imageUrl);
const imageArrayBuffer = await response.arrayBuffer();
const base64ImageData = Buffer.from(imageArrayBuffer).toString('base64');

const functionResponseMultimodalData = {
  inlineData: {
    mimeType: 'image/jpeg',
    displayName: 'instrument.jpg',
    data: base64ImageData,
  },
};

// 4. Send the tool's result back
// Append this turn's messages to history for a final response.
const history = [
  { role: 'user', parts: [{ text: prompt }] },
  response1.candidates[0].content,
  {
    role: 'tool',
    parts: [
      {
        functionResponse: {
          name: functionCall.name,
          response: functionResponseData,
          parts: [functionResponseMultimodalData],
        },
      },
    ],
  },
];

const response2 = await client.models.generateContent({
  model: 'gemini-3-flash-preview',
  contents: history,
  config: {
    tools: [toolConfig],
    thinkingConfig: { includeThoughts: true },
  },
});

console.log(`\nFinal model response: ${response2.text}`);

REST

IMG_URL="https://goo.gle/instrument-img"

MIME_TYPE=$(curl -sIL "$IMG_URL" | grep -i '^content-type:' | awk -F ': ' '{print $2}' | sed 's/\r$//' | head -n 1)
if [[ -z "$MIME_TYPE" || ! "$MIME_TYPE" == image/* ]]; then
  MIME_TYPE="image/jpeg"
fi

# Check for macOS
if [[ "$(uname)" == "Darwin" ]]; then
  IMAGE_B64=$(curl -sL "$IMG_URL" | base64 -b 0)
elif [[ "$(base64 --version 2>&1)" = *"FreeBSD"* ]]; then
  IMAGE_B64=$(curl -sL "$IMG_URL" | base64)
else
  IMAGE_B64=$(curl -sL "$IMG_URL" | base64 -w0)
fi

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-flash-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [
      ...,
      {
        "role": "user",
        "parts": [
        {
            "functionResponse": {
              "name": "get_image",
              "response": {
                "image_ref": {
                  "$ref": "instrument.jpg"
                }
              },
              "parts": [
                {
                  "inlineData": {
                    "displayName": "instrument.jpg",
                    "mimeType":"'"$MIME_TYPE"'",
                    "data": "'"$IMAGE_B64"'"
                  }
                }
              ]
            }
          }
        ]
      }
    ]
  }'

การย้ายข้อมูลจาก Gemini 2.5

Gemini 3 เป็นตระกูลโมเดลที่มากความสามารถที่สุดของเราในปัจจุบัน และมีการปรับปรุงทีละขั้นเมื่อเทียบกับ Gemini 2.5 เมื่อย้ายข้อมูล ให้พิจารณาสิ่งต่อไปนี้

  • การคิด: หากก่อนหน้านี้คุณใช้การออกแบบพรอมต์ที่ซับซ้อน (เช่น Chain of Thought) เพื่อบังคับให้ Gemini 2.5 ให้เหตุผล ให้ลองใช้ Gemini 3 กับ thinking_level: "high" และพรอมต์ที่เรียบง่าย
  • การตั้งค่าอุณหภูมิ: หากโค้ดที่มีอยู่ตั้งค่าอุณหภูมิอย่างชัดเจน (โดยเฉพาะค่าต่ำสำหรับเอาต์พุตที่แน่นอน) เราขอแนะนำให้นำพารามิเตอร์นี้ออกและใช้ค่าเริ่มต้นของ Gemini 3 ซึ่งคือ 1.0 เพื่อหลีกเลี่ยงปัญหาการวนซ้ำที่อาจเกิดขึ้นหรือประสิทธิภาพลดลงในงานที่ซับซ้อน
  • การทำความเข้าใจ PDF และเอกสาร: ความละเอียด OCR เริ่มต้นสำหรับ PDF มีการเปลี่ยนแปลง หากคุณอาศัยลักษณะการทำงานที่เฉพาะเจาะจงสำหรับการแยกวิเคราะห์เอกสารที่มีข้อมูลหนาแน่น ให้ทดสอบmedia_resolution_highการตั้งค่าใหม่เพื่อให้มั่นใจว่าข้อมูลจะยังคงถูกต้องต่อไป
  • การใช้โทเค็น: การย้ายข้อมูลไปใช้ค่าเริ่มต้นของ Gemini 3 อาจเพิ่มการใช้โทเค็นสำหรับ PDF แต่ลดการใช้โทเค็นสำหรับวิดีโอ หากคำขอเกินกรอบหน้าต่างบริบทเนื่องจากความละเอียดเริ่มต้นสูงขึ้น เราขอแนะนำให้ลดความละเอียดของสื่ออย่างชัดเจน
  • การแบ่งกลุ่มรูปภาพ: Gemini 3 Pro หรือ Gemini 3 Flash ไม่รองรับความสามารถในการแบ่งกลุ่มรูปภาพ (การแสดงผลมาสก์ระดับพิกเซลสำหรับออบเจ็กต์) สำหรับภาระงานที่ต้องใช้การแบ่งกลุ่มรูปภาพดั้งเดิม เราขอแนะนำให้ใช้ Gemini 2.5 Flash ต่อไปโดยปิดการคิด หรือใช้ Gemini Robotics-ER 1.5
  • การรองรับเครื่องมือ: โมเดล Gemini 3 ยังไม่รองรับเครื่องมือการอ้างอิงจาก Maps และเครื่องมือการใช้งานคอมพิวเตอร์ จึงจะไม่ย้ายข้อมูล นอกจากนี้ ระบบยังไม่รองรับการรวมเครื่องมือในตัวเข้ากับการเรียกใช้ฟังก์ชัน

ความเข้ากันได้กับ OpenAI

สำหรับผู้ใช้ที่ใช้เลเยอร์ความเข้ากันได้ของ OpenAI ระบบจะแมปพารามิเตอร์มาตรฐานกับพารามิเตอร์ที่เทียบเท่าใน Gemini โดยอัตโนมัติ ดังนี้

  • reasoning_effort (OAI) แมปกับ thinking_level (Gemini) โปรดทราบว่าreasoning_effortปานกลางจะเทียบเท่ากับthinking_levelสูงใน Gemini 3 Flash

แนวทางปฏิบัติแนะนำในการเขียนพรอมต์

Gemini 3 เป็นโมเดลการให้เหตุผล ซึ่งจะเปลี่ยนวิธีที่คุณควรใช้พรอมต์

  • วิธีการที่ชัดเจน: ระบุพรอมต์อินพุตอย่างกระชับ Gemini 3 ตอบสนองต่อคำสั่งที่ชัดเจนและตรงไปตรงมาได้ดีที่สุด ซึ่งอาจวิเคราะห์เทคนิคการออกแบบพรอมต์แบบละเอียดหรือซับซ้อนมากเกินไปที่ใช้กับโมเดลรุ่นเก่า
  • ความละเอียดของเอาต์พุต: โดยค่าเริ่มต้น Gemini 3 จะมีความละเอียดน้อยกว่าและชอบให้คำตอบที่ตรงประเด็นและมีประสิทธิภาพ หากกรณีการใช้งานของคุณต้องใช้บุคลิกที่สนทนาหรือ "ช่างพูด" มากขึ้น คุณต้องชี้นำโมเดลอย่างชัดเจนในพรอมต์ (เช่น "อธิบายเรื่องนี้ในฐานะผู้ช่วยที่เป็นมิตรและช่างพูด")
  • การจัดการบริบท: เมื่อทำงานกับชุดข้อมูลขนาดใหญ่ (เช่น หนังสือทั้งเล่ม ฐานโค้ด หรือวิดีโอยาว) ให้วางคำสั่งหรือคำถามที่เฉพาะเจาะจงไว้ท้ายพรอมต์หลังจากบริบทของข้อมูล ยึดตรรกะของโมเดลกับข้อมูลที่ให้ไว้โดยเริ่มคำถามด้วยวลี เช่น "จากข้อมูลด้านบน..."

ดูข้อมูลเพิ่มเติมเกี่ยวกับกลยุทธ์การออกแบบพรอมต์ได้ในคู่มือการสร้างพรอมต์

คำถามที่พบบ่อย

  1. วันที่ความรู้ล่าสุดของ Gemini 3 คือวันใด โมเดล Gemini 3 มีการตัดความรู้ในเดือนมกราคม 2025 หากต้องการข้อมูลล่าสุด โปรดใช้เครื่องมือการอ้างอิงการค้นหา

  2. ขีดจำกัดของหน้าต่างบริบทคืออะไร โมเดล Gemini 3 รองรับหน้าต่างบริบทของอินพุตขนาด 1 ล้านโทเค็นและเอาต์พุตสูงสุด 64,000 โทเค็น

  3. Gemini 3 มีแพ็กเกจฟรีไหม Gemini 3 Flash gemini-3-flash-preview มีระดับฟรีใน Gemini API คุณสามารถทดลองใช้ทั้ง Gemini 3 Pro และ Flash ได้ฟรีใน Google AI Studio แต่ปัจจุบันยังไม่มีระดับฟรีสำหรับ gemini-3-pro-preview ใน Gemini API

  4. โค้ด thinking_budget เก่าของฉันจะยังใช้งานได้ไหม ได้ เรายังคงรองรับ thinking_budget เพื่อให้ใช้กับเวอร์ชันก่อนหน้าได้ แต่ขอแนะนำให้ย้ายข้อมูลไปยัง thinking_level เพื่อให้ได้ประสิทธิภาพที่คาดการณ์ได้มากขึ้น อย่าใช้ทั้ง 2 อย่างในคำขอเดียวกัน

  5. Gemini 3 รองรับ Batch API ไหม ได้ Gemini 3 รองรับ Batch API

  6. ระบบรองรับการแคชบริบทไหม ได้ Context Caching รองรับ Gemini 3

  7. Gemini 3 รองรับเครื่องมือใดบ้าง Gemini 3 รองรับ Google Search, การค้นหาไฟล์, การเรียกใช้โค้ด และบริบท URL นอกจากนี้ยังรองรับ Function Calling มาตรฐานสำหรับเครื่องมือที่กำหนดเอง (แต่ไม่รองรับเครื่องมือในตัว) โปรดทราบว่าขณะนี้ระบบยังไม่รองรับการเชื่อมโยงกับ Google Maps และการใช้คอมพิวเตอร์

ขั้นตอนถัดไป

  • เริ่มต้นใช้งาน Gemini 3 Cookbook
  • ดูคำแนะนำเฉพาะสำหรับ Cookbook เกี่ยวกับระดับการคิดและวิธีย้ายข้อมูลจากงบประมาณการคิดไปยังระดับการคิด