-
Notifications
You must be signed in to change notification settings - Fork 18.8k
community[tool]: Integrate a tool for the naver_search #30392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ccurme
merged 8 commits into
langchain-ai:master
from
e7217:feat/add-tool-naver-community
Mar 23, 2025
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2951669
feat: add tool for the naver_search
e7217 723e6c5
feat: add content to 'packages.yml' and 'naver.mdx'
e7217 88288f6
docs: add integration details and agent usage example to naver_search…
e7217 ff2689c
docs: add naver-community.mdx
e7217 4ddca63
fix: apply linting and formatting
e7217 7e01245
Merge branch 'master' into feat/add-tool-naver-community
e7217 470149a
consolidate provider pages
ccurme 50af998
nit
ccurme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# NAVER | ||
|
||
All functionality related to Naver tools and services integrated with LangChain. | ||
|
||
> [Naver](https://navercorp.com/) is a global technology company based in South Korea, offering various services including search, commerce, fintech, content, cloud, and AI. | ||
|
||
> **Note**: `langchain-naver-community` is an unofficial, community-maintained package and is not officially supported by Naver or LangChain. It provides integration with Naver services through their public APIs. | ||
|
||
## Installation and Setup | ||
|
||
```bash | ||
pip install -U langchain-naver-community | ||
``` | ||
|
||
## Tools | ||
|
||
### Naver Search | ||
|
||
The Naver Search integration allows your LangChain applications to retrieve information from Naver's search engine. This is particularly useful for Korean language queries and getting up-to-date information about Korean topics. | ||
|
||
To use the Naver Search tools, you need to: | ||
|
||
1. Sign in to the [Naver Developers portal](https://developers.naver.com/main/) | ||
2. Create a new application and enable the Search API | ||
3. Obtain your **NAVER_CLIENT_ID** and **NAVER_CLIENT_SECRET** from the "Application List" section | ||
4. Set these as environment variables in your application | ||
|
||
```python | ||
from langchain_naver_community.tool import NaverSearchResults | ||
from langchain_naver_community.utils import NaverSearchAPIWrapper | ||
|
||
# Set up the search wrapper | ||
search = NaverSearchAPIWrapper() | ||
|
||
# Create a tool | ||
tool = NaverSearchResults(api_wrapper=search) | ||
``` | ||
|
||
See a [usage example](/docs/integrations/tools/naver_search) for more details. | ||
|
||
### Specialized Search Tools | ||
|
||
The package also provides specialized search tools for different types of content: | ||
|
||
```python | ||
from langchain_naver_community.tool import NaverNewsSearch # For news articles | ||
from langchain_naver_community.tool import NaverBlogSearch # For blog posts | ||
from langchain_naver_community.tool import NaverImageSearch # For images | ||
``` | ||
|
||
Each of these can be used within LangChain agents to provide more targeted search capabilities. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,262 @@ | ||||||
{ | ||||||
"cells": [ | ||||||
{ | ||||||
"cell_type": "markdown", | ||||||
"id": "245a954a", | ||||||
"metadata": {}, | ||||||
"source": [ | ||||||
"# Naver Search\n", | ||||||
"\n", | ||||||
"## Overview\n", | ||||||
"\n", | ||||||
"### Integration details\n", | ||||||
"\n", | ||||||
"| Class | Package | Serializable | JS support | Package latest |\n", | ||||||
"| :--- | :--- | :---: | :---: | :---: |\n", | ||||||
"| NaverSearchResults | [langchain-naver-community](https://pypi.org/project/langchain-naver-community/) | ❌ | ❌ |  |\n", | ||||||
"\n", | ||||||
"### Tool features\n", | ||||||
"\n", | ||||||
"**Search** : The Naver Search Tool provides a simple interface to search Naver and get results: \n", | ||||||
"\n", | ||||||
"## Setup\n", | ||||||
"### Setting Up API Credentials\n", | ||||||
"To use Naver Search, you need to obtain API credentials. Follow these steps:\n", | ||||||
"\n", | ||||||
"Sign in to the [Naver Developers portal](https://developers.naver.com/main/).\n", | ||||||
"Create a new application and enable the Search API.\n", | ||||||
"Obtain your **NAVER_CLIENT_ID** and **NAVER_CLIENT_SECRET** from the \"Application List\" section.\n", | ||||||
"\n", | ||||||
"### Setting Up Environment Variables\n", | ||||||
"After obtaining the credentials, set them as environment variables in your script:" | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"cell_type": "code", | ||||||
"execution_count": null, | ||||||
"id": "a2998f9c", | ||||||
"metadata": {}, | ||||||
"outputs": [], | ||||||
"source": [ | ||||||
"%pip install --upgrade --quiet langchain-naver-community" | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"cell_type": "code", | ||||||
"execution_count": 2, | ||||||
"id": "30692b20", | ||||||
"metadata": {}, | ||||||
"outputs": [], | ||||||
"source": [ | ||||||
"import getpass\n", | ||||||
"import os\n", | ||||||
"\n", | ||||||
"if not os.environ.get(\"NAVER_CLIENT_ID\"):\n", | ||||||
" os.environ[\"NAVER_CLIENT_ID\"] = getpass.getpass(\"Enter your Naver Client ID:\\n\")\n", | ||||||
"\n", | ||||||
"if not os.environ.get(\"NAVER_CLIENT_SECRET\"):\n", | ||||||
" os.environ[\"NAVER_CLIENT_SECRET\"] = getpass.getpass(\n", | ||||||
" \"Enter your Naver Client Secret:\\n\"\n", | ||||||
" )" | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"cell_type": "markdown", | ||||||
"id": "c43917d5", | ||||||
"metadata": {}, | ||||||
"source": [ | ||||||
"## Instantiation" | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"cell_type": "code", | ||||||
"execution_count": null, | ||||||
"id": "3d2be578", | ||||||
"metadata": {}, | ||||||
"outputs": [], | ||||||
"source": [ | ||||||
"from langchain_naver_community.utils import NaverSearchAPIWrapper\n", | ||||||
"\n", | ||||||
"search = NaverSearchAPIWrapper()" | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"cell_type": "markdown", | ||||||
"id": "c97b3f7a", | ||||||
"metadata": {}, | ||||||
"source": [ | ||||||
"## Invocation" | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"cell_type": "code", | ||||||
"execution_count": 5, | ||||||
"id": "ac4910f8", | ||||||
"metadata": {}, | ||||||
"outputs": [ | ||||||
{ | ||||||
"data": { | ||||||
"text/plain": [ | ||||||
"[{'title': 'Seoul shares rise for 4th day on tech gains; won at 2-week low',\n", | ||||||
" 'link': 'https://n.news.naver.com/mnews/article/001/0015277717?sid=104',\n", | ||||||
" '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... ',\n", | ||||||
" 'pubDate': 'Thu, 20 Mar 2025 16:09:00 +0900'},\n", | ||||||
" {'title': \"Seoul Mayor Oh's residence, office raided over alleged ties to shadowy po...\",\n", | ||||||
" 'link': 'https://n.news.naver.com/mnews/article/640/0000067073?sid=100',\n", | ||||||
" '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... ',\n", | ||||||
" 'pubDate': 'Thu, 20 Mar 2025 19:12:00 +0900'},\n", | ||||||
" {'title': 'Education can heal divides: Seoul schools chief',\n", | ||||||
" 'link': 'https://n.news.naver.com/mnews/article/044/0000267866?sid=104',\n", | ||||||
" '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... ',\n", | ||||||
" 'pubDate': 'Thu, 20 Mar 2025 14:35:00 +0900'}]" | ||||||
] | ||||||
}, | ||||||
"execution_count": 5, | ||||||
"metadata": {}, | ||||||
"output_type": "execute_result" | ||||||
} | ||||||
], | ||||||
"source": [ | ||||||
"search.results(\"Seoul\")[:3]" | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"cell_type": "markdown", | ||||||
"id": "2511982a", | ||||||
"metadata": {}, | ||||||
"source": [ | ||||||
"## Tool Usage" | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"cell_type": "code", | ||||||
"execution_count": 19, | ||||||
"id": "e17126e7", | ||||||
"metadata": {}, | ||||||
"outputs": [ | ||||||
{ | ||||||
"data": { | ||||||
"text/plain": [ | ||||||
"[{'title': \"2025 is here. Here's what to watch out for\",\n", | ||||||
" 'link': 'https://n.news.naver.com/mnews/article/044/0000265707?sid=104',\n", | ||||||
" '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... ',\n", | ||||||
" 'pubDate': 'Sat, 18 Jan 2025 16:01:00 +0900'},\n", | ||||||
" {'title': '[INTERVIEW] Korea to overhaul weather prediction model against climate ch...',\n", | ||||||
" 'link': 'https://www.koreatimes.co.kr/www/nation/2023/06/371_353628.html?utm_source=na',\n", | ||||||
" '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... ',\n", | ||||||
" 'pubDate': 'Sun, 25 Jun 2023 17:22:00 +0900'}]" | ||||||
] | ||||||
}, | ||||||
"execution_count": 19, | ||||||
"metadata": {}, | ||||||
"output_type": "execute_result" | ||||||
} | ||||||
], | ||||||
"source": [ | ||||||
"from langchain_naver_community.tool import NaverSearchResults\n", | ||||||
"from langchain_naver_community.utils import NaverSearchAPIWrapper\n", | ||||||
"\n", | ||||||
"search = NaverSearchAPIWrapper()\n", | ||||||
"\n", | ||||||
"tool = NaverSearchResults(api_wrapper=search)\n", | ||||||
"\n", | ||||||
"tool.invoke(\"what is the weather in seoul?\")[3:5]" | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"cell_type": "markdown", | ||||||
"id": "74295cb5", | ||||||
"metadata": {}, | ||||||
"source": [ | ||||||
"## Use within an agent\n", | ||||||
"\n", | ||||||
"The Naver Search tool can be integrated into LangChain agents for more complex tasks. Below we demonstrate how to set up an agent that can search Naver for current information.\n" | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"cell_type": "code", | ||||||
"execution_count": null, | ||||||
"id": "386e19b0", | ||||||
"metadata": {}, | ||||||
"outputs": [], | ||||||
"source": [ | ||||||
"from langchain_openai import ChatOpenAI\n", | ||||||
"\n", | ||||||
"llm = ChatOpenAI(model=\"gpt-4o-mini\")\n", | ||||||
"\n", | ||||||
"system_prompt = \"\"\"\n", | ||||||
"You are a helpful assistant that can search the web for information.\n", | ||||||
"\"\"\"" | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"cell_type": "code", | ||||||
"execution_count": null, | ||||||
"id": "70da8682", | ||||||
"metadata": {}, | ||||||
"outputs": [], | ||||||
"source": [ | ||||||
"from langchain_naver_community.tool import NaverNewsSearch\n", | ||||||
"from langgraph.prebuilt import create_react_agent\n", | ||||||
"\n", | ||||||
"tools = [NaverNewsSearch()]\n", | ||||||
"\n", | ||||||
"agent_executor = create_react_agent(\n", | ||||||
" llm,\n", | ||||||
" tools,\n", | ||||||
" prompt=system_prompt,\n", | ||||||
")" | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"cell_type": "markdown", | ||||||
"id": "4b73dbaf", | ||||||
"metadata": {}, | ||||||
"source": [ | ||||||
"Now we can run the agent with a query." | ||||||
] | ||||||
}, | ||||||
{ | ||||||
"cell_type": "code", | ||||||
"execution_count": null, | ||||||
"id": "726e575a", | ||||||
"metadata": {}, | ||||||
"outputs": [], | ||||||
"source": [ | ||||||
"query = \"What is the weather in Seoul?\"\n", | ||||||
"result = agent_executor.invoke({\"messages\": [(\"human\", query)]})\n", | ||||||
"result[\"messages\"][-1].content" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Might be nice to run this to show output! |
||||||
] | ||||||
}, | ||||||
{ | ||||||
"cell_type": "markdown", | ||||||
"id": "d566a4c0", | ||||||
"metadata": {}, | ||||||
"source": [ | ||||||
"## API reference\n", | ||||||
"\n" | ||||||
] | ||||||
} | ||||||
], | ||||||
"metadata": { | ||||||
"kernelspec": { | ||||||
"display_name": "Python 3", | ||||||
"language": "python", | ||||||
"name": "python3" | ||||||
}, | ||||||
"language_info": { | ||||||
"codemirror_mode": { | ||||||
"name": "ipython", | ||||||
"version": 3 | ||||||
}, | ||||||
"file_extension": ".py", | ||||||
"mimetype": "text/x-python", | ||||||
"name": "python", | ||||||
"nbconvert_exporter": "python", | ||||||
"pygments_lexer": "ipython3", | ||||||
"version": "3.11.10" | ||||||
} | ||||||
}, | ||||||
"nbformat": 4, | ||||||
"nbformat_minor": 5 | ||||||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence ends abruptly.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your feedback.