Skip to content

Commit

Permalink
[integration package] add api_key alias on upstage llm and embeddings (
Browse files Browse the repository at this point in the history
…#14233)

* fix: alias upsage_api_key to api_key

* chore: update package version
  • Loading branch information
JuHyung-Son committed Jun 22, 2024
1 parent 40600da commit 4835cb3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class UpstageEmbedding(OpenAIEmbedding):
default_factory=dict, description="Additional kwargs for the Upstage API."
)

api_key: str = Field(description="The Upstage API key.")
api_key: str = Field(alias="upstage_api_key", description="The Upstage API key.")
api_base: Optional[str] = Field(
default=DEFAULT_UPSTAGE_API_BASE, description="The base URL for Upstage API."
)
Expand Down Expand Up @@ -86,6 +86,9 @@ def __init__(
f"embed_batch_size should be less than or equal to {MAX_EMBED_BATCH_SIZE}."
)

if "upstage_api_key" in kwargs:
api_key = kwargs.pop("upstage_api_key")

api_key, api_base = resolve_upstage_credentials(
api_key=api_key, api_base=api_base
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ license = "MIT"
name = "llama-index-embeddings-upstage"
packages = [{include = "llama_index/"}]
readme = "README.md"
version = "0.1.1"
version = "0.1.2"

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ def test_upstage_embedding_class(upstage_embedding):
assert BaseEmbedding.__name__ in names_of_base_classes


def upstage_embedding_fail_wrong_model(upstage_embedding):
def test_upstage_embedding_fail_wrong_model(upstage_embedding):
with pytest.raises(ValueError):
upstage_embedding(model="foo")


def test_upstage_embedding_api_key_alias(upstage_embedding):
api_key = "test_key"
embedding1 = upstage_embedding(api_key=api_key)
embedding2 = upstage_embedding(upstage_api_key=api_key)
embedding3 = upstage_embedding(error_api_key=api_key)

assert embedding1.api_key == api_key
assert embedding2.api_key == api_key
assert embedding3.api_key == ""
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ class Upstage(OpenAI):
default=True,
)

api_key: str = Field(default=None, description="The Upstage API key.")
api_key: str = Field(
default=None, alias="upstage_api_key", description="The Upstage API key."
)
api_base: str = Field(
default="https://api.upstage.ai/v1/solar",
description="The Upstage API base URL.",
Expand Down Expand Up @@ -112,6 +114,8 @@ def __init__(
output_parser: Optional[BaseOutputParser] = None,
**kwargs: Any
) -> None:
if "upstage_api_key" in kwargs:
api_key = kwargs.pop("upstage_api_key")
additional_kwargs = additional_kwargs or {}
api_key, api_base = resolve_upstage_credentials(
api_key=api_key, api_base=api_base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ license = "MIT"
name = "llama-index-llms-upstage"
packages = [{include = "llama_index/"}]
readme = "README.md"
version = "0.1.0"
version = "0.1.1"

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
from llama_index.llms.upstage import Upstage


def test_text_inference_embedding_class():
def test_text_inference_llm_class():
names_of_base_classes = [b.__name__ for b in Upstage.__mro__]
assert BaseLLM.__name__ in names_of_base_classes


def test_upstage_llm_api_key_alias():
api_key = "test_key"
embedding1 = Upstage(api_key=api_key)
embedding2 = Upstage(upstage_api_key=api_key)
embedding3 = Upstage(error_api_key=api_key)

assert embedding1.api_key == api_key
assert embedding2.api_key == api_key
assert embedding3.api_key == ""

0 comments on commit 4835cb3

Please sign in to comment.