diff --git a/libs/cli/langchain_cli/integration_template/integration_template/chat_models.py b/libs/cli/langchain_cli/integration_template/integration_template/chat_models.py index 917feb2df0b..9939fe71f5d 100644 --- a/libs/cli/langchain_cli/integration_template/integration_template/chat_models.py +++ b/libs/cli/langchain_cli/integration_template/integration_template/chat_models.py @@ -13,7 +13,7 @@ from langchain_core.messages import ( ) from langchain_core.messages.ai import UsageMetadata from langchain_core.outputs import ChatGeneration, ChatGenerationChunk, ChatResult -from pydantic import Field +from pydantic import ConfigDict, Field class Chat__ModuleName__(BaseChatModel): @@ -266,7 +266,7 @@ class Chat__ModuleName__(BaseChatModel): """ # noqa: E501 - model_name: str = Field(alias="model") + model: str = Field(alias="model_name") """The name of the model""" parrot_buffer_length: int """The number of characters from the last message of the prompt to be echoed.""" @@ -276,6 +276,10 @@ class Chat__ModuleName__(BaseChatModel): stop: Optional[List[str]] = None max_retries: int = 2 + model_config = ConfigDict( + populate_by_name=True, + ) + @property def _llm_type(self) -> str: """Return type of chat model.""" @@ -293,7 +297,7 @@ class Chat__ModuleName__(BaseChatModel): # rules in LLM monitoring applications (e.g., in LangSmith users # can provide per token pricing for their model and monitor # costs for the given LLM.) - "model_name": self.model_name, + "model": self.model, } def _generate( diff --git a/libs/standard-tests/tests/unit_tests/custom_chat_model.py b/libs/standard-tests/tests/unit_tests/custom_chat_model.py index 1791138cf35..032d69b6406 100644 --- a/libs/standard-tests/tests/unit_tests/custom_chat_model.py +++ b/libs/standard-tests/tests/unit_tests/custom_chat_model.py @@ -11,7 +11,7 @@ from langchain_core.messages import ( ) from langchain_core.messages.ai import UsageMetadata from langchain_core.outputs import ChatGeneration, ChatGenerationChunk, ChatResult -from pydantic import Field +from pydantic import ConfigDict, Field class ChatParrotLink(BaseChatModel): @@ -33,7 +33,7 @@ class ChatParrotLink(BaseChatModel): [HumanMessage(content="world")]]) """ - model_name: str = Field(alias="model") + model: str = Field(alias="model_name") """The name of the model""" parrot_buffer_length: int """The number of characters from the last message of the prompt to be echoed.""" @@ -43,6 +43,10 @@ class ChatParrotLink(BaseChatModel): stop: Optional[List[str]] = None max_retries: int = 2 + model_config = ConfigDict( + populate_by_name=True, + ) + def _generate( self, messages: List[BaseMessage], @@ -163,5 +167,5 @@ class ChatParrotLink(BaseChatModel): # rules in LLM monitoring applications (e.g., in LangSmith users # can provide per token pricing for their model and monitor # costs for the given LLM.) - "model_name": self.model_name, + "model": self.model, }