ابزار زمینه 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) {