ابزار زمینهای نشانی وب به شما امکان میدهد زمینههای بیشتری را در قالب نشانیهای وب به مدل ارائه دهید. مدل میتواند به محتوای این نشانیهای وب دسترسی داشته باشد تا پاسخ خود را بهبود دهد و اطلاعات بیشتری ارائه دهد.
زمینه نشانی وب مزایای زیر را دارد:
استخراج داده: اطلاعات خاصی مانند قیمتها، نامها، یا یافتههای کلیدی را از یک مقاله یا چند نشانی وب ارائه دهید.
مقایسه اطلاعات: چندین گزارش، مقاله، یا PDF را تجزیهوتحلیل کنید تا تفاوتها را شناسایی کنید و روندها را پیگیری کنید.
ترکیب و ایجاد محتوا: اطلاعات را از چندین نشانی وب منبع ترکیب کنید تا خلاصههای دقیق، پستهای وبلاگ، گزارشها، یا پرسشهای آزمون تولید کنید.
تجزیهوتحلیل کد و محتوای فنی: نشانیهای وب مخزن GitHub یا اسناد فنی را برای توضیح کد، تولید دستورالعملهای راهاندازی، یا پاسخ به سؤالات ارائه دهید.
مطمئن شوید که هنگام استفاده از ابزار بافت نشانی وب، روالهای مطلوب و محدودیتها را مرور کنید.
مدلهای پشتیبانیشده
gemini-4-argon-
gemini-3.8-flash(و مدلهای قدیمیترgemini-3.7-flash،gemini-3.6-flash، وgemini-3.5-flash) -
gemini-3.5-flash-lite(وgemini-3.1-flash-liteقدیمیتر)
مدلهای gemini-3.1-pro-preview و Gemini 2.5 با کاربرد عمومی (که
منسوخ شدهاند) نیز از این قابلیت پشتیبانی میکنند.
زبانهای پشتیبانیشده
زبانهای پشتیبانیشده برای مدلهای Gemini را ببینید.
استفاده از ابزار بافت نشانی وب
میتوانید از ابزار بافت نشانی وب به دو روش اصلی استفاده کنید:
ترکیبشده با پایهسازی با
Google Search
فقط ابزار بافت نشانی وب
|
روی ارائهدهنده Gemini API خود کلیک کنید تا محتوا و کد مخصوص ارائهدهنده را در این صفحه مشاهده کنید. |
وقتی نمونه GenerativeModel را ایجاد میکنید، UrlContext را بهعنوان ابزار ارائه دهید.
سپس، نشانیهای وب خاصی را که میخواهید مدل به آنها دسترسی داشته باشد و آنها را تجزیهوتحلیل کند مستقیماً در پیاموارهتان ارائه دهید.
مثال زیر نشان میدهد که چگونه دو دستورالعمل را از وبسایتهای مختلف مقایسه کنید:
Swift
import FirebaseAILogic
// Initialize the Gemini Developer API backend service.
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Create a `GenerativeModel` instance with a model that supports your use case.
let model = ai.generativeModel(
modelName: "GEMINI_MODEL_NAME",
// Enable the URL context tool.
tools: [.urlContext()]
)
// Specify one or more URLs for the tool to access.
let url1 = "FIRST_RECIPE_URL"
let url2 = "SECOND_RECIPE_URL"
// Provide the URLs in the prompt sent in the request.
let prompt = "Compare the ingredients and cooking times from the recipes at \(url1) and \(url2)"
// Get and handle the model's response.
let response = try await model.generateContent(prompt)
print(response.text ?? "No text in response.")
Kotlin
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "GEMINI_MODEL_NAME",
// Enable the URL context tool.
tools = listOf(Tool.urlContext())
)
// Specify one or more URLs for the tool to access.
val url1 = "FIRST_RECIPE_URL"
val url2 = "SECOND_RECIPE_URL"
// Provide the URLs in the prompt sent in the request.
val prompt = "Compare the ingredients and cooking times from the recipes at $url1 and $url2"
// Get and handle the model's response.
val response = model.generateContent(prompt)
print(response.text)
Java
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel("GEMINI_MODEL_NAME",
null,
null,
// Enable the URL context tool.
List.of(Tool.urlContext(new UrlContext())));
// Use the GenerativeModelFutures Java compatibility layer which offers
// support for ListenableFuture and Publisher APIs
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
// Specify one or more URLs for the tool to access.
String url1 = "FIRST_RECIPE_URL";
String url2 = "SECOND_RECIPE_URL";
// Provide the URLs in the prompt sent in the request.
String prompt = "Compare the ingredients and cooking times from the recipes at " + url1 + " and " + url2 + "";
ListenableFuture response = model.generateContent(prompt);
Futures.addCallback(response, new FutureCallback() {
@Override
public void onSuccess(GenerateContentResponse result) {
String resultText = result.getText();
System.out.println(resultText);
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}, executor);
Web
import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend } from "firebase/ai";
// TODO(developer): Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
// ...
};
// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Create a `GenerativeModel` instance with a model that supports your use case.
const model = getGenerativeModel(
ai,
{
model: "GEMINI_MODEL_NAME",
// Enable the URL context tool.
tools: [{ urlContext: {} }]
}
);
// Specify one or more URLs for the tool to access.
const url1 = "FIRST_RECIPE_URL"
const url2 = "SECOND_RECIPE_URL"
// Provide the URLs in the prompt sent in the request.
const prompt = `Compare the ingredients and cooking times from the recipes at ${url1} and ${url2}`
// Get and handle the model's response.
const result = await model.generateContent(prompt);
console.log(result.response.text());
Dart
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_ai/firebase_ai.dart';
import 'firebase_options.dart';
// Initialize FirebaseApp
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
// Enable the URL context tool.
tools: [
Tool.urlContext(),
],
);
// Specify one or more URLs for the tool to access.
final url1 = "FIRST_RECIPE_URL";
final url2 = "SECOND_RECIPE_URL";
// Provide the URLs in the prompt sent in the request.
final prompt = "Compare the ingredients and cooking times from the recipes at $url1 and $url2";
// Get and handle the model's response.
final response = await model.generateContent([Content.text(prompt)]);
print(response.text);
Unity
using Firebase;
using Firebase.AI;
// Initialize the Gemini Developer API backend service.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
// Create a `GenerativeModel` instance with a model that supports your use case.
var model = ai.GetGenerativeModel(
modelName: "GEMINI_MODEL_NAME",
// Enable the URL context tool.
tools: new[] { new Tool(new UrlContext()) }
);
// Specify one or more URLs for the tool to access.
var url1 = "FIRST_RECIPE_URL";
var url2 = "SECOND_RECIPE_URL";
// Provide the URLs in the prompt sent in the request.
var prompt = $"Compare the ingredients and cooking times from the recipes at {url1} and {url2}";
// Get and handle the model's response.
var response = await model.GenerateContentAsync(prompt);
UnityEngine.Debug.Log(response.Text ?? "No text in response.");
با نحوه انتخاب مدل مناسب برای مورد استفاده و برنامه خود آشنا شوید.
زمینه نشانی وب با «زمینهسازی با Google Search » ترکیب شد
|
روی ارائهدهنده Gemini API خود کلیک کنید تا محتوا و کد مخصوص ارائهدهنده را در این صفحه مشاهده کنید. |
میتوانید هم بافت نشانی وب و هم
«پایهسازی» با
وقتی «زمینهسازی با
در اینجا چند مورد استفاده آورده شده است:
نشانی وبی را در پیامواره ارائه میدهید تا به تولید بخشی از پاسخ کمک کند. بااینحال، برای تولید پاسخ مناسب، مدل همچنان به اطلاعات بیشتری درباره موضوعات دیگر نیاز دارد، بنابراین از ابزار «پایهسازی با
Google Search » استفاده میکند.پیامواره نمونه:
Give me a three day event schedule based on YOUR_URL. Also what do I need to pack according to the weather?نشانی وبی در پیامواره ارائه نمیدهید. بنابراین، برای تولید پاسخ مناسب، مدل از ابزار «پایهگذاری با
Google Search » برای یافتن نشانیهای وب مرتبط استفاده میکند و سپس از ابزار زمینه نشانی وب برای تجزیهوتحلیل محتوای آنها استفاده میکند.پیامواره نمونه:
Recommend 3 beginner-level books to learn about the latest YOUR_SUBJECT.
مثال زیر نحوه فعال کردن و استفاده از هر دو ابزار — بافت نشانی وب و
«پشتیبانی با
Swift
import FirebaseAILogic
// Initialize the Gemini Developer API backend service.
let ai = FirebaseAI.firebaseAI(backend: .googleAI())
// Create a `GenerativeModel` instance with a model that supports your use case.
let model = ai.generativeModel(
modelName: "GEMINI_MODEL_NAME",
// Enable both the URL context tool and Google Search tool.
tools: [
.urlContext(),
.googleSearch()
]
)
// Specify one or more URLs for the tool to access.
let url = "YOUR_URL"
// Provide the URLs in the prompt sent in the request.
// If the model can't generate a response using its own knowledge or the content in the specified URL,
// then the model will use the grounding with Google Search tool.
let prompt = "Give me a three day event schedule based on \(url). Also what do I need to pack according to the weather?"
// Get and handle the model's response.
let response = try await model.generateContent(prompt)
print(response.text ?? "No text in response.")
// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result
Kotlin
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "GEMINI_MODEL_NAME",
// Enable both the URL context tool and Google Search tool.
tools = listOf(Tool.urlContext(), Tool.googleSearch())
)
// Specify one or more URLs for the tool to access.
val url = "YOUR_URL"
// Provide the URLs in the prompt sent in the request.
// If the model can't generate a response using its own knowledge or the content in the specified URL,
// then the model will use the grounding with Google Search tool.
val prompt = "Give me a three day event schedule based on $url. Also what do I need to pack according to the weather?"
// Get and handle the model's response.
val response = model.generateContent(prompt)
print(response.text)
// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result
Java
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel("GEMINI_MODEL_NAME",
null,
null,
// Enable both the URL context tool and Google Search tool.
List.of(Tool.urlContext(new UrlContext()), Tool.googleSearch(new GoogleSearch())));
// Use the GenerativeModelFutures Java compatibility layer which offers
// support for ListenableFuture and Publisher APIs
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
// Specify one or more URLs for the tool to access.
String url = "YOUR_URL";
// Provide the URLs in the prompt sent in the request.
// If the model can't generate a response using its own knowledge or the content in the specified URL,
// then the model will use the grounding with Google Search tool.
String prompt = "Give me a three day event schedule based on " + url + ". Also what do I need to pack according to the weather?";
ListenableFuture response = model.generateContent(prompt);
Futures.addCallback(response, new FutureCallback() {
@Override
public void onSuccess(GenerateContentResponse result) {
String resultText = result.getText();
System.out.println(resultText);
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}, executor);
// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result
Web
import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend } from "firebase/ai";
// TODO(developer): Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
// ...
};
// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Gemini Developer API backend service.
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Create a `GenerativeModel` instance with a model that supports your use case.
const model = getGenerativeModel(
ai,
{
model: "GEMINI_MODEL_NAME",
// Enable both the URL context tool and Google Search tool.
tools: [{ urlContext: {} }, { googleSearch: {} }],
}
);
// Specify one or more URLs for the tool to access.
const url = "YOUR_URL"
// Provide the URLs in the prompt sent in the request.
// If the model can't generate a response using its own knowledge or the content in the specified URL,
// then the model will use the grounding with Google Search tool.
const prompt = `Give me a three day event schedule based on ${url}. Also what do I need to pack according to the weather?`
// Get and handle the model's response.
const result = await model.generateContent(prompt);
console.log(result.response.text());
// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result
Dart
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_ai/firebase_ai.dart';
import 'firebase_options.dart';
// Initialize FirebaseApp.
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
// Enable both the URL context tool and Google Search tool.
tools: [
Tool.urlContext(),
Tool.googleSearch(),
],
);
// Specify one or more URLs for the tool to access.
final url = "YOUR_URL";
// Provide the URLs in the prompt sent in the request.
// If the model can't generate a response using its own knowledge or the content in the specified URL,
// then the model will use the grounding with Google Search tool.
final prompt = "Give me a three day event schedule based on $url. Also what do I need to pack according to the weather?";
final response = await model.generateContent([Content.text(prompt)]);
print(response.text);
// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result
Unity
using Firebase;
using Firebase.AI;
// Initialize the Gemini Developer API backend service.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
// Create a `GenerativeModel` instance with a model that supports your use case.
var model = ai.GetGenerativeModel(
modelName: "GEMINI_MODEL_NAME",
// Enable both the URL context tool and Google Search tool.
tools: new[] { new Tool(new GoogleSearch()), new Tool(new UrlContext()) }
);
// Specify one or more URLs for the tool to access.
var url = "YOUR_URL";
// Provide the URLs in the prompt sent in the request.
// If the model can't generate a response using its own knowledge or the content in the specified URL,
// then the model will use the grounding with Google Search tool.
var prompt = $"Give me a three day event schedule based on {url}. Also what do I need to pack according to the weather?";
// Get and handle the model's response.
var response = await model.GenerateContentAsync(prompt);
UnityEngine.Debug.Log(response.Text ?? "No text in response.");
// Make sure to comply with the "Grounding with Google Search" usage requirements,
// which includes how you use and display the grounded result
با نحوه انتخاب مدل مناسب برای مورد استفاده و برنامه خود آشنا شوید.
نحوه عملکرد ابزار زمینهای نشانی وب
ابزار زمینهای نشانی وب از فرایند بازیابی دو مرحلهای برای ایجاد تعادل بین سرعت، هزینه، و دسترسی به دادههای جدید استفاده میکند.
مرحله ۱: وقتی نشانی وب خاصی را ارائه میکنید، ابزار ابتدا تلاش میکند محتوا را از حافظه نهان نمایه داخلی واکشی کند. این فایل مثل یک حافظه نهان بسیار بهینهسازیشده است.
مرحله ۲: اگر نشانی وبی در نمایه دردسترس نباشد (برای مثال، اگر صفحه بسیار جدید باشد)، ابزار بهطور خودکار به واکشی زنده برمیگردد. این ویژگی مستقیماً به نشانی وب دسترسی پیدا میکند تا محتوای آن را بهصورت همزمان بازیابی کند.
روالهای مطلوب
نشانیهای وب خاص ارائه دهید: برای بهترین نتایج، نشانیهای وب مستقیم به محتوایی که میخواهید مدل تجزیهوتحلیل کند ارائه دهید. این مدل فقط محتوا را از نشانیهای وبی که ارائه میکنید بازیابی میکند، نه محتوای پیوندهای تودرتو.
بررسی دسترسپذیری: مطمئن شوید نشانیهای وبی که ارائه میدهید به صفحههایی که نیاز به ورود به سیستم دارند یا پشت دیوار پرداخت هستند منتهی نمیشوند.
از نشانی وب کامل استفاده کنید: نشانی وب کامل را بههمراه پروتکل ارائه دهید (برای مثال،
https://www.example.comبهجای فقطexample.com).
فهمیدن پاسخ
پاسخ مدل براساس محتوایی خواهد بود که از نشانیهای وب بازیابی کرده است.
اگر مدل محتوا را از نشانیهای وب بازیابی کرده باشد، پاسخ شامل
url_context_metadata خواهد بود. چنین پاسخی ممکن است چیزی شبیه به موارد زیر باشد
(بخشهایی از پاسخ برای اختصار حذف شده است):
{
"candidates": [
{
"content": {
"parts": [
{
"text": "... \n"
}
],
"role": "model"
},
...
"url_context_metadata":
{
"url_metadata":
[
{
"retrieved_url": "https://www.example.com",
"url_retrieval_status": "URL_RETRIEVAL_STATUS_SUCCESS"
},
{
"retrieved_url": "https://www.example.org",
"url_retrieval_status": "URL_RETRIEVAL_STATUS_SUCCESS"
},
]
}
}
]
}
بررسیهای ایمنی
سیستم بررسی تعدیل محتوا را روی نشانی وب انجام میدهد تا تأیید کند که استانداردهای ایمنی را رعایت میکند. اگر نشانی وبی که ارائه کردهاید در این بررسی رد شود،
url_retrieval_status از URL_RETRIEVAL_STATUS_UNSAFE دریافت خواهید کرد.
محدودیتها
در اینجا برخیاز محدودیتهای ابزار بافت نشانی وب آورده شده است:
ترکیب با فراخوانی تابع: از ابزار بافت نشانی وب نمیتوان در درخواستی که از فراخوانی تابع نیز استفاده میکند استفاده کرد.
محدودیت نشانی وب در هر درخواست: حداکثر تعداد نشانی وب در هر درخواست ۲۰ نشانی وب است.
حد مجاز اندازه محتوای نشانی وب: حداکثر اندازه محتوای بازیابیشده از یک نشانی وب ۳۴ مگابایت است.
تازگی: این ابزار نسخههای زنده صفحات وب را واکشی نمیکند، بنابراین ممکن است مشکلاتی در تازگی یا اطلاعات بالقوه قدیمی وجود داشته باشد.
دسترسپذیری عمومی نشانی وب: نشانیهای وب ارائهشده باید بهصورت عمومی در وب دردسترس باشند. موارد زیر پشتیبانی نمیشوند: محتوای تحت دیوار پرداخت، محتوایی که نیاز به ورود به سیستم کاربر دارد، شبکههای خصوصی، نشانیهای میزبان محلی (مانند
localhostیا127.0.0.1)، و سرویسهای تونلسازی (مانند ngrok یا pinggy).
انواع محتوای پشتیبانیشده و پشتیبانینشده
پشتیبانیشده: این ابزار میتواند محتوا را از نشانیهای وب با انواع محتوای زیر استخراج کند:
نوشتار (
text/html،application/json،text/plain،text/xml،text/css،text/javascript،text/csv،text/rtf)تصویر (
image/png،image/jpeg،image/bmp،image/webp)پیدیاف (
application/pdf)
پشتیبانی نمیشود: این ابزار از انواع محتوای زیر پشتیبانی نمیکند
ویدیوهای YouTube (بهجای آن، تحلیل ویدیوها را ببینید)
فایلهای ویدیویی و صوتی (بهجای آن، تجزیهوتحلیل ویدیو یا تجزیهوتحلیل صدا را ببینید)
فایلهای Google Workspace، مثل اسناد Google یا صفحهگستردهها
(درصورت استفاده از Agent Platform Gemini API (formerly Vertex AI)) نشانیهای وب Cloud Storage
این نوع نشانیهای وب توسط Gemini Developer API پشتیبانی نمیشوند صرفنظر از اینکه چگونه به آن دسترسی پیدا میکنید.محتوایی که بهطور عمومی قابلدسترسی نیست. موارد زیر پشتیبانی نمیشوند: محتوای تحت دیوار پرداخت، محتوایی که به ورود به سیستم کاربر نیاز دارد، شبکههای خصوصی، نشانیهای میزبان محلی (مثل
localhostیا127.0.0.1)، و سرویسهای تونلزنی (مثل ngrok یا pinggy).
قیمتگذاری و شمارش کردن کدهای ابزار
محتوای بازیابیشده از نشانیهای وب بهعنوان نشانههای ورودی محسوب میشود.
میتوانید تعداد نشانههای پیامواره و استفاده از ابزارها را در
usage_metadata شیء برونداد مدل ببینید. برونداد نمونه در زیر آمده است:
'usage_metadata': {
'candidates_token_count': 45,
'prompt_token_count': 27,
'prompt_tokens_details': [{'modality': <MediaModality.TEXT: 'TEXT'>,
'token_count': 27}],
'thoughts_token_count': 31,
'tool_use_prompt_token_count': 10309,
'tool_use_prompt_tokens_details': [{'modality': <MediaModality.TEXT: 'TEXT'>,
'token_count': 10309}],
'total_token_count': 10412
}
حد نرخ و قیمتگذاری براساس مدل استفادهشده است. درباره قیمتگذاری برای ابزار زمینهای نشانی وب در اسناد ارائهدهنده انتخابی Gemini API بیشتر بدانید: Gemini Developer API | Agent Platform Gemini API (formerly Vertex AI).