mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
feat(model-profiles): distribute data across packages (#34024)
This commit is contained in:
@@ -5,13 +5,18 @@ from __future__ import annotations
|
||||
import json
|
||||
from collections.abc import Callable, Iterator, Sequence
|
||||
from json import JSONDecodeError
|
||||
from typing import Any, Literal, TypeAlias
|
||||
from typing import Any, Literal, TypeAlias, cast
|
||||
|
||||
import openai
|
||||
from langchain_core.callbacks import (
|
||||
CallbackManagerForLLMRun,
|
||||
)
|
||||
from langchain_core.language_models import LangSmithParams, LanguageModelInput
|
||||
from langchain_core.language_models import (
|
||||
LangSmithParams,
|
||||
LanguageModelInput,
|
||||
ModelProfile,
|
||||
ModelProfileRegistry,
|
||||
)
|
||||
from langchain_core.messages import AIMessage, AIMessageChunk, BaseMessage
|
||||
from langchain_core.outputs import ChatGenerationChunk, ChatResult
|
||||
from langchain_core.runnables import Runnable
|
||||
@@ -21,6 +26,8 @@ from langchain_openai.chat_models.base import BaseChatOpenAI
|
||||
from pydantic import BaseModel, ConfigDict, Field, SecretStr, model_validator
|
||||
from typing_extensions import Self
|
||||
|
||||
from langchain_deepseek.data._profiles import _PROFILES
|
||||
|
||||
DEFAULT_API_BASE = "https://api.deepseek.com/v1"
|
||||
DEFAULT_BETA_API_BASE = "https://api.deepseek.com/beta"
|
||||
|
||||
@@ -28,6 +35,14 @@ _DictOrPydanticClass: TypeAlias = dict[str, Any] | type[BaseModel]
|
||||
_DictOrPydantic: TypeAlias = dict[str, Any] | BaseModel
|
||||
|
||||
|
||||
_MODEL_PROFILES = cast("ModelProfileRegistry", _PROFILES)
|
||||
|
||||
|
||||
def _get_default_model_profile(model_name: str) -> ModelProfile:
|
||||
default = _MODEL_PROFILES.get(model_name) or {}
|
||||
return default.copy()
|
||||
|
||||
|
||||
class ChatDeepSeek(BaseChatOpenAI):
|
||||
"""DeepSeek chat model integration to access models hosted in DeepSeek's API.
|
||||
|
||||
@@ -232,6 +247,13 @@ class ChatDeepSeek(BaseChatOpenAI):
|
||||
self.async_client = self.root_async_client.chat.completions
|
||||
return self
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _set_model_profile(self) -> Self:
|
||||
"""Set model profile if not overridden."""
|
||||
if self.profile is None:
|
||||
self.profile = _get_default_model_profile(self.model_name)
|
||||
return self
|
||||
|
||||
def _get_request_payload(
|
||||
self,
|
||||
input_: LanguageModelInput,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
"""Model profile data. All edits should be made in profile_augmentations.toml."""
|
||||
43
libs/partners/deepseek/langchain_deepseek/data/_profiles.py
Normal file
43
libs/partners/deepseek/langchain_deepseek/data/_profiles.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""Auto-generated model profiles.
|
||||
|
||||
DO NOT EDIT THIS FILE MANUALLY.
|
||||
This file is generated by the langchain-profiles CLI tool.
|
||||
|
||||
It contains data derived from the models.dev project.
|
||||
|
||||
Source: https://github.com/sst/models.dev
|
||||
License: MIT License
|
||||
|
||||
To update these data, refer to the instructions here:
|
||||
|
||||
https://docs.langchain.com/oss/python/langchain/models#updating-or-overwriting-profile-data
|
||||
"""
|
||||
|
||||
from typing import Any
|
||||
|
||||
_PROFILES: dict[str, dict[str, Any]] = {
|
||||
"deepseek-chat": {
|
||||
"max_input_tokens": 128000,
|
||||
"max_output_tokens": 8192,
|
||||
"image_inputs": False,
|
||||
"audio_inputs": False,
|
||||
"video_inputs": False,
|
||||
"image_outputs": False,
|
||||
"audio_outputs": False,
|
||||
"video_outputs": False,
|
||||
"reasoning_output": False,
|
||||
"tool_calling": True,
|
||||
},
|
||||
"deepseek-reasoner": {
|
||||
"max_input_tokens": 128000,
|
||||
"max_output_tokens": 128000,
|
||||
"image_inputs": False,
|
||||
"audio_inputs": False,
|
||||
"video_inputs": False,
|
||||
"image_outputs": False,
|
||||
"audio_outputs": False,
|
||||
"video_outputs": False,
|
||||
"reasoning_output": True,
|
||||
"tool_calling": True,
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user