跳到主要内容
Naver搜索工具提供了一个简单的界面来搜索Naver并获取结果。

集成详情

类别可序列化JS 支持版本
NaverSearchResultslangchain-naver-communityPyPI - Version

工具特性

搜索:Naver搜索工具提供了一个简单的界面来搜索Naver并获取结果。

设置

设置API凭据

要使用Naver搜索,您需要获取API凭据。请遵循以下步骤: 登录Naver开发者门户。创建一个新应用程序并启用搜索API。从“应用程序列表”部分获取您的NAVER_CLIENT_IDNAVER_CLIENT_SECRET

设置环境变量

获取凭据后,将它们设置为脚本中的环境变量
pip install -qU  langchain-naver-community
import getpass
import os

if not os.environ.get("NAVER_CLIENT_ID"):
    os.environ["NAVER_CLIENT_ID"] = getpass.getpass("Enter your Naver Client ID:\n")

if not os.environ.get("NAVER_CLIENT_SECRET"):
    os.environ["NAVER_CLIENT_SECRET"] = getpass.getpass(
        "Enter your Naver Client Secret:\n"
    )

实例化

from langchain_naver_community.utils import NaverSearchAPIWrapper

search = NaverSearchAPIWrapper()

调用

search.results("Seoul")[:3]
[{'title': 'Seoul shares rise for 4th day on tech gains; won at 2-week low',
  'link': 'https://n.news.naver.com/mnews/article/001/0015277717?sid=104',
  'description': 'stocks-summary Seoul shares rise for 4th day on tech gains; won at 2-week low SEOUL, March 20 (Yonhap) -- Seoul shares extended their winning streak to a fourth day Thursday on the back of gains... ',
  'pubDate': 'Thu, 20 Mar 2025 16:09:00 +0900'},
 {'title': "Seoul Mayor Oh's residence, office raided over alleged ties to shadowy po...",
  'link': 'https://n.news.naver.com/mnews/article/640/0000067073?sid=100',
  'description': 'Prosecutors on Thursday raided Seoul Mayor Oh Se-hoon’s official residence and the City Hall... The raid came as part of the Seoul Central District Prosecutors’ Office’s probe into... ',
  'pubDate': 'Thu, 20 Mar 2025 19:12:00 +0900'},
 {'title': 'Education can heal divides: Seoul schools chief',
  'link': 'https://n.news.naver.com/mnews/article/044/0000267866?sid=104',
  'description': 'Jung Keun-sik, Superintendent of Seoul Metropolitan Office of Education speaks during an interview with The Korea Herald at his office on March 13. (Lim Se-jun/ The Korea Herald) Seoul education... ',
  'pubDate': 'Thu, 20 Mar 2025 14:35:00 +0900'}]

工具使用

from langchain_naver_community.tool import NaverSearchResults
from langchain_naver_community.utils import NaverSearchAPIWrapper

search = NaverSearchAPIWrapper()

tool = NaverSearchResults(api_wrapper=search)

tool.invoke("what is the weather in seoul?")[3:5]
[{'title': "2025 is here. Here's what to watch out for",
  'link': 'https://n.news.naver.com/mnews/article/044/0000265707?sid=104',
  'description': 'The trend was predicted in "Trend Korea 2025," written by Kim Ran-do, a professor of consumer science at Seoul National University, and his team. The annually published book also predicts that... ',
  'pubDate': 'Sat, 18 Jan 2025 16:01:00 +0900'},
 {'title': '[INTERVIEW] Korea to overhaul weather prediction model against climate ch...',
  'link': 'https://www.koreatimes.co.kr/www/nation/2023/06/371_353628.html?utm_source=na',
  'description': 'western Seoul to protest its confusing weather predictions, false forecasting is hardly accepted compared to what Yoo saw in Oklahoma. The administrator hopes the Korean public would understand... ',
  'pubDate': 'Sun, 25 Jun 2023 17:22:00 +0900'}]

在代理中使用

Naver搜索工具可以集成到LangChain代理中,以执行更复杂的任务。下面我们演示如何设置一个可以搜索Naver以获取当前信息的代理。
from langchain_openai import ChatOpenAI

model = ChatOpenAI(model="gpt-4o-mini")

system_prompt = """
You are a helpful assistant that can search the web for information.
"""
from langchain_naver_community.tool import NaverNewsSearch
from langchain.agents import create_agent


tools = [NaverNewsSearch()]

agent_executor = create_agent(
    model,
    tools,
    prompt=system_prompt,
)
现在我们可以使用查询运行代理。
query = "What is the weather in Seoul?"
result = agent_executor.invoke({"messages": [("human", query)]})
result["messages"][-1].content

API 参考


以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.