From 4d28c70000e3845a6f162f322d7fafeb57713e38 Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Tue, 6 Aug 2024 22:53:50 -0400 Subject: [PATCH] core[patch]: Sort Config attributes (#25127) This PR does an aesthetic sort of the config object attributes. This will make it a bit easier to go back and forth between pydantic v1 and pydantic v2 on the 0.3.x branch --- .../example_selectors/semantic_similarity.py | 4 +--- .../langchain_core/language_models/chat_models.py | 2 -- libs/core/langchain_core/language_models/llms.py | 2 -- libs/core/langchain_core/memory.py | 2 -- libs/core/langchain_core/prompts/base.py | 2 -- libs/core/langchain_core/prompts/few_shot.py | 12 +++--------- .../prompts/few_shot_with_templates.py | 4 +--- libs/core/langchain_core/retrievers.py | 2 -- libs/core/langchain_core/tools.py | 2 -- libs/core/langchain_core/vectorstores/base.py | 2 -- 10 files changed, 5 insertions(+), 29 deletions(-) diff --git a/libs/core/langchain_core/example_selectors/semantic_similarity.py b/libs/core/langchain_core/example_selectors/semantic_similarity.py index b4d8d0cc1c6..c14428a0c11 100644 --- a/libs/core/langchain_core/example_selectors/semantic_similarity.py +++ b/libs/core/langchain_core/example_selectors/semantic_similarity.py @@ -43,10 +43,8 @@ class _VectorStoreExampleSelector(BaseExampleSelector, BaseModel, ABC): """Extra arguments passed to similarity_search function of the vectorstore.""" class Config: - """Configuration for this pydantic object.""" - - extra = Extra.forbid arbitrary_types_allowed = True + extra = Extra.forbid @staticmethod def _example_to_text( diff --git a/libs/core/langchain_core/language_models/chat_models.py b/libs/core/langchain_core/language_models/chat_models.py index bc6630858a3..b4d367572a1 100644 --- a/libs/core/langchain_core/language_models/chat_models.py +++ b/libs/core/langchain_core/language_models/chat_models.py @@ -236,8 +236,6 @@ class BaseChatModel(BaseLanguageModel[BaseMessage], ABC): return values class Config: - """Configuration for this pydantic object.""" - arbitrary_types_allowed = True # --- Runnable methods --- diff --git a/libs/core/langchain_core/language_models/llms.py b/libs/core/langchain_core/language_models/llms.py index 1b1e014a8ef..03ae2be5e23 100644 --- a/libs/core/langchain_core/language_models/llms.py +++ b/libs/core/langchain_core/language_models/llms.py @@ -298,8 +298,6 @@ class BaseLLM(BaseLanguageModel[str], ABC): """[DEPRECATED]""" class Config: - """Configuration for this pydantic object.""" - arbitrary_types_allowed = True @root_validator(pre=True) diff --git a/libs/core/langchain_core/memory.py b/libs/core/langchain_core/memory.py index 34a90d879e3..743c68b68b6 100644 --- a/libs/core/langchain_core/memory.py +++ b/libs/core/langchain_core/memory.py @@ -48,8 +48,6 @@ class BaseMemory(Serializable, ABC): """ # noqa: E501 class Config: - """Configuration for this pydantic object.""" - arbitrary_types_allowed = True @property diff --git a/libs/core/langchain_core/prompts/base.py b/libs/core/langchain_core/prompts/base.py index a58f916d4aa..8ba8e560711 100644 --- a/libs/core/langchain_core/prompts/base.py +++ b/libs/core/langchain_core/prompts/base.py @@ -100,8 +100,6 @@ class BasePromptTemplate( return True class Config: - """Configuration for this pydantic object.""" - arbitrary_types_allowed = True @property diff --git a/libs/core/langchain_core/prompts/few_shot.py b/libs/core/langchain_core/prompts/few_shot.py index d750851f468..934ac88a81a 100644 --- a/libs/core/langchain_core/prompts/few_shot.py +++ b/libs/core/langchain_core/prompts/few_shot.py @@ -33,10 +33,8 @@ class _FewShotPromptTemplateMixin(BaseModel): Either this or examples should be provided.""" class Config: - """Configuration for this pydantic object.""" - - extra = Extra.forbid arbitrary_types_allowed = True + extra = Extra.forbid @root_validator(pre=True) def check_examples_and_selector(cls, values: Dict) -> Dict: @@ -161,10 +159,8 @@ class FewShotPromptTemplate(_FewShotPromptTemplateMixin, StringPromptTemplate): return values class Config: - """Configuration for this pydantic object.""" - - extra = Extra.forbid arbitrary_types_allowed = True + extra = Extra.forbid def format(self, **kwargs: Any) -> str: """Format the prompt with inputs generating a string. @@ -370,10 +366,8 @@ class FewShotChatMessagePromptTemplate( return False class Config: - """Configuration for this pydantic object.""" - - extra = Extra.forbid arbitrary_types_allowed = True + extra = Extra.forbid def format_messages(self, **kwargs: Any) -> List[BaseMessage]: """Format kwargs into a list of messages. diff --git a/libs/core/langchain_core/prompts/few_shot_with_templates.py b/libs/core/langchain_core/prompts/few_shot_with_templates.py index 8e5db1a81fa..6b98694d44b 100644 --- a/libs/core/langchain_core/prompts/few_shot_with_templates.py +++ b/libs/core/langchain_core/prompts/few_shot_with_templates.py @@ -86,10 +86,8 @@ class FewShotPromptWithTemplates(StringPromptTemplate): return values class Config: - """Configuration for this pydantic object.""" - - extra = Extra.forbid arbitrary_types_allowed = True + extra = Extra.forbid def _get_examples(self, **kwargs: Any) -> List[dict]: if self.examples is not None: diff --git a/libs/core/langchain_core/retrievers.py b/libs/core/langchain_core/retrievers.py index efce96bdade..6bbf34072b7 100644 --- a/libs/core/langchain_core/retrievers.py +++ b/libs/core/langchain_core/retrievers.py @@ -112,8 +112,6 @@ class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC): """ # noqa: E501 class Config: - """Configuration for this pydantic object.""" - arbitrary_types_allowed = True _new_arg_supported: bool = False diff --git a/libs/core/langchain_core/tools.py b/libs/core/langchain_core/tools.py index 729d68ffc3b..98a86b0aaf1 100644 --- a/libs/core/langchain_core/tools.py +++ b/libs/core/langchain_core/tools.py @@ -374,8 +374,6 @@ class ChildTool(BaseTool): super().__init__(**kwargs) class Config(Serializable.Config): - """Configuration for this pydantic object.""" - arbitrary_types_allowed = True @property diff --git a/libs/core/langchain_core/vectorstores/base.py b/libs/core/langchain_core/vectorstores/base.py index 88688894969..f6f3f37772d 100644 --- a/libs/core/langchain_core/vectorstores/base.py +++ b/libs/core/langchain_core/vectorstores/base.py @@ -1208,8 +1208,6 @@ class VectorStoreRetriever(BaseRetriever): ) class Config: - """Configuration for this pydantic object.""" - arbitrary_types_allowed = True @root_validator(pre=True)