网址上下文

借助网址上下文工具,您可以网址的形式向模型提供更多上下文。通过在请求中添加网址,模型将访问这些网页中的内容(只要不是限制部分中列出的网址类型),以便提供更优质的回答。

网址上下文工具适用于以下任务:

  • 提取数据:从多个网址中提取价格、名称或关键发现等特定信息。
  • 比较文档:分析多份报告、文章或 PDF,以找出差异并跟踪趋势。
  • 综合和创建内容:整合来自多个来源网址的信息,以生成准确的摘要、博文或报告。
  • 分析代码和文档:指向 GitHub 代码库或技术文档,以解释代码、生成设置说明或回答问题。

以下示例展示了如何比较来自不同网站的两份食谱。

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.6-flash",
    input=f"Compare the ingredients and cooking times from the recipes at {url1