บริบท URL
เครื่องมือบริบท URL ช่วยให้คุณระบุบริบทเพิ่มเติมให้กับโมเดลในรูปแบบของ URL ได้ การใส่ URL ในคำขอจะช่วยให้โมเดลเข้าถึงเนื้อหาจากหน้าเหล่านั้นได้ (ตราบใดที่ URL ไม่ใช่ประเภทที่ระบุไว้ในส่วนข้อจำกัด) เพื่อให้ข้อมูลและปรับปรุงคำตอบ
เครื่องมือบริบท URL มีประโยชน์สำหรับงานต่างๆ เช่น
- ดึงข้อมูล: ดึงข้อมูลที่เฉพาะเจาะจง เช่น ราคา ชื่อ หรือข้อค้นพบที่สำคัญ จาก URL หลายรายการ
- เปรียบเทียบเอกสาร: วิเคราะห์รายงาน บทความ หรือ PDF หลายรายการเพื่อ ระบุความแตกต่างและติดตามเทรนด์
- สังเคราะห์และสร้างเนื้อหา: รวมข้อมูลจาก URL แหล่งที่มาหลายรายการเพื่อสร้างข้อมูลสรุป บล็อกโพสต์ หรือรายงานที่ถูกต้อง
- วิเคราะห์โค้ดและเอกสาร: ชี้ไปยังที่เก็บ GitHub หรือเอกสารทางเทคนิค เพื่ออธิบายโค้ด สร้างวิธีการตั้งค่า หรือตอบคำถาม
ตัวอย่างต่อไปนี้แสดงวิธีเปรียบเทียบสูตรอาหาร 2 สูตรจากเว็บไซต์ต่างๆ
Python
from google import genai
client = genai.Client()
url1 = "https://www.foodnetwork.com/recipes/ina-garten/perfect-roast-chicken-recipe-1940592"
url2 = "https://www.allrecipes.com/recipe/21151/simple-whole-roast-chicken/"
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input=f"Compare the ingredients and cooking times from the recipes at {url1} and {url2}",
tools=[{"type": "url_context"}]
)
# Print the model's text response and its source annotations
for step in interaction.steps:
if step.type == "model_output":
for content_block in step.content:
if content_block.type == "text":
print(content_block.text)
if content_block.annotations:
print("\nSources:")
for annotation in content_block.annotations:
if annotation.type == "url_citation":
print(f" - {annotation.title}: {annotation.url}")
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: "Compare the ingredients and cooking times from the recipes at https://www.foodnetwork.com/recipes/ina-garten/perfect-roast-chicken-recipe-1940592 and https://www.allrecipes.com/recipe/21151/simple-whole-roast-chicken/",
tools: [{ type: "url_context" }]
});
// Print the model's text response and its source annotations
for (const step of interaction.steps) {
if (step.type === 'model_output') {
for (const contentBlock of step.content) {
if (contentBlock.type === 'text') {
console.log(contentBlock.text);
if (contentBlock.annotations) {
console.log("\nSources:");
for (const annotation of contentBlock.annotations) {
if (annotation.type === 'url_citation') {
console.log(` - ${annotation.title}: ${annotation.url}`);
}
}
}
}
}
}
}
}
await main();
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3-flash-preview",
"input": "Compare the ingredients and cooking times from the recipes at https://www.foodnetwork.com/recipes/ina-garten/perfect-roast-chicken-recipe-1940592 and https://www.allrecipes.com/recipe/21151/simple-whole-roast-chicken/",
"tools": [{"type": "url_context"}]
}'
วิธีการทำงาน
เครื่องมือบริบท URL ใช้กระบวนการดึงข้อมูล 2 ขั้นตอนเพื่อ รักษาสมดุลระหว่างความเร็ว ต้นทุน และการเข้าถึงข้อมูลล่าสุด เมื่อคุณระบุ URL เครื่องมือจะ พยายามดึงข้อมูลเนื้อหาจากแคชดัชนีภายในก่อน ซึ่งทำหน้าที่เป็นแคชที่ได้รับการเพิ่มประสิทธิภาพสูง หาก URL ไม่พร้อมใช้งานในดัชนี (เช่น หากเป็นหน้าเว็บใหม่มาก) เครื่องมือจะกลับไปใช้การดึงข้อมูลเวอร์ชันที่ใช้จริงโดยอัตโนมัติ ซึ่งจะเข้าถึง URL โดยตรงเพื่อดึงเนื้อหาแบบเรียลไทม์
การใช้ร่วมกับเครื่องมืออื่นๆ
คุณสามารถใช้เครื่องมือบริบท URL ร่วมกับเครื่องมืออื่นๆ เพื่อสร้างเวิร์กโฟลว์ที่มีประสิทธิภาพมากขึ้น
โมเดล Gemini 3 รองรับการรวมเครื่องมือในตัว (เช่น บริบท URL) กับเครื่องมือที่กำหนดเอง (การเรียกใช้ฟังก์ชัน) ดูข้อมูลเพิ่มเติมได้ที่หน้าชุดเครื่องมือ
การเชื่อมต่อแหล่งข้อมูลกับ Search
เมื่อเปิดใช้ทั้งบริบท URL และการเชื่อมต่อแหล่งข้อมูลกับ Google Search โมเดลจะใช้ความสามารถในการค้นหาเพื่อค้นหาข้อมูลที่เกี่ยวข้องทางออนไลน์ แล้วใช้เครื่องมือบริบท URL เพื่อทำความเข้าใจหน้าเว็บที่พบในเชิงลึกมากขึ้นได้ วิธีนี้มีประสิทธิภาพสำหรับ พรอมต์ที่ต้องใช้ทั้งการค้นหาแบบกว้างและการวิเคราะห์หน้าเว็บที่เฉพาะเจาะจงอย่างละเอียด
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="Give me three day events schedule based on YOUR_URL. Also let me know what needs to taken care of considering weather and commute.",
tools=[
{"type": "url_context"},
{"type": "google_search"}
]
)
for step in interaction.steps:
if step.type == "model_output":
for content_block in step.content:
if content_block.type == "text":
print(content_block.text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: "Give me three day events schedule based on YOUR_URL. Also let me know what needs to taken care of considering weather and commute.",
tools: [
{ type: "url_context" },
{ type: "google_search" }
]
});
for (const step of interaction.steps) {
if (step.type === 'model_output') {
for (const contentBlock of step.content) {
if (contentBlock.type === 'text') console.log(contentBlock.text);
}
}
}
}
await main();
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3-flash-preview",
"input": "Give me three day events schedule based on YOUR_URL. Also let me know what needs to taken care of considering weather and commute.",
"tools": [
{"type": "url_context"},
{"type": "google_search"}
]
}'
ทำความเข้าใจคำตอบ
เมื่อโมเดลใช้เครื่องมือบริบท URL ข้อความตอบกลับจะมี
url_citationคำอธิบายประกอบในบล็อกเนื้อหาข้อความ คำอธิบายประกอบแต่ละรายการจะลิงก์
ส่วนของข้อความตอบกลับ (ผ่าน start_index และ end_index) กับแหล่งที่มา
URL ที่ได้มาจากแหล่งที่มานั้น นี่คือวิธีหลักในการแสดงการอ้างอิงในแอปพลิเคชันของคุณ ดูตัวอย่างหลักด้านบนเพื่อดูวิธีแยกการอ้างอิง
การตอบกลับจะมีขั้นตอน url_context_result พร้อมข้อมูลเมตาเกี่ยวกับการพยายามดึงข้อมูล URL แต่ละรายการ (สถานะ, URL ที่ดึงข้อมูล) ซึ่งส่วนใหญ่จะมีประโยชน์สำหรับการ
แก้ไขข้อบกพร่อง
การตรวจสอบความปลอดภัย
ระบบจะตรวจสอบการกลั่นกรองเนื้อหาใน URL เพื่อยืนยันว่า URL เป็นไปตามมาตรฐานความปลอดภัย
หาก URL ไม่ผ่านการตรวจสอบนี้ url_context_resultขั้นตอนที่เกี่ยวข้องจะแสดง status เป็น "unsafe"
จำนวนโทเค็น
ระบบจะนับเนื้อหาที่ดึงมาจาก URL ที่คุณระบุในพรอมต์เป็นส่วนหนึ่งของโทเค็นอินพุต
คุณดูจำนวนโทเค็นได้ในusageออบเจ็กต์ของการโต้ตอบ ตัวอย่างเช่น
'usage': {
'output_tokens': 45,
'input_tokens': 27,
'input_tokens_details': [{'modality': 'TEXT', 'token_count': 27}],
'thoughts_tokens': 31,
'tool_use_input_tokens': 10309,
'tool_use_input_tokens_details': [{'modality': 'TEXT', 'token_count': 10309}],
'total_tokens': 10412
}
ราคาต่อโทเค็นจะขึ้นอยู่กับโมเดลที่ใช้ โปรดดูรายละเอียดในหน้าการกำหนดราคา
โมเดลที่รองรับ
| รุ่น | บริบท URL |
|---|---|
| ตัวอย่าง Gemini 3.1 Pro | ✔️ |
| Gemini 3.1 Flash-Lite | ✔️ |
| Gemini 3.1 Flash-Lite (เวอร์ชันตัวอย่าง) | ✔️ |
| ตัวอย่าง Gemini 3 Flash | ✔️ |
| Gemini 2.5 Pro | ✔️ |
| Gemini 2.5 Flash | ✔️ |
| Gemini 2.5 Flash-Lite | ✔️ |
แนวทางปฏิบัติแนะนำ
- ระบุ URL ที่เฉพาะเจาะจง: เพื่อให้ได้ผลลัพธ์ที่ดีที่สุด ให้ระบุ URL โดยตรงไปยังเนื้อหาที่คุณต้องการให้โมเดลวิเคราะห์ โมเดลจะดึงข้อมูลเนื้อหาจาก URL ที่คุณระบุเท่านั้น ไม่ใช่เนื้อหาจากลิงก์ที่ซ้อนกัน
- ตรวจสอบการช่วยเหลือพิเศษ: ตรวจสอบว่า URL ที่คุณระบุไม่ได้นำไปยังหน้าเว็บที่ต้องมีการเข้าสู่ระบบหรืออยู่หลังเพย์วอลล์
- ใช้ URL แบบเต็ม: ระบุ URL แบบเต็ม รวมถึงโปรโตคอล (เช่น https://www.google.com แทนที่จะเป็น google.com)
ข้อจำกัด
- การเรียกใช้ฟังก์ชัน: ปัจจุบันระบบไม่รองรับการใช้เครื่องมือ (บริบท URL, การเชื่อมต่อแหล่งข้อมูลกับ Google Search ฯลฯ) กับการเรียกใช้ฟังก์ชัน
- ขีดจํากัดของคําขอ: เครื่องมือนี้ประมวลผล URL ได้สูงสุด 20 รายการต่อคําขอ
- ขนาดเนื้อหา URL: ขนาดสูงสุดของเนื้อหาที่ดึงมาจาก URL เดียวคือ 34 MB
- การเข้าถึงแบบสาธารณะ: URL ต้องเข้าถึงได้แบบสาธารณะบนเว็บ ระบบไม่รองรับที่อยู่ localhost (เช่น localhost, 127.0.0.1), เครือข่ายส่วนตัว และ บริการอุโมงค์ (เช่น ngrok, pinggy)
- Gemini API เท่านั้น: บริบท URL ใช้ได้ใน Gemini API เท่านั้น ไม่ใช่ผ่าน แพลตฟอร์ม Agent ของ Gemini Enterprise
ประเภทเนื้อหาที่รองรับและไม่รองรับ
เครื่องมือนี้สามารถดึงเนื้อหาจาก URL ที่มีเนื้อหาประเภทต่อไปนี้
- ข้อความ (text/html, application/json, text/plain, text/xml, text/css, text/javascript , text/csv, text/rtf)
- รูปภาพ (image/png, image/jpeg, image/bmp, image/webp)
- PDF (application/pdf)
ระบบไม่รองรับเนื้อหาประเภทต่อไปนี้
- เนื้อหาเพย์วอลล์
- วิดีโอ YouTube (ดูการทำความเข้าใจวิดีโอเพื่อดูวิธี ประมวลผล URL ของ YouTube)
- ไฟล์ Google Workspace เช่น Google เอกสารหรือสเปรดชีต
- ไฟล์วิดีโอและเสียง