upstage: deprecate UPSTAGE_DOCUMENT_AI_API_KEY (#21363)

Description: We are merging UPSTAGE_DOCUMENT_AI_API_KEY and
UPSTAGE_API_KEY into one, and only UPSTAGE_API_KEY will be used going
forward. And we changed the base class of ChatUpstage to BaseChatOpenAI.

---------

Co-authored-by: Sean <chosh0615@gmail.com>
Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
JuHyung Son 2024-05-08 20:02:26 +02:00 committed by GitHub
parent 6a295d1ec0
commit 710e57d779
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 63 additions and 25 deletions

View File

@ -4,7 +4,10 @@
"cell_type": "raw",
"id": "910f5772b6af13c9",
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"---\n",
@ -16,7 +19,10 @@
"cell_type": "markdown",
"id": "433f5422ad8e1efa",
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"# UpstageLayoutAnalysisLoader\n",
@ -41,9 +47,9 @@
"\n",
"Make sure to set the following environment variables:\n",
"\n",
"- `UPSTAGE_DOCUMENT_AI_API_KEY`: Your Upstage Document AI API key. Read [Upstage developers document](https://developers.upstage.ai/docs/getting-started/quick-start) to get your API key.\n",
"- `UPSTAGE_API_KEY`: Your Upstage API key. Read [Upstage developers document](https://developers.upstage.ai/docs/getting-started/quick-start) to get your API key.\n",
"\n",
"> As of April 2024, you need separate access tokens for Solar and Layout Analysis. The access tokens will be consolidated soon (hopefully in May) and you'll need just one key for all features."
"> The previously used UPSTAGE_DOCUMENT_AI_API_KEY is deprecated. However, the key previously used in UPSTAGE_DOCUMENT_AI_API_KEY can now be used in UPSTAGE_API_KEY."
]
},
{
@ -63,7 +69,7 @@
"source": [
"import os\n",
"\n",
"os.environ[\"UPSTAGE_DOCUMENT_AI_API_KEY\"] = \"YOUR_API_KEY\""
"os.environ[\"UPSTAGE_API_KEY\"] = \"YOUR_API_KEY\""
]
},
{
@ -98,7 +104,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@ -112,7 +118,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
"version": "3.12.3"
}
},
"nbformat": 4,

View File

@ -37,9 +37,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Get [API Keys](https://console.upstage.ai) and set environment variables `UPSTAGE_API_KEY` and `UPSTAGE_DOCUMENT_AI_API_KEY`.\n",
"\n",
"> As of April 2024, you need separate API Keys for Solar and Document AI(Layout Analysis). The API Keys will be consolidated soon (hopefully in May) and you'll need just one key for all features."
"Get [API Keys](https://console.upstage.ai) and set environment variable `UPSTAGE_API_KEY`."
]
},
{
@ -75,8 +73,7 @@
"source": [
"import os\n",
"\n",
"os.environ[\"UPSTAGE_API_KEY\"] = \"YOUR_API_KEY\"\n",
"os.environ[\"UPSTAGE_DOCUMENT_AI_API_KEY\"] = \"YOUR_DOCUMENT_AI_API_KEY\""
"os.environ[\"UPSTAGE_API_KEY\"] = \"YOUR_API_KEY\""
]
},
{
@ -131,7 +128,10 @@
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"### Groundedness Check"
@ -141,7 +141,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
@ -160,7 +163,10 @@
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"### Layout Analysis"
@ -204,9 +210,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}

View File

@ -12,10 +12,10 @@ from langchain_core.utils import (
convert_to_secret_str,
get_from_dict_or_env,
)
from langchain_openai import ChatOpenAI
from langchain_openai.chat_models.base import BaseChatOpenAI
class ChatUpstage(ChatOpenAI):
class ChatUpstage(BaseChatOpenAI):
"""ChatUpstage chat model.
To use, you should have the environment variable `UPSTAGE_API_KEY`
@ -59,6 +59,16 @@ class ChatUpstage(ChatOpenAI):
upstage_api_base: Optional[str] = Field(
default="https://api.upstage.ai/v1/solar", alias="base_url"
)
"""Base URL path for API requests, leave blank if not using a proxy or service
emulator."""
openai_api_key: Optional[SecretStr] = Field(default=None)
"""openai api key is not supported for upstage. use `upstage_api_key` instead."""
openai_api_base: Optional[str] = Field(default=None)
"""openai api base is not supported for upstage. use `upstage_api_base` instead."""
openai_organization: Optional[str] = Field(default=None)
"""openai organization is not supported for upstage."""
tiktoken_model_name: Optional[str] = None
"""tiktoken is not supported for upstage."""
@root_validator()
def validate_environment(cls, values: Dict) -> Dict:

View File

@ -1,4 +1,5 @@
import os
import warnings
from pathlib import Path
from typing import Iterator, List, Literal, Optional, Union
@ -73,7 +74,7 @@ def get_from_param_or_env(
class UpstageLayoutAnalysisLoader(BaseLoader):
"""Upstage Layout Analysis.
To use, you should have the environment variable `UPSTAGE_DOCUMENT_AI_API_KEY`
To use, you should have the environment variable `UPSTAGE_API_KEY`
set with your API key or pass it as a named parameter to the constructor.
Example:
@ -110,7 +111,7 @@ class UpstageLayoutAnalysisLoader(BaseLoader):
api_key (str, optional): The API key for accessing the Upstage API.
Defaults to None, in which case it will be
fetched from the environment variable
`UPSTAGE_DOCUMENT_AI_API_KEY`.
`UPSTAGE_API_KEY`.
use_ocr (bool, optional): Extract text from images in the document.
Defaults to False. (Use text info in PDF file)
exclude (list, optional): Exclude specific elements from
@ -120,8 +121,14 @@ class UpstageLayoutAnalysisLoader(BaseLoader):
self.file_path = file_path
self.output_type = output_type
self.split = split
if deprecated_key := os.environ.get("UPSTAGE_DOCUMENT_AI_API_KEY"):
warnings.warn(
"UPSTAGE_DOCUMENT_AI_API_KEY is deprecated."
"Please use UPSTAGE_API_KEY instead."
)
self.api_key = get_from_param_or_env(
"UPSTAGE_DOCUMENT_AI_API_KEY", api_key, "UPSTAGE_DOCUMENT_AI_API_KEY"
"UPSTAGE_API_KEY", api_key, "UPSTAGE_API_KEY", deprecated_key
)
self.use_ocr = use_ocr
self.exclude = exclude

View File

@ -1,6 +1,7 @@
import io
import json
import os
import warnings
from typing import Dict, Iterator, List, Literal, Optional, Union
import fitz # type: ignore
@ -103,7 +104,7 @@ def get_from_param_or_env(
class UpstageLayoutAnalysisParser(BaseBlobParser):
"""Upstage Layout Analysis Parser.
To use, you should have the environment variable `UPSTAGE_DOCUMENT_AI_API_KEY`
To use, you should have the environment variable `UPSTAGE_API_KEY`
set with your API key or pass it as a named parameter to the constructor.
Example:
@ -129,7 +130,7 @@ class UpstageLayoutAnalysisParser(BaseBlobParser):
api_key (str, optional): The API key for accessing the Upstage API.
Defaults to None, in which case it will be
fetched from the environment variable
`UPSTAGE_DOCUMENT_AI_API_KEY`.
`UPSTAGE_API_KEY`.
output_type (Union[OutputType, dict], optional): The type of output to be
generated by the parser.
Defaults to "html".
@ -140,8 +141,13 @@ class UpstageLayoutAnalysisParser(BaseBlobParser):
exclude (list, optional): Exclude specific elements from the output.
Defaults to [] (all included).
"""
if deprecated_key := os.environ.get("UPSTAGE_DOCUMENT_AI_API_KEY"):
warnings.warn(
"UPSTAGE_DOCUMENT_AI_API_KEY is deprecated."
"Please use UPSTAGE_API_KEY instead."
)
self.api_key = get_from_param_or_env(
"UPSTAGE_DOCUMENT_AI_API_KEY", api_key, "UPSTAGE_DOCUMENT_AI_API_KEY"
"UPSTAGE_API_KEY", api_key, "UPSTAGE_API_KEY", deprecated_key
)
self.output_type = output_type

View File

@ -1,4 +1,5 @@
"""Test Upstage embeddings."""
from langchain_upstage import UpstageEmbeddings

View File

@ -1,4 +1,5 @@
"""Standard LangChain interface tests"""
from typing import Type
import pytest

View File

@ -1,4 +1,5 @@
"""Test embedding model integration."""
import os
import pytest