ابزار زمینه URL به شما امکان میدهد زمینههای اضافی را در قالب URLها به مدلها ارائه دهید. با گنجاندن URLها در درخواست خود، مدل به محتوای آن صفحات (تا زمانی که نوع URL ذکر شده در بخش محدودیتها نباشد) دسترسی پیدا میکند تا پاسخ خود را آگاه و بهبود بخشد.
ابزار URL context برای کارهایی مانند موارد زیر مفید است:
- استخراج دادهها : اطلاعات خاص مانند قیمتها، نامها یا یافتههای کلیدی را از چندین URL استخراج کنید.
- مقایسه اسناد : چندین گزارش، مقاله یا PDF را تجزیه و تحلیل کنید تا تفاوتها را شناسایی کرده و روندها را پیگیری کنید.
- ترکیب و ایجاد محتوا : اطلاعات را از چندین آدرس اینترنتی منبع ترکیب کنید تا خلاصهها، پستهای وبلاگ یا گزارشهای دقیقی تولید کنید.
- تحلیل کد و مستندات : برای توضیح کد، ایجاد دستورالعملهای راهاندازی یا پاسخ به سوالات، به یک مخزن گیتهاب یا مستندات فنی اشاره کنید.
مثال زیر نحوه مقایسه دو دستور غذا از وبسایتهای مختلف را نشان میدهد.
پایتون
# This will only work for SDK newer than 2.0.0
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.7-flash",
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}")
جاوا اسکریپت
// This will only work for SDK newer than 2.0.0
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const interaction = await client.interactions.create({
model: "gemini-3.7-flash",
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();
استراحت
# Specifies the API revision to avoid breaking changes when they become default
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.7-flash",
"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 Context از یک فرآیند بازیابی دو مرحلهای برای ایجاد تعادل بین سرعت، هزینه و دسترسی به دادههای تازه استفاده میکند. وقتی یک URL ارائه میدهید، این ابزار ابتدا تلاش میکند تا محتوا را از یک حافظه پنهان داخلی دریافت کند. این به عنوان یک حافظه پنهان بسیار بهینه عمل میکند. اگر یک URL در فهرست موجود نباشد (به عنوان مثال، اگر یک صفحه بسیار جدید باشد)، ابزار به طور خودکار برای انجام یک واکشی زنده به عقب برمیگردد. این کار مستقیماً به URL دسترسی پیدا میکند تا محتوای آن را به صورت بلادرنگ بازیابی کند.
ترکیب با ابزارهای دیگر
شما میتوانید ابزار URL context را با ابزارهای دیگر ترکیب کنید تا گردشهای کاری قدرتمندتری ایجاد کنید.
مدلهای Gemini 3 از ترکیب ابزارهای داخلی (مانند URL Context) با ابزارهای سفارشی (فراخوانی تابع) پشتیبانی میکنند. برای کسب اطلاعات بیشتر به صفحه ترکیب ابزارها مراجعه کنید.
اتصال به زمین با جستجو
وقتی هر دو قابلیت زمینه URL و زمینهیابی با جستجوی گوگل فعال باشند، مدل میتواند از قابلیتهای جستجوی خود برای یافتن اطلاعات مرتبط آنلاین استفاده کند و سپس از ابزار زمینه URL برای درک عمیقتر صفحاتی که پیدا میکند، استفاده کند. این رویکرد برای درخواستهایی که نیاز به جستجوی گسترده و تحلیل عمیق صفحات خاص دارند، قدرتمند است.
پایتون
# This will only work for SDK newer than 2.0.0
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.7-flash",
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)
جاوا اسکریپت
// This will only work for SDK newer than 2.0.0
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
async function main() {
const interaction = await client.interactions.create({
model: "gemini-3.7-flash",
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();
استراحت
# Specifies the API revision to avoid breaking changes when they become default
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{