ابزار بافت نشانی وب به شما امکان میدهد بافت اضافی را در قالب نشانیهای وب به مدل ارائه دهید. مدل میتواند به محتوای آن نشانیهای وب دسترسی داشته باشد تا پاسخ خود را بهبود بخشد و اطلاعات بیشتری ارائه دهد.
بافت نشانی وب مزایای زیر را دارد:
استخراج داده: اطلاعات خاصی مانند قیمتها، نامها، یا یافتههای کلیدی را از یک مقاله یا چند نشانی وب ارائه دهید.
مقایسه اطلاعات: چندین گزارش، مقاله، یا فایل 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)PDF (
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).