1
0
mirror of https://github.com/hwchase17/langchain.git synced 2025-05-08 00:28:47 +00:00
This commit is contained in:
Erick Friis 2025-02-04 18:21:28 -08:00
parent 3b441f312a
commit 07b1ccb230
2 changed files with 21 additions and 1 deletions
libs
partners/openai/langchain_openai/chat_models
standard-tests/langchain_tests/unit_tests

View File

@ -440,7 +440,7 @@ class BaseChatOpenAI(BaseChatModel):
async_client: Any = Field(default=None, exclude=True) #: :meta private:
root_client: Any = Field(default=None, exclude=True) #: :meta private:
root_async_client: Any = Field(default=None, exclude=True) #: :meta private:
model_name: str = Field(default="gpt-3.5-turbo", alias="model")
model: str = Field(default="gpt-3.5-turbo", alias="model_name")
"""Model name to use."""
temperature: Optional[float] = None
"""What sampling temperature to use."""
@ -545,6 +545,10 @@ class BaseChatOpenAI(BaseChatModel):
model_config = ConfigDict(populate_by_name=True)
@property
def model_name(self) -> str:
return self.model
@model_validator(mode="before")
@classmethod
def build_extra(cls, values: Dict[str, Any]) -> Any:

View File

@ -534,6 +534,22 @@ class ChatModelUnitTests(ChatModelTests):
If this test fails, ensure that the model can be initialized with a
``model`` parameter, and that the model parameter can be accessed as
``.model``.
If not, the easiest way to configure this is likely to add
``from pydantic import ConfigDict`` at the top of your file, and add a
``model_config`` class attribute to your model class:
.. code-block:: python
class MyChatModel(BaseChatModel):
model: str = Field(alias="model_name")
model_config = ConfigDict(populate_by_name=True)
# optional property for backwards-compatibility
# for folks accessing chat_model.model_name
@property
def model_name(self) -> str:
return self.model
"""
params = {
**self.standard_chat_model_params,