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
8 changed files with 63 additions and 25 deletions

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