测试Tavily include_raw_content 功能

内容分享1个月前发布
0 0 0

Tavily Search – Tavily Docs

下面的参数说明 include_raw_content 设置为True, raw_content 可以

include_raw_content

booleanenum<string>

default:false

Include the cleaned and parsed HTML content of each search result. markdown or true returns search result content in markdown format. text returns the plain text from the results and may increase latency.

content

string

A short description of the search result.

Example:

“Lionel Messi, an Argentine footballer, is widely regarded as one of the greatest football players of his generation. Born in 1987, Messi spent the majority of his career playing for Barcelona, where he won numerous domestic league titles and UEFA Champions League titles. Messi is known for his exceptional dribbling skills, vision, and goal”

raw_content

string

The cleaned and parsed HTML content of the search result. Only if include_raw_content is true.

Example:

null

[结果 2] URL:
https://blog.csdn.net/zhangzhentiyes/article/details/148715211

[raw_content 为空或未返回]

[结果 5] URL:
https://www.deloitte.com/cn/zh/Industries/technology/perspectives/tech-trends-2025.html

[raw_content 为空或未返回]

import requests

# === 配置 ===
TAVILY_API_KEY = "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"
DASHSCOPE_API_KEY = "sk-367bf249444e43338a7578e07ffd8100"
SEARCH_QUERY = "最新的人工智能技术进展"

# === Step 1: Tavily Search API ===
tavily_url = "https://api.tavily.com/search"
tavily_headers = {
    "Authorization": f"Bearer {TAVILY_API_KEY}",
    "Content-Type": "application/json"
}
tavily_payload = {
    "query": SEARCH_QUERY,
    "include_raw_content": True,
    "max_results": 5
}

tavily_response = requests.post(tavily_url, json=tavily_payload, headers=tavily_headers)
tavily_data = tavily_response.json()

# === Step 2: 提取 raw_content 并打印验证 ===
results = tavily_data.get("results", [])
raw_contents = []

print("=== Tavily 返回的搜索结果(含 URL 和 raw_content) ===")
for i, result in enumerate(results, 1):
    url = result.get("url", "无URL")
    raw = result.get("raw_content")
    print(f"
[结果 {i}] URL: {url}")
    if raw:
        print(f"[raw_content 前5000字]:
{raw[:500]}...
")
        raw_contents.append(raw)
    else:
        print("[raw_content 为空或未返回]
")

combined_content = "

".join(raw_contents)

# === Step 3: DashScope Qwen 问答 ===
dashscope_url = "https://dashscope.aliyuncs.com/compatible-mode/v1"
dashscope_headers = {
    "Authorization": f"Bearer {DASHSCOPE_API_KEY}",
    "Content-Type": "application/json"
}
dashscope_payload = {
    "model": "qwen-plus",
    "input": {
        "prompt": f"请根据以下网页内容回答:{SEARCH_QUERY}

{combined_content}"
    },
    "parameters": {
        "temperature": 0.7,
        "top_p": 0.9
    }
}

dashscope_response = requests.post(dashscope_url, json=dashscope_payload, headers=dashscope_headers)
dashscope_data = dashscope_response.json()

# === Step 4: 输出 Qwen 回答 ===
print("
=== Qwen 模型的回答 ===")
print(dashscope_data.get("output", {}).get("text", "未获取到回答"))

C:UsersshiqiPycharmProjectspythonProject2.venvScriptspython.exe C:UsersshiqiPycharmProjectspythonProject2 est_tavily_search.py

=== Tavily 返回的搜索结果(含 URL 和 raw_content) ===

[结果 1] URL:
https://m.leiphone.com/category/ai

[raw_content 前5000字]:

* [对话加拿大工程院于非院士:寻找 AI 领域的「香农定理」](
/banner/homepageUrl/id/3100)

* [独家 | 创新工场首席科学家周明:NLP 与金融「联姻」,从经济实惠的小模型开始](
/banner/homepageUrl/id/3101)

* | |

| — |

| IEEE Fellow黄建伟:「网络经济、群体智能」跨界融合,智慧城市的新风暴 |

* | |

| — |

| 对话清华黄民烈:借用自动驾驶分级定义AI对话系统,元宇宙虚拟伴侣或位于L5 |

[全部](/category/ai)

[人工智能开发者](/category/yanxishe)

[人工智能学术](/category/academic)

* ### [连续发布两款万亿参数模型,蚂蚁 AI 来势汹汹](
https://www.leiphone.com/category/ai/L6tQCmiyhpWnqvRk.html “连续发布两款万亿参数模型,蚂蚁 AI 来势汹汹”)

大模型开源生态有了新变化。

[齐铖湧](https://www.lei…

[结果 2] URL:
https://blog.csdn.net/zhangzhentiyes/article/details/148715211

[raw_content 为空或未返回]

[结果 3] URL:
https://www.microsoft.com/en-us/research/articles/6-ai-trends-in-2025/

[raw_content 前5000字]:

[跳转至主内容](javascript:void(0))

[Microsoft](https://www.microsoft.com)

[微软研究院](/en-us/research/?locale=zh_CN)

## 微软亚洲研究院

# 2025年六大AI趋势展望

已发布 | 更新

分享这个页面

* [分享到Facebook](
https://www.facebook.com/sharer/sharer.php?u=
https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fresearch%2Farticles%2F6-ai-trends-in-2025%2F%3Flocale%3Dzh-cn “分享到Facebook”)

* [分享到 X](

https://x.com/intent/tweet?text=2025%E5%B9%B4%E5%85%AD%E5%A4%A7AI%E8%B6%8B%E5%8A%BF%E5%B1%95%E6%9C%9B&url=https%3A%2F%2Fwww.microsoft.com%2Fen-us…

[结果 4] URL:
https://www.mckinsey.com.cn/%E9%BA%A6%E8%82%AF%E9%94%A1%E5%85%A8%E7%90%83%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD%E6%9C%80%E6%96%B0%E8%B0%83%E7%A0%94%EF%BC%9Aai%E5%9C%A8%E4%B8%AD%E5%9B%BD%E4%BC%81%E4%B8%9A%E7%9A%84%E8%90%BD%E5%9C%B0/

[raw_content 前5000字]:

[Skip to content](#content “Skip to content”)

自20世纪50年代概念提出后 ,人工智能(AI)已在各行各业得到普及应用,为人类社会带来了巨大机遇,创造了难以估量的价值。从2017年起,麦肯锡已连续5年开展全球人工智能调研,从数据、算法应用、投资回报、人才培养与可持续发展等角度切入,研究分析全球范围内企业在AI领域的应用情况。

我们的最新调研显示,近5年全球范围内企业的AI使用率大幅提升,2022年有50%的公司部署了AI,远高于2017年的20%。对AI的资本投入也随使用率的提升而大幅增长。5年前约有40%的公司对AI投入了超过5%的总预算,而2022年已有超过一半的公司有此投入比例。可以说,各行各业对于AI的重点关注程度与日俱增。

若将目光投向中国,我们预计到2030年,人工智能将为中国一些关键产业带来巨大的增长机会,尤其在如汽车、交通运输和物流;制造业;医疗保健和生命科学;企业软件等创新和研发支出向来落后于全球同行的行业。在这些行业,一系列人工智能用例每年可创造超过6000亿美元的经济价值。(具体可参阅我们于2022年7月发布的报告…

[结果 5] URL:
https://www.deloitte.com/cn/zh/Industries/technology/perspectives/tech-trends-2025.html

[raw_content 为空或未返回]

Traceback (most recent call last):

File “C:UsersshiqiPycharmProjectspythonProject2.venvLibsite-packages
equestsmodels.py”, line 976, in json

return complexjson.loads(self.text, **kwargs)

~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^

File “C:UsersshiqiAppDataLocalProgramsPythonPython313Libjson\__init__.py”, line 346, in loads

return _default_decoder.decode(s)

~~~~~~~~~~~~~~~~~~~~~~~^^^

File “C:UsersshiqiAppDataLocalProgramsPythonPython313Libjsondecoder.py”, line 344, in decode

obj, end = self.raw_decode(s, idx=_w(s, 0).end())

~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^

File “C:UsersshiqiAppDataLocalProgramsPythonPython313Libjsondecoder.py”, line 362, in raw_decode

raise JSONDecodeError(“Expecting value”, s, err.value) from None

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File “C:UsersshiqiPycharmProjectspythonProject2 est_tavily_search.py”, line 58, in <module>

dashscope_data = dashscope_response.json()

File “C:UsersshiqiPycharmProjectspythonProject2.venvLibsite-packages
equestsmodels.py”, line 980, in json

raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

进程已结束,退出代码为 1

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
none
暂无评论...