mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-19 11:08:55 +00:00
community: update Naver integration to use langchain-naver package and improve documentation (#30956)
## **Description:** This PR was requested after the `langchain-naver` partner-managed packages were completed. We build our package as requested in [this comment](https://github.com/langchain-ai/langchain/pull/29243#issuecomment-2595222791) and the initial version is now uploaded to [pypi](https://pypi.org/project/langchain-naver/). So we've updated some our documents with the additional changed features and how to download our partner-managed package. ## **Dependencies:** https://github.com/langchain-ai/langchain/pull/29243#issuecomment-2595222791 --------- Co-authored-by: ccurme <chester.curme@gmail.com>
This commit is contained in:
parent
a7c1bccd6a
commit
577cb53a00
@ -17,21 +17,21 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"# ChatClovaX\n",
|
"# ChatClovaX\n",
|
||||||
"\n",
|
"\n",
|
||||||
"This notebook provides a quick overview for getting started with Naver’s HyperCLOVA X [chat models](https://python.langchain.com/docs/concepts/chat_models) via CLOVA Studio. For detailed documentation of all ChatClovaX features and configurations head to the [API reference](https://python.langchain.com/api_reference/community/chat_models/langchain_community.chat_models.naver.ChatClovaX.html).\n",
|
"This notebook provides a quick overview for getting started with Naver’s HyperCLOVA X [chat models](https://python.langchain.com/docs/concepts/chat_models) via CLOVA Studio. For detailed documentation of all ChatClovaX features and configurations head to the [API reference](https://guide.ncloud-docs.com/docs/clovastudio-dev-langchain).\n",
|
||||||
"\n",
|
"\n",
|
||||||
"[CLOVA Studio](http://clovastudio.ncloud.com/) has several chat models. You can find information about latest models and their costs, context windows, and supported input types in the CLOVA Studio API Guide [documentation](https://api.ncloud-docs.com/docs/clovastudio-chatcompletions).\n",
|
"[CLOVA Studio](http://clovastudio.ncloud.com/) has several chat models. You can find information about latest models and their costs, context windows, and supported input types in the CLOVA Studio Guide [documentation](https://guide.ncloud-docs.com/docs/clovastudio-model).\n",
|
||||||
"\n",
|
"\n",
|
||||||
"## Overview\n",
|
"## Overview\n",
|
||||||
"### Integration details\n",
|
"### Integration details\n",
|
||||||
"\n",
|
"\n",
|
||||||
"| Class | Package | Local | Serializable | JS support | Package downloads | Package latest |\n",
|
"| Class | Package | Local | Serializable | JS support | Package downloads | Package latest |\n",
|
||||||
"| :--- | :--- |:-----:| :---: |:------------------------------------------------------------------------:| :---: | :---: |\n",
|
"| :--- | :--- |:-----:| :---: |:------------------------------------------------------------------------:| :---: | :---: |\n",
|
||||||
"| [ChatClovaX](https://python.langchain.com/api_reference/community/chat_models/langchain_community.chat_models.naver.ChatClovaX.html) | [langchain-community](https://python.langchain.com/api_reference/community/index.html) | ❌ | ❌ | ❌ |  |  |\n",
|
"| [ChatClovaX](https://guide.ncloud-docs.com/docs/clovastudio-dev-langchain#HyperCLOVAX%EB%AA%A8%EB%8D%B8%EC%9D%B4%EC%9A%A9) | [langchain-naver](https://pypi.org/project/langchain-naver/) | ❌ | ❌ | ❌ |  |  |\n",
|
||||||
"\n",
|
"\n",
|
||||||
"### Model features\n",
|
"### Model features\n",
|
||||||
"| [Tool calling](/docs/how_to/tool_calling/) | [Structured output](/docs/how_to/structured_output/) | JSON mode | [Image input](/docs/how_to/multimodal_inputs/) | Audio input | Video input | [Token-level streaming](/docs/how_to/chat_streaming/) | Native async | [Token usage](/docs/how_to/chat_token_usage_tracking/) | [Logprobs](/docs/how_to/logprobs/) |\n",
|
"| [Tool calling](/docs/how_to/tool_calling/) | [Structured output](/docs/how_to/structured_output/) | JSON mode | [Image input](/docs/how_to/multimodal_inputs/) | Audio input | Video input | [Token-level streaming](/docs/how_to/chat_streaming/) | Native async | [Token usage](/docs/how_to/chat_token_usage_tracking/) | [Logprobs](/docs/how_to/logprobs/) |\n",
|
||||||
"|:------------------------------------------:| :---: | :---: | :---: | :---: | :---: |:-----------------------------------------------------:| :---: |:------------------------------------------------------:|:----------------------------------:|\n",
|
"|:------------------------------------------:| :---: | :---: | :---: | :---: | :---: |:-----------------------------------------------------:| :---: |:------------------------------------------------------:|:----------------------------------:|\n",
|
||||||
"|❌| ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ |\n",
|
"|✅| ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ |\n",
|
||||||
"\n",
|
"\n",
|
||||||
"## Setup\n",
|
"## Setup\n",
|
||||||
"\n",
|
"\n",
|
||||||
@ -39,26 +39,23 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"1. Creating [NAVER Cloud Platform](https://www.ncloud.com/) account\n",
|
"1. Creating [NAVER Cloud Platform](https://www.ncloud.com/) account\n",
|
||||||
"2. Apply to use [CLOVA Studio](https://www.ncloud.com/product/aiService/clovaStudio)\n",
|
"2. Apply to use [CLOVA Studio](https://www.ncloud.com/product/aiService/clovaStudio)\n",
|
||||||
"3. Create a CLOVA Studio Test App or Service App of a model to use (See [here](https://guide.ncloud-docs.com/docs/en/clovastudio-playground01#테스트앱생성).)\n",
|
"3. Create a CLOVA Studio Test App or Service App of a model to use (See [here](https://guide.ncloud-docs.com/docs/clovastudio-playground-testapp).)\n",
|
||||||
"4. Issue a Test or Service API key (See [here](https://api.ncloud-docs.com/docs/ai-naver-clovastudio-summary#API%ED%82%A4).)\n",
|
"4. Issue a Test or Service API key (See [here](https://api.ncloud-docs.com/docs/ai-naver-clovastudio-summary#API%ED%82%A4).)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"### Credentials\n",
|
"### Credentials\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Set the `NCP_CLOVASTUDIO_API_KEY` environment variable with your API key.\n",
|
"Set the `CLOVASTUDIO_API_KEY` environment variable with your API key.\n",
|
||||||
" - Note that if you are using a legacy API Key (that doesn't start with `nv-*` prefix), you might need to get an additional API Key by clicking `App Request Status` > `Service App, Test App List` > `‘Details’ button for each app` in [CLOVA Studio](https://clovastudio.ncloud.com/studio-application/service-app) and set it as `NCP_APIGW_API_KEY`.\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"You can add them to your environment variables as below:\n",
|
"You can add them to your environment variables as below:\n",
|
||||||
"\n",
|
"\n",
|
||||||
"``` bash\n",
|
"``` bash\n",
|
||||||
"export NCP_CLOVASTUDIO_API_KEY=\"your-api-key-here\"\n",
|
"export CLOVASTUDIO_API_KEY=\"your-api-key-here\"\n",
|
||||||
"# Uncomment below to use a legacy API key\n",
|
|
||||||
"# export NCP_APIGW_API_KEY=\"your-api-key-here\"\n",
|
|
||||||
"```"
|
"```"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 2,
|
||||||
"id": "2def81b5-b023-4f40-a97b-b2c5ca59d6a9",
|
"id": "2def81b5-b023-4f40-a97b-b2c5ca59d6a9",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@ -66,22 +63,19 @@
|
|||||||
"import getpass\n",
|
"import getpass\n",
|
||||||
"import os\n",
|
"import os\n",
|
||||||
"\n",
|
"\n",
|
||||||
"if not os.getenv(\"NCP_CLOVASTUDIO_API_KEY\"):\n",
|
"if not os.getenv(\"CLOVASTUDIO_API_KEY\"):\n",
|
||||||
" os.environ[\"NCP_CLOVASTUDIO_API_KEY\"] = getpass.getpass(\n",
|
" os.environ[\"CLOVASTUDIO_API_KEY\"] = getpass.getpass(\n",
|
||||||
" \"Enter your NCP CLOVA Studio API Key: \"\n",
|
" \"Enter your CLOVA Studio API Key: \"\n",
|
||||||
" )\n",
|
" )"
|
||||||
"# Uncomment below to use a legacy API key\n",
|
|
||||||
"# if not os.getenv(\"NCP_APIGW_API_KEY\"):\n",
|
|
||||||
"# os.environ[\"NCP_APIGW_API_KEY\"] = getpass.getpass(\n",
|
|
||||||
"# \"Enter your NCP API Gateway API key: \"\n",
|
|
||||||
"# )"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "7c695442",
|
"id": "7c695442",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": "To enable automated tracing of your model calls, set your [LangSmith](https://docs.smith.langchain.com/) API key:"
|
"source": [
|
||||||
|
"To enable automated tracing of your model calls, set your [LangSmith](https://docs.smith.langchain.com/) API key:"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
@ -101,7 +95,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"### Installation\n",
|
"### Installation\n",
|
||||||
"\n",
|
"\n",
|
||||||
"The LangChain Naver integration lives in the `langchain-community` package:"
|
"The LangChain Naver integration lives in the `langchain-naver` package:"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -112,7 +106,7 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# install package\n",
|
"# install package\n",
|
||||||
"!pip install -qU langchain-community"
|
"%pip install -qU langchain-naver"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -127,21 +121,19 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 3,
|
||||||
"id": "cb09c344-1836-4e0c-acf8-11d13ac1dbae",
|
"id": "cb09c344-1836-4e0c-acf8-11d13ac1dbae",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from langchain_community.chat_models import ChatClovaX\n",
|
"from langchain_naver import ChatClovaX\n",
|
||||||
"\n",
|
"\n",
|
||||||
"chat = ChatClovaX(\n",
|
"chat = ChatClovaX(\n",
|
||||||
" model=\"HCX-003\",\n",
|
" model=\"HCX-005\",\n",
|
||||||
" max_tokens=100,\n",
|
|
||||||
" temperature=0.5,\n",
|
" temperature=0.5,\n",
|
||||||
" # clovastudio_api_key=\"...\" # set if you prefer to pass api key directly instead of using environment variables\n",
|
" max_tokens=None,\n",
|
||||||
" # task_id=\"...\" # set if you want to use fine-tuned model\n",
|
" timeout=None,\n",
|
||||||
" # service_app=False # set True if using Service App. Default value is False (means using Test App)\n",
|
" max_retries=2,\n",
|
||||||
" # include_ai_filters=False # set True if you want to detect inappropriate content. Default value is False\n",
|
|
||||||
" # other params...\n",
|
" # other params...\n",
|
||||||
")"
|
")"
|
||||||
]
|
]
|
||||||
@ -153,12 +145,12 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"## Invocation\n",
|
"## Invocation\n",
|
||||||
"\n",
|
"\n",
|
||||||
"In addition to invoke, we also support batch and stream functionalities."
|
"In addition to invoke, `ChatClovaX` also support batch and stream functionalities."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 4,
|
||||||
"id": "62e0dbc3",
|
"id": "62e0dbc3",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"tags": []
|
"tags": []
|
||||||
@ -167,10 +159,10 @@
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"AIMessage(content='저는 네이버 AI를 사용하는 것이 좋아요.', additional_kwargs={}, response_metadata={'stop_reason': 'stop_before', 'input_length': 25, 'output_length': 14, 'seed': 1112164354, 'ai_filter': None}, id='run-b57bc356-1148-4007-837d-cc409dbd57cc-0', usage_metadata={'input_tokens': 25, 'output_tokens': 14, 'total_tokens': 39})"
|
"AIMessage(content='네이버 인공지능을 사용하는 것을 정말 좋아합니다.', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 11, 'prompt_tokens': 28, 'total_tokens': 39, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'HCX-005', 'system_fingerprint': None, 'id': 'b70c26671cd247a0864115bacfb5fc12', 'finish_reason': 'stop', 'logprobs': None}, id='run-3faf6a8d-d5da-49ad-9fbb-7b56ed23b484-0', usage_metadata={'input_tokens': 28, 'output_tokens': 11, 'total_tokens': 39, 'input_token_details': {}, 'output_token_details': {}})"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 3,
|
"execution_count": 4,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@ -190,7 +182,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": 5,
|
||||||
"id": "24e7377f",
|
"id": "24e7377f",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@ -198,7 +190,7 @@
|
|||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"저는 네이버 AI를 사용하는 것이 좋아요.\n"
|
"네이버 인공지능을 사용하는 것을 정말 좋아합니다.\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -218,17 +210,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 5,
|
"execution_count": 6,
|
||||||
"id": "e197d1d7-a070-4c96-9f8a-a0e86d046e0b",
|
"id": "e197d1d7-a070-4c96-9f8a-a0e86d046e0b",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"AIMessage(content='저는 네이버 AI를 사용하는 것이 좋아요.', additional_kwargs={}, response_metadata={'stop_reason': 'stop_before', 'input_length': 25, 'output_length': 14, 'seed': 2575184681, 'ai_filter': None}, id='run-7014b330-eba3-4701-bb62-df73ce39b854-0', usage_metadata={'input_tokens': 25, 'output_tokens': 14, 'total_tokens': 39})"
|
"AIMessage(content='저는 네이버 인공지능을 사용하는 것을 좋아합니다.', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 10, 'prompt_tokens': 28, 'total_tokens': 38, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'HCX-005', 'system_fingerprint': None, 'id': 'b7a826d17fcf4fee8386fca2ebc63284', 'finish_reason': 'stop', 'logprobs': None}, id='run-35957816-3325-4d9c-9441-e40704912be6-0', usage_metadata={'input_tokens': 28, 'output_tokens': 10, 'total_tokens': 38, 'input_token_details': {}, 'output_token_details': {}})"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 5,
|
"execution_count": 6,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@ -266,7 +258,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 6,
|
"execution_count": 7,
|
||||||
"id": "2c07af21-dda5-4514-b4de-1f214c2cebcd",
|
"id": "2c07af21-dda5-4514-b4de-1f214c2cebcd",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@ -274,7 +266,7 @@
|
|||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"Certainly! In Korean, \"Hi\" is pronounced as \"안녕\" (annyeong). The first syllable, \"안,\" sounds like the \"ahh\" sound in \"apple,\" while the second syllable, \"녕,\" sounds like the \"yuh\" sound in \"you.\" So when you put them together, it's like saying \"ahhyuh-nyuhng.\" Remember to pronounce each syllable clearly and separately for accurate pronunciation."
|
"In Korean, the informal way of saying 'hi' is \"안녕\" (annyeong). If you're addressing someone older or showing more respect, you would use \"안녕하세요\" (annjeonghaseyo). Both phrases are used as greetings similar to 'hello'. Remember, pronunciation is key so make sure to pronounce each syllable clearly: 안-녀-엉 (an-nyeo-eong) and 안-녕-하-세-요 (an-nyeong-ha-se-yo)."
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -298,115 +290,37 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"### Using fine-tuned models\n",
|
"### Using fine-tuned models\n",
|
||||||
"\n",
|
"\n",
|
||||||
"You can call fine-tuned models by passing in your corresponding `task_id` parameter. (You don’t need to specify the `model_name` parameter when calling fine-tuned model.)\n",
|
"You can call fine-tuned models by passing the `task_id` to the `model` parameter as: `ft:{task_id}`.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"You can check `task_id` from corresponding Test App or Service App details."
|
"You can check `task_id` from corresponding Test App or Service App details."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 7,
|
"execution_count": null,
|
||||||
"id": "cb436788",
|
"id": "cb436788",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"AIMessage(content='저는 네이버 AI를 사용하는 것이 너무 좋아요.', additional_kwargs={}, response_metadata={'stop_reason': 'stop_before', 'input_length': 25, 'output_length': 15, 'seed': 52559061, 'ai_filter': None}, id='run-5bea8d4a-48f3-4c34-ae70-66e60dca5344-0', usage_metadata={'input_tokens': 25, 'output_tokens': 15, 'total_tokens': 40})"
|
"AIMessage(content='네이버 인공지능을 사용하는 것을 정말 좋아합니다.', additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 11, 'prompt_tokens': 28, 'total_tokens': 39, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'HCX-005', 'system_fingerprint': None, 'id': '2222d6d411a948c883aac1e03ca6cebe', 'finish_reason': 'stop', 'logprobs': None}, id='run-9696d7e2-7afa-4bb4-9c03-b95fcf678ab8-0', usage_metadata={'input_tokens': 28, 'output_tokens': 11, 'total_tokens': 39, 'input_token_details': {}, 'output_token_details': {}})"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 7,
|
"execution_count": 10,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"fine_tuned_model = ChatClovaX(\n",
|
"fine_tuned_model = ChatClovaX(\n",
|
||||||
" task_id=\"5s8egt3a\", # set if you want to use fine-tuned model\n",
|
" model=\"ft:a1b2c3d4\", # set as `ft:{task_id}` with your fine-tuned model's task id\n",
|
||||||
" # other params...\n",
|
" # other params...\n",
|
||||||
")\n",
|
")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"fine_tuned_model.invoke(messages)"
|
"fine_tuned_model.invoke(messages)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "f428deaf",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"### Service App\n",
|
|
||||||
"\n",
|
|
||||||
"When going live with production-level application using CLOVA Studio, you should apply for and use Service App. (See [here](https://guide.ncloud-docs.com/docs/en/clovastudio-playground01#서비스앱신청).)\n",
|
|
||||||
"\n",
|
|
||||||
"For a Service App, you should use a corresponding Service API key and can only be called with it."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"id": "dcf566df",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"# Update environment variables\n",
|
|
||||||
"\n",
|
|
||||||
"os.environ[\"NCP_CLOVASTUDIO_API_KEY\"] = getpass.getpass(\n",
|
|
||||||
" \"Enter NCP CLOVA Studio Service API Key: \"\n",
|
|
||||||
")"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 9,
|
|
||||||
"id": "cebe27ae",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"chat = ChatClovaX(\n",
|
|
||||||
" service_app=True, # True if you want to use your service app, default value is False.\n",
|
|
||||||
" # clovastudio_api_key=\"...\" # if you prefer to pass api key in directly instead of using env vars\n",
|
|
||||||
" model=\"HCX-003\",\n",
|
|
||||||
" # other params...\n",
|
|
||||||
")\n",
|
|
||||||
"ai_msg = chat.invoke(messages)"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "d73e7140",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"### AI Filter\n",
|
|
||||||
"\n",
|
|
||||||
"AI Filter detects inappropriate output such as profanity from the test app (or service app included) created in Playground and informs the user. See [here](https://guide.ncloud-docs.com/docs/en/clovastudio-playground01#AIFilter) for details."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"id": "32bfbc93",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"chat = ChatClovaX(\n",
|
|
||||||
" model=\"HCX-003\",\n",
|
|
||||||
" include_ai_filters=True, # True if you want to enable ai filter\n",
|
|
||||||
" # other params...\n",
|
|
||||||
")\n",
|
|
||||||
"\n",
|
|
||||||
"ai_msg = chat.invoke(messages)"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"id": "7bd9e179",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"print(ai_msg.response_metadata[\"ai_filter\"])"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "3a5bb5ca-c3ae-4a58-be67-2cd18574b9a3",
|
"id": "3a5bb5ca-c3ae-4a58-be67-2cd18574b9a3",
|
||||||
@ -414,13 +328,13 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"## API reference\n",
|
"## API reference\n",
|
||||||
"\n",
|
"\n",
|
||||||
"For detailed documentation of all ChatNaver features and configurations head to the API reference: https://python.langchain.com/api_reference/community/chat_models/langchain_community.chat_models.naver.ChatClovaX.html"
|
"For detailed documentation of all ChatClovaX features and configurations head to the [API reference](https://guide.ncloud-docs.com/docs/clovastudio-dev-langchain)"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"display_name": "Python 3 (ipykernel)",
|
"display_name": "Python 3",
|
||||||
"language": "python",
|
"language": "python",
|
||||||
"name": "python3"
|
"name": "python3"
|
||||||
},
|
},
|
||||||
@ -434,7 +348,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.12.3"
|
"version": "3.12.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
@ -10,19 +10,23 @@ Please refer to [NCP User Guide](https://guide.ncloud-docs.com/docs/clovastudio-
|
|||||||
|
|
||||||
## Installation and Setup
|
## Installation and Setup
|
||||||
|
|
||||||
- Get a CLOVA Studio API Key by [issuing it](https://api.ncloud-docs.com/docs/ai-naver-clovastudio-summary#API%ED%82%A4) and set it as an environment variable (`NCP_CLOVASTUDIO_API_KEY`).
|
- Get a CLOVA Studio API Key by [issuing it](https://api.ncloud-docs.com/docs/ai-naver-clovastudio-summary#API%ED%82%A4) and set it as an environment variable (`CLOVASTUDIO_API_KEY`).
|
||||||
- If you are using a legacy API Key (that doesn't start with `nv-*` prefix), you might need to get an additional API Key by [creating your app](https://guide.ncloud-docs.com/docs/en/clovastudio-playground01#create-test-app) and set it as `NCP_APIGW_API_KEY`.
|
|
||||||
|
|
||||||
Naver integrations live in two packages:
|
Naver integrations live in two packages:
|
||||||
|
|
||||||
- `langchain-naver-community`: a dedicated integration package for Naver. It is a community-maintained package and is not officially maintained by Naver or LangChain.
|
- `langchain-naver`: a dedicated integration package for Naver.
|
||||||
- `langchain-community`: a collection of [third-party integrations](https://python.langchain.com/docs/concepts/architecture/#langchain-community),
|
- `langchain-naver-community`: a community-maintained package and is not officially maintained by Naver or LangChain.
|
||||||
including Naver. **New features should be implemented in the dedicated `langchain-naver-community` package**.
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install -U langchain-community langchain-naver-community
|
pip install -U langchain-naver
|
||||||
|
# pip install -U langchain-naver-community // Install to use Naver Search tool.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> **(Note)** Naver integration via `langchain-community`, a collection of [third-party integrations](https://python.langchain.com/docs/concepts/architecture/#langchain-community), is outdated.
|
||||||
|
> - **Use `langchain-naver` instead as new features should only be implemented via this package**.
|
||||||
|
> - If you are using `langchain-community` (outdated) and got a legacy API Key (that doesn't start with `nv-*` prefix), you should set it as `NCP_CLOVASTUDIO_API_KEY`, and might need to get an additional API Gateway API Key by [creating your app](https://guide.ncloud-docs.com/docs/en/clovastudio-playground01#create-test-app) and set it as `NCP_APIGW_API_KEY`.
|
||||||
|
|
||||||
## Chat models
|
## Chat models
|
||||||
|
|
||||||
### ChatClovaX
|
### ChatClovaX
|
||||||
@ -30,7 +34,7 @@ pip install -U langchain-community langchain-naver-community
|
|||||||
See a [usage example](/docs/integrations/chat/naver).
|
See a [usage example](/docs/integrations/chat/naver).
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from langchain_community.chat_models import ChatClovaX
|
from langchain_naver import ChatClovaX
|
||||||
```
|
```
|
||||||
|
|
||||||
## Embedding models
|
## Embedding models
|
||||||
@ -40,7 +44,7 @@ from langchain_community.chat_models import ChatClovaX
|
|||||||
See a [usage example](/docs/integrations/text_embedding/naver).
|
See a [usage example](/docs/integrations/text_embedding/naver).
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from langchain_community.embeddings import ClovaXEmbeddings
|
from langchain_naver import ClovaXEmbeddings
|
||||||
```
|
```
|
||||||
|
|
||||||
## Tools
|
## Tools
|
||||||
|
@ -17,14 +17,14 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"# ClovaXEmbeddings\n",
|
"# ClovaXEmbeddings\n",
|
||||||
"\n",
|
"\n",
|
||||||
"This notebook covers how to get started with embedding models provided by CLOVA Studio. For detailed documentation on `ClovaXEmbeddings` features and configuration options, please refer to the [API reference](https://python.langchain.com/api_reference/community/embeddings/langchain_community.embeddings.naver.ClovaXEmbeddings.html).\n",
|
"This notebook covers how to get started with embedding models provided by CLOVA Studio. For detailed documentation on `ClovaXEmbeddings` features and configuration options, please refer to the [API reference](https://guide.ncloud-docs.com/docs/clovastudio-dev-langchain#%EC%9E%84%EB%B2%A0%EB%94%A9%EB%8F%84%EA%B5%AC%EC%9D%B4%EC%9A%A9).\n",
|
||||||
"\n",
|
"\n",
|
||||||
"## Overview\n",
|
"## Overview\n",
|
||||||
"### Integration details\n",
|
"### Integration details\n",
|
||||||
"\n",
|
"\n",
|
||||||
"| Provider | Package |\n",
|
"| Provider | Package |\n",
|
||||||
"|:--------:|:-------:|\n",
|
"|:--------:|:-------:|\n",
|
||||||
"| [Naver](/docs/integrations/providers/naver.mdx) | [langchain-community](https://python.langchain.com/api_reference/community/embeddings/langchain_community.embeddings.naver.ClovaXEmbeddings.html) |\n",
|
"| [Naver](/docs/integrations/providers/naver.mdx) | [langchain-naver](https://pypi.org/project/langchain-naver/) |\n",
|
||||||
"\n",
|
"\n",
|
||||||
"## Setup\n",
|
"## Setup\n",
|
||||||
"\n",
|
"\n",
|
||||||
@ -33,12 +33,11 @@
|
|||||||
"1. Creating [NAVER Cloud Platform](https://www.ncloud.com/) account \n",
|
"1. Creating [NAVER Cloud Platform](https://www.ncloud.com/) account \n",
|
||||||
"2. Apply to use [CLOVA Studio](https://www.ncloud.com/product/aiService/clovaStudio)\n",
|
"2. Apply to use [CLOVA Studio](https://www.ncloud.com/product/aiService/clovaStudio)\n",
|
||||||
"3. Create a CLOVA Studio Test App or Service App of a model to use (See [here](https://guide.ncloud-docs.com/docs/clovastudio-explorer03#%ED%85%8C%EC%8A%A4%ED%8A%B8%EC%95%B1%EC%83%9D%EC%84%B1).)\n",
|
"3. Create a CLOVA Studio Test App or Service App of a model to use (See [here](https://guide.ncloud-docs.com/docs/clovastudio-explorer03#%ED%85%8C%EC%8A%A4%ED%8A%B8%EC%95%B1%EC%83%9D%EC%84%B1).)\n",
|
||||||
"4. Issue a Test or Service API key (See [here](https://api.ncloud-docs.com/docs/ai-naver-clovastudio-summary#API%ED%82%A4).)\n",
|
"4. Issue a Test or Service API key (See [here](https://guide.ncloud-docs.com/docs/clovastudio-explorer-testapp).)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"### Credentials\n",
|
"### Credentials\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Set the `NCP_CLOVASTUDIO_API_KEY` environment variable with your API key.\n",
|
"Set the `CLOVASTUDIO_API_KEY` environment variable with your API key."
|
||||||
" - Note that if you are using a legacy API Key (that doesn't start with `nv-*` prefix), you might need two additional keys to be set as environment variables (`NCP_APIGW_API_KEY` and `NCP_CLOVASTUDIO_APP_ID`. They could be found by clicking `App Request Status` > `Service App, Test App List` > `Details` button for each app in [CLOVA Studio](https://clovastudio.ncloud.com/studio-application/service-app)."
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -51,30 +50,8 @@
|
|||||||
"import getpass\n",
|
"import getpass\n",
|
||||||
"import os\n",
|
"import os\n",
|
||||||
"\n",
|
"\n",
|
||||||
"if not os.getenv(\"NCP_CLOVASTUDIO_API_KEY\"):\n",
|
"if not os.getenv(\"CLOVASTUDIO_API_KEY\"):\n",
|
||||||
" os.environ[\"NCP_CLOVASTUDIO_API_KEY\"] = getpass.getpass(\n",
|
" os.environ[\"CLOVASTUDIO_API_KEY\"] = getpass.getpass(\"Enter CLOVA Studio API Key: \")"
|
||||||
" \"Enter NCP CLOVA Studio API Key: \"\n",
|
|
||||||
" )"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "b31fc062",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"Uncomment below to use a legacy API key:"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"id": "83520d8e-ecf8-4e47-b3bc-1ac205b3a2ab",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"# if not os.getenv(\"NCP_APIGW_API_KEY\"):\n",
|
|
||||||
"# os.environ[\"NCP_APIGW_API_KEY\"] = getpass.getpass(\"Enter NCP API Gateway API Key: \")\n",
|
|
||||||
"# os.environ[\"NCP_CLOVASTUDIO_APP_ID\"] = input(\"Enter NCP CLOVA Studio App ID: \")"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -84,7 +61,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"### Installation\n",
|
"### Installation\n",
|
||||||
"\n",
|
"\n",
|
||||||
"ClovaXEmbeddings integration lives in the `langchain_community` package:"
|
"ClovaXEmbeddings integration lives in the `langchain_naver` package:"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -95,7 +72,7 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# install package\n",
|
"# install package\n",
|
||||||
"!pip install -U langchain-community"
|
"%pip install -qU langchain-naver"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -113,7 +90,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 7,
|
"execution_count": null,
|
||||||
"id": "62e0dbc3",
|
"id": "62e0dbc3",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"scrolled": true,
|
"scrolled": true,
|
||||||
@ -121,10 +98,10 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from langchain_community.embeddings import ClovaXEmbeddings\n",
|
"from langchain_naver import ClovaXEmbeddings\n",
|
||||||
"\n",
|
"\n",
|
||||||
"embeddings = ClovaXEmbeddings(\n",
|
"embeddings = ClovaXEmbeddings(\n",
|
||||||
" model=\"clir-emb-dolphin\" # set with the model name of corresponding app id. Default is `clir-emb-dolphin`\n",
|
" model=\"clir-emb-dolphin\" # set with the model name of corresponding test/service app. Default is `clir-emb-dolphin`\n",
|
||||||
")"
|
")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -225,7 +202,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 10,
|
"execution_count": null,
|
||||||
"id": "1f2e6104",
|
"id": "1f2e6104",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@ -239,55 +216,12 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"text2 = \"LangChain is the framework for building context-aware reasoning applications\"\n",
|
"text2 = \"LangChain is a framework for building context-aware reasoning applications\"\n",
|
||||||
"two_vectors = embeddings.embed_documents([text, text2])\n",
|
"two_vectors = embeddings.embed_documents([text, text2])\n",
|
||||||
"for vector in two_vectors:\n",
|
"for vector in two_vectors:\n",
|
||||||
" print(str(vector)[:100]) # Show the first 100 characters of the vector"
|
" print(str(vector)[:100]) # Show the first 100 characters of the vector"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"id": "eee40d32367cc5c4",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"## Additional functionalities\n",
|
|
||||||
"\n",
|
|
||||||
"### Service App\n",
|
|
||||||
"\n",
|
|
||||||
"When going live with production-level application using CLOVA Studio, you should apply for and use Service App. (See [here](https://guide.ncloud-docs.com/docs/en/clovastudio-playground01#서비스앱신청).)\n",
|
|
||||||
"\n",
|
|
||||||
"For a Service App, you should use a corresponding Service API key and can only be called with it."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"id": "08f9f44e-c6a4-4163-8caf-27a0cda345b7",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"# Update environment variables\n",
|
|
||||||
"\n",
|
|
||||||
"os.environ[\"NCP_CLOVASTUDIO_API_KEY\"] = getpass.getpass(\n",
|
|
||||||
" \"Enter NCP CLOVA Studio API Key for Service App: \"\n",
|
|
||||||
")\n",
|
|
||||||
"# Uncomment below to use a legacy API key:\n",
|
|
||||||
"os.environ[\"NCP_CLOVASTUDIO_APP_ID\"] = input(\"Enter NCP CLOVA Studio Service App ID: \")"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"id": "86f59698-b3f4-4b19-a9d4-4facfcea304b",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"embeddings = ClovaXEmbeddings(\n",
|
|
||||||
" service_app=True,\n",
|
|
||||||
" model=\"clir-emb-dolphin\", # set with the model name of corresponding app id of your Service App\n",
|
|
||||||
")"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "1ddeaee9",
|
"id": "1ddeaee9",
|
||||||
@ -295,7 +229,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"## API Reference\n",
|
"## API Reference\n",
|
||||||
"\n",
|
"\n",
|
||||||
"For detailed documentation on `ClovaXEmbeddings` features and configuration options, please refer to the [API reference](https://python.langchain.com/latest/api_reference/community/embeddings/langchain_community.embeddings.naver.ClovaXEmbeddings.html)."
|
"For detailed documentation on `ClovaXEmbeddings` features and configuration options, please refer to the [API reference](https://guide.ncloud-docs.com/docs/clovastudio-dev-langchain#%EC%9E%84%EB%B2%A0%EB%94%A9%EB%8F%84%EA%B5%AC%EC%9D%B4%EC%9A%A9)."
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -558,9 +558,16 @@ packages:
|
|||||||
provider_page: zotero
|
provider_page: zotero
|
||||||
downloads: 72
|
downloads: 72
|
||||||
downloads_updated_at: '2025-04-22T15:25:24.644345+00:00'
|
downloads_updated_at: '2025-04-22T15:25:24.644345+00:00'
|
||||||
- name: langchain-naver-community
|
- name: langchain-naver
|
||||||
name_title: Naver
|
name_title: Naver
|
||||||
path: .
|
path: .
|
||||||
|
repo: NaverCloudPlatform/langchain-naver
|
||||||
|
provider_page: naver
|
||||||
|
downloads: 239
|
||||||
|
downloads_updated_at: '2025-04-22T15:43:47.979572+00:00'
|
||||||
|
- name: langchain-naver-community
|
||||||
|
name_title: Naver (community-maintained)
|
||||||
|
path: .
|
||||||
repo: e7217/langchain-naver-community
|
repo: e7217/langchain-naver-community
|
||||||
provider_page: naver
|
provider_page: naver
|
||||||
downloads: 119
|
downloads: 119
|
||||||
|
Loading…
Reference in New Issue
Block a user