mirror of
https://github.com/hwchase17/langchain.git
synced 2025-05-03 22:28:04 +00:00
This PR updates model names in the upstage library to reflect the latest naming conventions and removes deprecated models. Changes: Renamed Models: - `solar-1-mini-chat` -> `solar-mini` - `solar-1-mini-embedding-query` -> `embedding-query` Removed Deprecated Models: - `layout-analysis` (replaced to `document-parse`) Reference: - https://console.upstage.ai/docs/getting-started/overview - https://github.com/langchain-ai/langchain-upstage/releases/tag/libs%2Fupstage%2Fv0.5.0 Additional guidelines: - Make sure optional dependencies are imported within a function. - Please do not add dependencies to pyproject.toml files (even optional ones) unless they are required for unit tests. - Most PRs should not touch more than one package. - Changes should be backwards compatible. - If you are adding something to community, do not re-import it in langchain. If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.
70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
"""Wrapper around Solar chat models."""
|
|
|
|
from typing import Dict
|
|
|
|
from langchain_core._api import deprecated
|
|
from langchain_core.utils import get_from_dict_or_env, pre_init
|
|
from pydantic import ConfigDict, Field
|
|
|
|
from langchain_community.chat_models import ChatOpenAI
|
|
from langchain_community.llms.solar import SOLAR_SERVICE_URL_BASE, SolarCommon
|
|
|
|
|
|
@deprecated( # type: ignore[arg-type]
|
|
since="0.0.34", removal="1.0", alternative_import="langchain_upstage.ChatUpstage"
|
|
)
|
|
class SolarChat(SolarCommon, ChatOpenAI): # type: ignore[override, override]
|
|
"""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.)
|
|
Referenced from https://console.upstage.ai/services/solar
|
|
Example:
|
|
.. code-block:: python
|
|
|
|
from langchain_community.chat_models.solar import SolarChat
|
|
|
|
solar = SolarChat(model="solar-mini")
|
|
"""
|
|
|
|
max_tokens: int = Field(default=1024)
|
|
|
|
# this is needed to match ChatOpenAI superclass
|
|
model_config = ConfigDict(
|
|
populate_by_name=True,
|
|
arbitrary_types_allowed=True,
|
|
extra="ignore",
|
|
)
|
|
|
|
@pre_init
|
|
def validate_environment(cls, values: Dict) -> Dict:
|
|
"""Validate that the environment is set up correctly."""
|
|
values["solar_api_key"] = get_from_dict_or_env(
|
|
values, "solar_api_key", "SOLAR_API_KEY"
|
|
)
|
|
|
|
try:
|
|
import openai
|
|
|
|
except ImportError:
|
|
raise ImportError(
|
|
"Could not import openai python package. "
|
|
"Please install it with `pip install openai`."
|
|
)
|
|
|
|
client_params = {
|
|
"api_key": values["solar_api_key"],
|
|
"base_url": (
|
|
values["base_url"] if "base_url" in values else SOLAR_SERVICE_URL_BASE
|
|
),
|
|
}
|
|
|
|
if not values.get("client"):
|
|
values["client"] = openai.OpenAI(**client_params).chat.completions
|
|
if not values.get("async_client"):
|
|
values["async_client"] = openai.AsyncOpenAI(
|
|
**client_params
|
|
).chat.completions
|
|
|
|
return values
|