Konteksti i URL-së

Vegla e kontekstit të URL-së të lejon që t'u japësh kontekst shtesë modeleve në formën e URL-ve. Duke përfshirë URL-të në kërkesën tënde, modeli do të ketë qasje te përmbajtjet nga ato faqe (për aq kohë sa nuk është një lloj URL-je i listuar në seksionin e kufizimeve) për të informuar dhe përmirësuar përgjigjen e tij.

Vegla e kontekstit me URL është e dobishme për detyra si më poshtë:

  • Nxirr të dhënat: Nxirr informacione specifike si çmimet, emrat ose gjetjet kryesore nga disa URL.
  • Krahaso dokumentet: Analizo disa raporte, artikuj ose skedarë PDF për të identifikuar ndryshimet dhe për të monitoruar tendencat.
  • Sintetizo dhe krijo përmbajtje: Kombino informacione nga disa URL burimesh për të gjeneruar përmbledhje, postime në blog ose raporte të sakta.
  • Analizo kodin dhe dokumentet: Drejtohu te një depo e GitHub ose dokumentacion teknik për të shpjeguar kodin, për të gjeneruar udhëzime konfigurimi ose për t'iu përgjigjur pyetjeve.

Shembulli i mëposhtëm tregon se si të krahasosh dy receta nga uebsajte të ndryshme.

Python

# 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.8-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}")

JavaScript

// 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.8-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();

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    url1 := "https://www.foodnetwork.com/recipes/ina-garten/perfect-roast-chicken-recipe-1940592"
    url2 := "https://www.allrecipes.com/recipe/21151/simple-whole-roast-chicken/"

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.8-flash"),
            Input: interactions.NewInteractionsInput(
                fmt.Sprintf("Compare the ingredients and cooking times from the recipes at %s and %s", url1, url2),
            ),
            Tools: []interactions.Tool{
                interactions.NewTool(interactions.URLContext{}),
            },
        }),
    })
    if err != nil {
        log.Fatal(err)
    }

    // Print the model's text response and its source annotations
    for _, step := range res.Interaction.Steps {
        if step.ModelOutputStep != nil {
            for _, contentBlock := range step.ModelOutputStep.Content {
                if contentBlock.TextContent != nil {
                    fmt.Println(contentBlock.TextContent.Text)
                    if len(contentBlock.TextContent.Annotations) > 0 {
                        fmt.Println("\nSources:")
                        for _, annotation := range contentBlock.TextContent.Annotations {
                            if annotation.URLCitation != nil {
                                fmt.Printf("  - %s: %s\n", annotation.URLCitation.GetTitle(), annotation.URLCitation.GetURL())
                            }
                        }
                    }
                }
            }
        }
    }
}

REST

# 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.8-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"}]
  }'

Si funksionon

Vegla "Konteksti i URL-së" përdor një proces marrjeje në dy hapa për të balancuar shpejtësinë, koston dhe qasjen në të dhëna të reja. Kur jep një URL, veglat në fillim përpiqen të marrin përmbajtjen nga një memorie e brendshme specifike e indeksit. Kjo vepron si një kesh i optimizuar në nivel të lartë. Nëse një URL nuk ofrohet në indeks (për shembull, nëse është një faqe shumë e re), vegla kalon automatikisht te marrja e drejtpërdrejtë. Kjo qaset drejtpërdrejt në URL për të marrë përmbajtjen e saj në kohë reale.

Mund ta kombinosh veglën e kontekstit me URL me vegla të tjera për të krijuar flukse pune më të fuqishme.

Modelet Gemini 3 mbështesin kombinimin e veglave të integruara (si p.sh. "Konteksti me URL") me veglat e personalizuara (thirrja e funksionit). Mëso më shumë në faqen e kombinimeve të veglave.

Kur konteksti me URL dhe Argumentimi me "Kërko në Google" janë të aktivizuar, modeli mund të përdorë aftësitë e tij të kërkimit për të gjetur informacione të përshtatshme online dhe më pas të përdorë veglën e kontekstit me URL për të marrë një kuptim më të thellë të faqeve që gjen. Kjo qasje është e fuqishme për kërkesat që kërkojnë kërkim të gjerë dhe analizë të thellë të faqeve specifike.

Python

# 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.8-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)

JavaScript

// 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.8-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();

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.8-flash"),
            Input: interactions.NewInteractionsInput("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: []interactions.Tool{
                interactions.NewTool(interactions.URLContext{}),
                interactions.NewTool(interactions.GoogleSearch{}),
            },
        }),
    })
    if err != nil {
        log.Fatal(err)
    }

    for _, step := range res.Interaction.Steps {
        if step.ModelOutputStep != nil {
            for _, contentBlock := range step.ModelOutputStep.Content {
                if contentBlock.TextContent != nil {
                    fmt.Println(contentBlock.TextContent.Text)
                }
            }
        }
    }
}

REST

# 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.8-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"}
      ]
  }'

Po kupton përgjigjen

Kur modeli përdor veglën e kontekstit të URL-së, përgjigjja e tij me tekst përfshin shënime të integruara të url_citation në bllokun e përmbajtjes me tekst. Çdo shënim lidh një segment të tekstit të përgjigjes (nëpërmjet start_index dhe end_index) me URL-në e burimit nga i cili është nxjerrë. Kjo është mënyra kryesore për të shfaqur citimet në aplikacionin tënd — shiko shembullin kryesor më sipër për mënyrën se si t'i nxjerrësh ato.

Përgjigjja përfshin gjithashtu një hap url_context_result me metadata për çdo përpjekje për marrjen e URL-së (statusi, URL-ja e marrë). Kjo është e dobishme kryesisht për korrigjimin e gabimeve.

Kontrollet e sigurisë

Sistemi kryen një kontroll të moderimit të përmbajtjes në URL-të për të konfirmuar që ato plotësojnë standardet e sigurisë. Nëse një URL dështon në këtë kontroll, hapi përkatës i url_context_result do të shfaqë një status të "unsafe".

Numri i tokenëve

Përmbajtja e marrë nga URL-të që specifikon në kërkesën tënde numërohet si pjesë e kodeve hyrëse. Mund ta shikosh numrin e tokenëve tek objekti usage i ndërveprimit. Më poshtë është një shembull:

'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
}

Çmimi për kod varet nga modeli i përdorur. Shiko faqen e çmimeve për detaje.

Modelet e mbështetura

Modeli Konteksti i URL-së
Gemini 4 Argon ✔️
Gemini 3.8 Flash ✔️
Gemini 3.6 Flash ✔️
Gemini 3.5 Flash-Lite ✔️
Gemini 3.1 Pro Preview ✔️
Gemini 3.1 Flash-Lite ✔️
Gemini 3 Flash Preview ✔️
Gemini 2.5 Pro ✔️
Gemini 2.5 Flash ✔️
Gemini 2.5 Flash-Lite ✔️

Praktikat më të mira

  • Jep URL specifike: Për rezultatet më të mira, jep URL të drejtpërdrejta për te përmbajtjet që dëshiron që të analizohen nga modeli. Modeli do të tërheqë përmbajtje vetëm nga URL-të që jep ti, jo përmbajtje nga lidhjet e ndërthurura.
  • Kontrollo për qasshmërinë: Verifiko që URL-të që jep nuk të çojnë në faqe që kërkojnë identifikim ose që janë pas një muri pagese.
  • Përdor URL-në e plotë: Jep URL-në e plotë, duke përfshirë protokollin (p.sh. https://www.google.com në vend të thjesht google.com).

Kufizimet

  • Kufiri i kërkesës: Vegla mund të përpunojë deri në 20 URL për kërkesë.
  • Madhësia e përmbajtjes së URL-së: Madhësia maksimale për përmbajtjen e marrë nga një URL e vetme është 34 MB.
  • Qasshmëria publike: URL-të duhet të jenë të qasshme publikisht në ueb. Adresat e pritësit lokal (p.sh. localhost, 127.0.0.1), rrjetet private dhe shërbimet e tunelimit (p.sh. ngrok, pinggy) nuk mbështeten.

Llojet e mbështetura dhe të pambështetura të përmbajtjes

Vegla mund të nxjerrë përmbajtje nga URL-të me llojet e mëposhtme të përmbajtjeve:

  • Tekst (text/html, application/json, text/plain, text/xml, text/css, text/javascript , text/csv, text/rtf)
  • Imazh (image/png, image/jpeg, image/bmp, image/webp)
  • PDF (application/pdf)

Llojet e mëposhtme të përmbajtjes nuk mbështeten:

  • Përmbajtje me mur pagese
  • Videot në YouTube (Shiko kuptimin e videos për të mësuar se si të përpunosh URL-të e YouTube)
  • Skedarët e Google Workspace, si p.sh. "Dokumentet" ose "Fletëllogaritëset e Google"
  • Skedarët e videos dhe audios