mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-02 11:39:18 +00:00
upstage: init package (#20574)
Co-authored-by: Sean Cho <sean@upstage.ai> Co-authored-by: JuHyung-Son <sonju0427@gmail.com>
This commit is contained in:
@@ -2,16 +2,19 @@
|
||||
|
||||
from typing import Dict
|
||||
|
||||
from langchain_core.pydantic_v1 import root_validator
|
||||
from langchain_core._api import deprecated
|
||||
from langchain_core.pydantic_v1 import Field, root_validator
|
||||
from langchain_core.utils import get_from_dict_or_env
|
||||
|
||||
from langchain_community.chat_models import ChatOpenAI
|
||||
from langchain_community.llms.solar import SOLAR_SERVICE_URL_BASE, SolarCommon
|
||||
|
||||
|
||||
class SolarChat(SolarCommon, ChatOpenAI): # type: ignore[misc]
|
||||
"""Solar large language models.
|
||||
|
||||
@deprecated(
|
||||
since="0.0.34", removal="0.2.0", alternative_import="langchain_upstage.ChatUpstage"
|
||||
)
|
||||
class SolarChat(SolarCommon, ChatOpenAI):
|
||||
"""Wrapper around Solar large language models.
|
||||
To use, you should have the ``openai`` python package installed, and the
|
||||
environment variable ``SOLAR_API_KEY`` set with your API key.
|
||||
(Solar's chat API is compatible with OpenAI's SDK.)
|
||||
@@ -24,6 +27,16 @@ class SolarChat(SolarCommon, ChatOpenAI): # type: ignore[misc]
|
||||
solar = SolarChat(model="solar-1-mini-chat")
|
||||
"""
|
||||
|
||||
max_tokens: int = Field(default=1024)
|
||||
|
||||
# this is needed to match ChatOpenAI superclass
|
||||
class Config:
|
||||
"""Configuration for this pydantic object."""
|
||||
|
||||
allow_population_by_field_name = True
|
||||
arbitrary_types_allowed = True
|
||||
extra = "ignore"
|
||||
|
||||
@root_validator()
|
||||
def validate_environment(cls, values: Dict) -> Dict:
|
||||
"""Validate that the environment is set up correctly."""
|
||||
@@ -42,9 +55,9 @@ class SolarChat(SolarCommon, ChatOpenAI): # type: ignore[misc]
|
||||
|
||||
client_params = {
|
||||
"api_key": values["solar_api_key"],
|
||||
"base_url": values["base_url"]
|
||||
if "base_url" in values
|
||||
else SOLAR_SERVICE_URL_BASE,
|
||||
"base_url": (
|
||||
values["base_url"] if "base_url" in values else SOLAR_SERVICE_URL_BASE
|
||||
),
|
||||
}
|
||||
|
||||
if not values.get("client"):
|
||||
|
Reference in New Issue
Block a user