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>
pull/20706/merge
JuHyung Son 1 month ago committed by GitHub
parent 6a295d1ec0
commit 710e57d779
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -4,7 +4,10 @@
"cell_type": "raw", "cell_type": "raw",
"id": "910f5772b6af13c9", "id": "910f5772b6af13c9",
"metadata": { "metadata": {
"collapsed": false "collapsed": false,
"jupyter": {
"outputs_hidden": false
}
}, },
"source": [ "source": [
"---\n", "---\n",
@ -16,7 +19,10 @@
"cell_type": "markdown", "cell_type": "markdown",
"id": "433f5422ad8e1efa", "id": "433f5422ad8e1efa",
"metadata": { "metadata": {
"collapsed": false "collapsed": false,
"jupyter": {
"outputs_hidden": false
}
}, },
"source": [ "source": [
"# UpstageLayoutAnalysisLoader\n", "# UpstageLayoutAnalysisLoader\n",
@ -41,9 +47,9 @@
"\n", "\n",
"Make sure to set the following environment variables:\n", "Make sure to set the following environment variables:\n",
"\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", "\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": [ "source": [
"import os\n", "import os\n",
"\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": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python 3 (ipykernel)",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -112,7 +118,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.10.14" "version": "3.12.3"
} }
}, },
"nbformat": 4, "nbformat": 4,

@ -37,9 +37,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Get [API Keys](https://console.upstage.ai) and set environment variables `UPSTAGE_API_KEY` and `UPSTAGE_DOCUMENT_AI_API_KEY`.\n", "Get [API Keys](https://console.upstage.ai) and set environment variable `UPSTAGE_API_KEY`."
"\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."
] ]
}, },
{ {
@ -75,8 +73,7 @@
"source": [ "source": [
"import os\n", "import os\n",
"\n", "\n",
"os.environ[\"UPSTAGE_API_KEY\"] = \"YOUR_API_KEY\"\n", "os.environ[\"UPSTAGE_API_KEY\"] = \"YOUR_API_KEY\""
"os.environ[\"UPSTAGE_DOCUMENT_AI_API_KEY\"] = \"YOUR_DOCUMENT_AI_API_KEY\""
] ]
}, },
{ {
@ -131,7 +128,10 @@
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {
"collapsed": false "collapsed": false,
"jupyter": {
"outputs_hidden": false
}
}, },
"source": [ "source": [
"### Groundedness Check" "### Groundedness Check"
@ -141,7 +141,10 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": false,
"jupyter": {
"outputs_hidden": false
}
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
@ -160,7 +163,10 @@
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {
"collapsed": false "collapsed": false,
"jupyter": {
"outputs_hidden": false
}
}, },
"source": [ "source": [
"### Layout Analysis" "### Layout Analysis"
@ -204,9 +210,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.10.11" "version": "3.10.13"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 1 "nbformat_minor": 4
} }

@ -12,10 +12,10 @@ from langchain_core.utils import (
convert_to_secret_str, convert_to_secret_str,
get_from_dict_or_env, 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. """ChatUpstage chat model.
To use, you should have the environment variable `UPSTAGE_API_KEY` To use, you should have the environment variable `UPSTAGE_API_KEY`
@ -59,6 +59,16 @@ class ChatUpstage(ChatOpenAI):
upstage_api_base: Optional[str] = Field( upstage_api_base: Optional[str] = Field(
default="https://api.upstage.ai/v1/solar", alias="base_url" 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() @root_validator()
def validate_environment(cls, values: Dict) -> Dict: def validate_environment(cls, values: Dict) -> Dict:

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

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

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

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

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

Loading…
Cancel
Save