跳到主要内容

联网搜索

让答案包含实时信息(行情、新闻、天气、事实核查)。图灵平台提供两条路径,适用场景不同:

路径典型用法你写什么
路径 A:模型内置搜索一次 LLM 调用就得到"已整合搜索结果"的最终答案/chat/completions/messages 请求里加 toolsenable_search 参数
路径 B:独立搜索端点你自己控制 pipeline:先搜索、再喂给任意 LLM / RAG直接调用 /proxy/<provider>/search,拿到结果后自行拼 prompt

不确定走哪条?在需要 "模型自己决定何时搜索、且引用要自动注入回答" 的场景选 A;需要 "搜索结果要进 embedding / 做检索 / 和业务系统融合" 时选 B。


路径 A:模型内置搜索

三家厂商都走标准 /v1/chat/completions endpoint,参数差异体现在 tools / extra_body 里。完整请求体 schema 见 /api/create-chat-completion;Claude 原生协议见 Messages 接口

支持的模型

完整支持范围以模型列表中的厂商段落和 Web Search / 内置工具标记为准:

Qwen

from openai import OpenAI

client = OpenAI(
api_key="your-api-key",
base_url="https://live-turing.cn.llm.tcljd.com/api/v1"
)

response = client.chat.completions.create(
model="qwen-plus-latest",
messages=[
{"role": "user", "content": "杭州明天天气如何"}
],
# enable_search 非 OpenAI 标准参数,Python SDK 通过 extra_body 传入
extra_body={
"enable_search": True
}
)

print(response.choices[0].message.content)
curl $TURING_BASE_URL/chat/completions \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-plus-latest",
"messages": [
{"role": "user", "content": "杭州明天天气如何"}
],
"enable_search": true
}'

Gemini

Gemini 系列用 tools 参数配置 Google Search,两种搜索模式:

  • googleSearch:标准 Google 搜索
  • enterpriseWebSearch:企业级搜索,提供更安全、合规的搜索结果
from openai import OpenAI

client = OpenAI(
api_key="your-api-key",
base_url="https://live-turing.cn.llm.tcljd.com/api/v1"
)

response = client.chat.completions.create(
model="turing/gemini-3-pro-latest",
messages=[
{"role": "user", "content": "上海今天天气如何"}
],
extra_body={
"tools": [{"googleSearch": {}}]
}
)

print(response.choices[0].message.content)

切换到企业级模式只需把 googleSearch 换成 enterpriseWebSearch

extra_body={
"tools": [{"enterpriseWebSearch": {}}]
}

Claude

Claude 系列通过 tools 参数传入 Anthropic 原生的 web_search_20250305 工具类型,模型会自动判断何时检索,并把搜索结果与引用整合到回答中。

官方文档:Web search tool (Anthropic)

可选字段:

  • max_uses:单次对话最多调用搜索的次数上限
  • allowed_domains / blocked_domains:域名白/黑名单(二选一)
  • user_location:提示模型检索时结合的地理位置信息
from openai import OpenAI

client = OpenAI(
api_key="your-api-key",
base_url="https://live-turing.cn.llm.tcljd.com/api/v1"
)

response = client.chat.completions.create(
model="turing/claude-sonnet-5",
max_tokens=4096,
messages=[
{"role": "user", "content": "今日上证指数收盘价是多少?"}
],
extra_body={
"tools": [
{
"type": "web_search_20250305",
"name": "web_search",
"max_uses": 3
}
]
}
)

print(response.choices[0].message.content)

Claude 响应结构

Claude 的响应里会包含搜索调用次数和引用元数据,具体字段位置取决于所用接口。无论走哪条接口,usage.server_tool_use.web_search_requests 都会返回本次请求实际触发的搜索次数,用于计费对账。

通过 /v1/messages(Anthropic 原生接口) —— content 数组按顺序出现以下 block:

  1. server_tool_use — 模型发起的搜索请求(含 input.query
  2. web_search_tool_result — 搜索结果列表(title / url / encrypted_content / page_age
  3. text — 最终回答;引用以独立 text block 形式插入,block 上的 citations[] 数组指向对应的 web_search_result_location

示例(节选):

{
"model": "claude-sonnet-5",
"content": [
{
"type": "server_tool_use",
"id": "srvtoolu_vrtx_01FZ...",
"name": "web_search",
"input": { "query": "上证指数今日收盘价" }
},
{
"type": "web_search_tool_result",
"tool_use_id": "srvtoolu_vrtx_01FZ...",
"content": [
{
"type": "web_search_result",
"title": "上证指数 (SSEC) 实时行情…",
"url": "https://cn.investing.com/indices/shanghai-composite",
"page_age": "5 days ago"
}
]
},
{
"type": "text",
"text": "上证指数最新报价为4,051.43点",
"citations": [
{
"type": "web_search_result_location",
"cited_text": "上证指数(SSEC)最新指数报价为4,051.43…",
"url": "https://cn.investing.com/indices/shanghai-composite",
"title": "上证指数 (SSEC) 实时行情…"
}
]
}
],
"usage": {
"input_tokens": 11505,
"output_tokens": 235,
"server_tool_use": {
"web_search_requests": 1
}
}
}

通过 /chat/completions(OpenAI 兼容接口) —— 响应形态贴近 OpenAI:

  • choices[0].message.content — 模型的最终文本回答
  • choices[0].message.tool_calls — 模型实际发起的每一次 web_search 调用
  • choices[0].message.provider_specific_fields.citations — 引用数组,含 cited_text / url / title / supported_text
  • usage.server_tool_use.web_search_requests — 本次触发的搜索次数
提示

encrypted_content / encrypted_index 字段是 Anthropic 侧用于多轮对话签名校验的不透明数据,透传回下一轮请求即可,不要篡改


路径 B:独立搜索端点

平台代理了多家第三方搜索引擎,适合自定义 RAG pipeline:先拿结果,再做 embedding / rerank / 喂给任意 LLM。

Baidu(百度,仅中国区)

curl $TURING_BASE_URL/proxy/baidu/search \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"q": "帮我搜索一下今天的中证50的表现",
"count": 10
}'

响应节选:

{
"trace_id": "trace_32bHCrZm1GIXbYNyP6duD",
"code": 0,
"message": "Success",
"data": {
"requestId": "51ec6302-1aa0-4c09-b32a-d7e18c4676fc",
"references": [
{
"id": 1,
"title": "中证A50(930050)股票价格_行情_走势图…",
"url": "https://emwap.eastmoney.com/quote/stock/2.930050.html",
"website": "东方财富",
"content": "今开 最高 …",
"date": "2026-02-27 00:00:00",
"type": "web"
}
]
}
}

Tavily(全球,LLM-optimized)

请求体与响应结构完全透传 Tavily 官方协议,完整参数(search_depthtopictime_rangeinclude_domainsinclude_answerinclude_raw_content 等)请见 Tavily Search API Reference

  • 端点POST /proxy/tavily/search
  • 必填参数query
  • 常用参数max_resultssearch_depthbasic / advanced)、topicgeneral / news / finance)、time_rangeinclude_answerinclude_raw_contentinclude_domainsexclude_domains
curl $TURING_BASE_URL/proxy/tavily/search \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "latest AI developments 2024",
"max_results": 5
}'

响应节选:

{
"query": "latest AI developments 2024",
"results": [
{
"title": "2024 Global Trends in AI - WEKA",
"url": "https://www.weka.io/resources/analyst-report/2024-global-trends-in-ai/",
"content": "Discover key AI trends in 2024…",
"score": 0.7498395
}
],
"responseTime": 0.86,
"requestId": "bb84e696-88cd-4b0f-b832-0aba925d312e"
}

Cloudsway(搜索,中国区)

中国区的另一条搜索通道,适合你先拿网页结果,再自行做摘要、RAG、重排或喂给其他模型。

  • 端点GET /proxy/cloudsway/search
  • 必填参数q
  • 常用参数countfreshnessoffsetenableContentcontentTypecontentTimeoutmainTextsitesblockWebsites
  • 请求头:通常只需要 AuthorizationPragmaAccept 等头可按调用方需要自行决定是否传入
curl --location "$TURING_BASE_URL/proxy/cloudsway/search?q=%E6%97%A5%E6%9C%AC" \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Accept: */*"

参数说明:

  • q:搜索查询词,不能为空。
  • count:返回结果数量,默认 10,最大 50,可选值范围 1-50
  • freshness:按时间过滤结果,可选 Day / Week / Month
  • offset:分页偏移量,默认 0;设置过大时可能返回空结果。
  • enableContent:是否抓取网页长摘要;true 返回长摘要,false 不返回,默认 false
  • contentType:长摘要格式,仅在 enableContent=true 时生效,可选 HTML / MARKDOWN / TEXT,默认返回 TEXT
  • contentTimeout:长摘要读取超时,单位秒,默认 0,最大 10,仅在 enableContent=true 时生效。
  • mainText:是否返回与查询最相关的正文片段,仅在 enableContent=true 时生效。
  • sites:只保留指定站点结果,值需填写 host,例如 baijiahao.baidu.com
  • blockWebsites:过滤指定站点结果,值需填写 host,例如 baijiahao.baidu.com

响应字段与 Legacy Bing Proxy 基本一致,常见字段包括:

  • queryContext.originalQuery:原始查询词。
  • webPages.value[]:搜索结果数组。
  • webPages.value[].name / url / snippet:标题、链接、短摘要。
  • webPages.value[].datePublished:页面发布时间,部分结果包含。
  • webPages.value[].mainText:与查询最相关的正文片段。
  • webPages.value[].siteName:站点名称,部分结果包含。
  • webPages.value[].contentCrawled:长摘要是否抓取成功。
  • webPages.value[].content:网页长摘要正文。
  • webPages.value[].logo / imageList / score:站点图标、图片列表、内容相关性分数。
提示

如果你只需要标准搜索结果,通常只传 qcount 即可;只有在要做摘要增强或构造 RAG 上下文时,再打开 enableContent / mainText

备注

sitesblockWebsites 都要求填写 host,不要带协议头,例如填写 www.tiktok.com,不要写成 https://www.tiktok.com

Legacy Bing Proxy(自动路由 Baidu/Google)

历史接口。国内自动走 Baidu,国外自动走 Google。新项目建议直接调用上面对应的端点,以获得更稳定的返回结构。

  • 端点POST /proxy/bing/v7.0/search
  • 参数q(必填,查询字符串)、count(可选,默认 10,最大 25)
curl $TURING_BASE_URL/proxy/bing/v7.0/search \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"q": "明故宫",
"count": "10"
}'

响应字段:queryContext.originalQuerywebPages.value[](含 id / name / url / snippet / displayUrl / datePublished 等)、_type: "SearchResponse"

注意事项
  • API Key 妥善保管,不要在客户端代码中暴露。
  • 搜索结果的可用性和准确性取决于搜索引擎提供商。
  • 部分搜索结果包含第三方内容,使用时请注意版权。

See also