From c172f972eadf0660ce6ab0550322dfdb858ffe3e Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Mon, 14 Aug 2023 09:37:32 -0400 Subject: [PATCH] Create pydantic v1 namespace, add partial compatibility for pydantic v2 (#9123) First of a few PRs to add full compatibility to both pydantic v1 and v2. This PR creates pydantic v1 namespace and adds it to sys.modules. Upcoming changes: 1. Handle `openapi-schema-pydantic = "^1.2"` and dependent chains/tools 2. bump dependencies to versions that are cross compatible for pydantic or remove them (see below) 3. Add tests to github workflows to test with pydantic v1 and v2 **Dependencies** From a quick look (could be wrong since was done manually) **dependencies pinning pydantic below 2** (some of these can be bumped to newer versions are provide cross-compatible code) anthropic bentoml confection fastapi langsmith octoai-sdk openapi-schema-pydantic qdrant-client spacy steamship thinc zep-python Unpinned marqo (*) nomic (*) xinference(*) --- libs/langchain/langchain/__init__.py | 23 +++++++++- libs/langchain/langchain/agents/agent.py | 2 +- .../agents/agent_toolkits/amadeus/toolkit.py | 2 +- .../azure_cognitive_services.py | 2 +- .../langchain/agents/agent_toolkits/base.py | 2 +- .../agent_toolkits/file_management/toolkit.py | 5 ++- .../agents/agent_toolkits/gmail/toolkit.py | 2 +- .../agents/agent_toolkits/nla/toolkit.py | 2 +- .../agent_toolkits/office365/toolkit.py | 2 +- .../agents/agent_toolkits/openapi/planner.py | 2 +- .../agent_toolkits/playwright/toolkit.py | 2 +- .../agents/agent_toolkits/powerbi/toolkit.py | 2 +- .../agent_toolkits/spark_sql/toolkit.py | 2 +- .../agents/agent_toolkits/sql/toolkit.py | 2 +- .../agent_toolkits/vectorstore/toolkit.py | 2 +- libs/langchain/langchain/agents/chat/base.py | 2 +- .../langchain/agents/conversational/base.py | 2 +- .../agents/conversational_chat/base.py | 2 +- libs/langchain/langchain/agents/mrkl/base.py | 2 +- .../agents/openai_functions_agent/base.py | 2 +- .../openai_functions_multi_agent/base.py | 2 +- libs/langchain/langchain/agents/react/base.py | 2 +- .../agents/self_ask_with_search/base.py | 2 +- .../langchain/agents/structured_chat/base.py | 2 +- .../agents/structured_chat/output_parser.py | 2 +- .../langchain/callbacks/tracers/schemas.py | 2 +- libs/langchain/langchain/chains/api/base.py | 2 +- .../langchain/chains/api/openapi/chain.py | 2 +- libs/langchain/langchain/chains/base.py | 2 +- .../chains/combine_documents/base.py | 2 +- .../chains/combine_documents/map_reduce.py | 2 +- .../chains/combine_documents/map_rerank.py | 2 +- .../chains/combine_documents/reduce.py | 2 +- .../chains/combine_documents/refine.py | 2 +- .../chains/combine_documents/stuff.py | 2 +- .../chains/constitutional_ai/models.py | 2 +- .../langchain/chains/conversation/base.py | 2 +- .../chains/conversational_retrieval/base.py | 2 +- .../chains/elasticsearch_database/base.py | 2 +- libs/langchain/langchain/chains/flare/base.py | 2 +- .../langchain/chains/graph_qa/arangodb.py | 2 +- .../langchain/chains/graph_qa/base.py | 2 +- .../langchain/chains/graph_qa/cypher.py | 2 +- .../langchain/chains/graph_qa/hugegraph.py | 2 +- .../langchain/chains/graph_qa/kuzu.py | 2 +- .../langchain/chains/graph_qa/nebulagraph.py | 2 +- .../chains/graph_qa/neptune_cypher.py | 2 +- .../langchain/chains/graph_qa/sparql.py | 2 +- libs/langchain/langchain/chains/hyde/base.py | 2 +- libs/langchain/langchain/chains/llm.py | 2 +- .../langchain/chains/llm_bash/base.py | 2 +- .../langchain/chains/llm_checker/base.py | 2 +- .../langchain/chains/llm_math/base.py | 2 +- .../langchain/chains/llm_requests.py | 2 +- .../chains/llm_summarization_checker/base.py | 2 +- .../chains/llm_symbolic_math/base.py | 2 +- libs/langchain/langchain/chains/mapreduce.py | 2 +- libs/langchain/langchain/chains/moderation.py | 2 +- .../langchain/langchain/chains/natbot/base.py | 2 +- .../langchain/chains/openai_functions/base.py | 14 +++--- .../openai_functions/citation_fuzzy_match.py | 2 +- .../chains/openai_functions/extraction.py | 2 +- .../openai_functions/qa_with_structure.py | 2 +- .../langchain/chains/prompt_selector.py | 2 +- .../langchain/chains/qa_generation/base.py | 2 +- .../langchain/chains/qa_with_sources/base.py | 2 +- .../chains/qa_with_sources/retrieval.py | 2 +- .../chains/qa_with_sources/vector_db.py | 2 +- .../langchain/chains/query_constructor/ir.py | 2 +- .../chains/query_constructor/schema.py | 2 +- .../langchain/chains/retrieval_qa/base.py | 2 +- .../langchain/langchain/chains/router/base.py | 2 +- .../chains/router/embedding_router.py | 2 +- .../langchain/chains/router/llm_router.py | 2 +- libs/langchain/langchain/chains/sequential.py | 2 +- libs/langchain/langchain/chains/transform.py | 2 +- .../langchain/chat_models/anyscale.py | 2 +- .../langchain/chat_models/azure_openai.py | 2 +- .../langchain/chat_models/azureml_endpoint.py | 2 +- libs/langchain/langchain/chat_models/base.py | 2 +- .../langchain/chat_models/google_palm.py | 2 +- libs/langchain/langchain/chat_models/human.py | 2 +- .../langchain/chat_models/jinachat.py | 2 +- .../chat_models/mlflow_ai_gateway.py | 6 ++- .../langchain/langchain/chat_models/openai.py | 2 +- .../langchain/chat_models/vertexai.py | 2 +- .../document_loaders/apify_dataset.py | 2 +- .../document_loaders/blob_loaders/schema.py | 2 +- .../langchain/document_loaders/docugami.py | 2 +- .../langchain/document_loaders/dropbox.py | 2 +- .../langchain/document_loaders/embaas.py | 2 +- .../langchain/document_loaders/github.py | 2 +- .../langchain/document_loaders/googledrive.py | 2 +- .../langchain/document_loaders/onedrive.py | 2 +- .../document_loaders/onedrive_file.py | 2 +- .../langchain/document_loaders/youtube.py | 4 +- .../embeddings_redundant_filter.py | 2 +- .../long_context_reorder.py | 2 +- .../document_transformers/openai_functions.py | 2 +- .../langchain/embeddings/aleph_alpha.py | 2 +- libs/langchain/langchain/embeddings/awa.py | 2 +- .../langchain/langchain/embeddings/bedrock.py | 2 +- .../langchain/embeddings/clarifai.py | 2 +- libs/langchain/langchain/embeddings/cohere.py | 2 +- .../langchain/embeddings/dashscope.py | 2 +- .../langchain/embeddings/deepinfra.py | 2 +- libs/langchain/langchain/embeddings/edenai.py | 2 +- libs/langchain/langchain/embeddings/embaas.py | 2 +- libs/langchain/langchain/embeddings/fake.py | 2 +- .../langchain/embeddings/google_palm.py | 2 +- .../langchain/langchain/embeddings/gpt4all.py | 2 +- .../langchain/embeddings/huggingface.py | 2 +- .../langchain/embeddings/huggingface_hub.py | 2 +- libs/langchain/langchain/embeddings/jina.py | 2 +- .../langchain/embeddings/llamacpp.py | 2 +- .../langchain/langchain/embeddings/localai.py | 2 +- .../langchain/langchain/embeddings/minimax.py | 2 +- .../langchain/embeddings/mlflow_gateway.py | 2 +- .../langchain/embeddings/modelscope_hub.py | 2 +- .../langchain/embeddings/mosaicml.py | 2 +- .../langchain/embeddings/nlpcloud.py | 2 +- .../langchain/embeddings/octoai_embeddings.py | 2 +- libs/langchain/langchain/embeddings/openai.py | 2 +- .../embeddings/sagemaker_endpoint.py | 2 +- .../langchain/embeddings/self_hosted.py | 2 +- .../langchain/embeddings/spacy_embeddings.py | 2 +- .../langchain/embeddings/tensorflow_hub.py | 2 +- .../langchain/embeddings/vertexai.py | 2 +- .../agents/trajectory_eval_chain.py | 2 +- .../evaluation/comparison/eval_chain.py | 2 +- .../evaluation/criteria/eval_chain.py | 2 +- .../evaluation/embedding_distance/base.py | 2 +- .../langchain/evaluation/qa/eval_chain.py | 2 +- .../langchain/evaluation/qa/generate_chain.py | 2 +- .../evaluation/string_distance/base.py | 2 +- libs/langchain/langchain/indexes/graph.py | 2 +- .../langchain/indexes/vectorstore.py | 2 +- libs/langchain/langchain/llms/ai21.py | 2 +- libs/langchain/langchain/llms/aleph_alpha.py | 2 +- .../langchain/llms/amazon_api_gateway.py | 2 +- libs/langchain/langchain/llms/anthropic.py | 2 +- libs/langchain/langchain/llms/anyscale.py | 2 +- libs/langchain/langchain/llms/aviary.py | 2 +- .../langchain/llms/azureml_endpoint.py | 2 +- libs/langchain/langchain/llms/bananadev.py | 2 +- libs/langchain/langchain/llms/base.py | 2 +- libs/langchain/langchain/llms/baseten.py | 2 +- libs/langchain/langchain/llms/beam.py | 2 +- libs/langchain/langchain/llms/bedrock.py | 2 +- libs/langchain/langchain/llms/cerebriumai.py | 2 +- libs/langchain/langchain/llms/clarifai.py | 2 +- libs/langchain/langchain/llms/cohere.py | 2 +- .../langchain/langchain/llms/ctransformers.py | 2 +- libs/langchain/langchain/llms/databricks.py | 2 +- libs/langchain/langchain/llms/deepinfra.py | 2 +- libs/langchain/langchain/llms/edenai.py | 2 +- libs/langchain/langchain/llms/fireworks.py | 2 +- libs/langchain/langchain/llms/forefrontai.py | 2 +- libs/langchain/langchain/llms/google_palm.py | 2 +- libs/langchain/langchain/llms/gooseai.py | 2 +- libs/langchain/langchain/llms/gpt4all.py | 2 +- .../langchain/llms/huggingface_endpoint.py | 2 +- .../langchain/llms/huggingface_hub.py | 2 +- .../langchain/llms/huggingface_pipeline.py | 2 +- .../llms/huggingface_text_gen_inference.py | 2 +- libs/langchain/langchain/llms/human.py | 2 +- libs/langchain/langchain/llms/llamacpp.py | 2 +- libs/langchain/langchain/llms/manifest.py | 2 +- libs/langchain/langchain/llms/minimax.py | 2 +- .../langchain/llms/mlflow_ai_gateway.py | 6 ++- libs/langchain/langchain/llms/modal.py | 2 +- libs/langchain/langchain/llms/mosaicml.py | 2 +- libs/langchain/langchain/llms/nlpcloud.py | 2 +- .../langchain/llms/octoai_endpoint.py | 2 +- libs/langchain/langchain/llms/ollama.py | 2 +- libs/langchain/langchain/llms/openai.py | 2 +- libs/langchain/langchain/llms/openllm.py | 2 +- libs/langchain/langchain/llms/openlm.py | 2 +- libs/langchain/langchain/llms/petals.py | 2 +- libs/langchain/langchain/llms/pipelineai.py | 2 +- libs/langchain/langchain/llms/predibase.py | 2 +- .../langchain/llms/predictionguard.py | 2 +- libs/langchain/langchain/llms/replicate.py | 2 +- libs/langchain/langchain/llms/rwkv.py | 2 +- .../langchain/llms/sagemaker_endpoint.py | 2 +- libs/langchain/langchain/llms/self_hosted.py | 2 +- .../llms/self_hosted_hugging_face.py | 2 +- libs/langchain/langchain/llms/stochasticai.py | 2 +- .../langchain/llms/symblai_nebula.py | 2 +- libs/langchain/langchain/llms/textgen.py | 2 +- libs/langchain/langchain/llms/tongyi.py | 2 +- libs/langchain/langchain/llms/vertexai.py | 2 +- libs/langchain/langchain/llms/vllm.py | 2 +- libs/langchain/langchain/llms/writer.py | 2 +- libs/langchain/langchain/load/serializable.py | 2 +- libs/langchain/langchain/memory/buffer.py | 2 +- .../langchain/langchain/memory/chat_memory.py | 2 +- .../chat_message_histories/in_memory.py | 2 +- libs/langchain/langchain/memory/combined.py | 2 +- libs/langchain/langchain/memory/entity.py | 2 +- libs/langchain/langchain/memory/kg.py | 2 +- libs/langchain/langchain/memory/summary.py | 2 +- .../langchain/memory/summary_buffer.py | 2 +- .../langchain/langchain/memory/vectorstore.py | 2 +- .../langchain/output_parsers/combining.py | 2 +- .../langchain/output_parsers/enum.py | 2 +- .../output_parsers/openai_functions.py | 2 +- .../langchain/output_parsers/pydantic.py | 2 +- .../langchain/output_parsers/structured.py | 2 +- libs/langchain/langchain/prompts/chat.py | 17 +++++-- .../prompts/example_selector/length_based.py | 2 +- .../prompts/example_selector/ngram_overlap.py | 2 +- .../example_selector/semantic_similarity.py | 2 +- libs/langchain/langchain/prompts/few_shot.py | 2 +- .../prompts/few_shot_with_templates.py | 2 +- libs/langchain/langchain/prompts/loading.py | 5 ++- libs/langchain/langchain/prompts/pipeline.py | 2 +- libs/langchain/langchain/prompts/prompt.py | 2 +- .../retrievers/azure_cognitive_search.py | 2 +- .../retrievers/document_compressors/base.py | 2 +- .../document_compressors/cohere_rerank.py | 2 +- .../document_compressors/embeddings_filter.py | 2 +- .../langchain/retrievers/ensemble.py | 2 +- .../google_cloud_enterprise_search.py | 2 +- libs/langchain/langchain/retrievers/kendra.py | 31 ++++++++----- .../langchain/retrievers/llama_index.py | 2 +- libs/langchain/langchain/retrievers/metal.py | 2 +- libs/langchain/langchain/retrievers/milvus.py | 2 +- .../langchain/retrievers/multi_query.py | 2 +- .../retrievers/pinecone_hybrid_search.py | 2 +- .../langchain/retrievers/self_query/base.py | 2 +- .../retrievers/time_weighted_retriever.py | 2 +- .../retrievers/weaviate_hybrid_search.py | 2 +- .../langchain/retrievers/web_research.py | 2 +- libs/langchain/langchain/retrievers/zep.py | 2 +- libs/langchain/langchain/retrievers/zilliz.py | 2 +- .../langchain/runnables/openai_functions.py | 2 +- libs/langchain/langchain/schema/document.py | 2 +- libs/langchain/langchain/schema/messages.py | 2 +- libs/langchain/langchain/schema/output.py | 2 +- .../langchain/schema/prompt_template.py | 2 +- .../langchain/schema/runnable/base.py | 2 +- .../langchain/smith/evaluation/config.py | 2 +- .../langchain/langchain/tools/amadeus/base.py | 2 +- .../tools/amadeus/closest_airport.py | 2 +- .../langchain/tools/amadeus/flight_search.py | 2 +- libs/langchain/langchain/tools/arxiv/tool.py | 2 +- .../form_recognizer.py | 2 +- .../image_analysis.py | 2 +- .../azure_cognitive_services/speech2text.py | 2 +- .../azure_cognitive_services/text2speech.py | 2 +- libs/langchain/langchain/tools/base.py | 12 ++++- .../tools/dataforseo_api_search/tool.py | 2 +- .../langchain/tools/ddg_search/tool.py | 2 +- .../langchain/tools/file_management/copy.py | 2 +- .../langchain/tools/file_management/delete.py | 2 +- .../tools/file_management/file_search.py | 2 +- .../tools/file_management/list_dir.py | 2 +- .../langchain/tools/file_management/move.py | 2 +- .../langchain/tools/file_management/read.py | 2 +- .../langchain/tools/file_management/utils.py | 2 +- .../langchain/tools/file_management/write.py | 2 +- libs/langchain/langchain/tools/github/tool.py | 2 +- libs/langchain/langchain/tools/gmail/base.py | 2 +- .../langchain/tools/gmail/create_draft.py | 2 +- .../langchain/tools/gmail/get_message.py | 2 +- .../langchain/tools/gmail/get_thread.py | 2 +- .../langchain/langchain/tools/gmail/search.py | 2 +- .../langchain/tools/gmail/send_message.py | 2 +- .../langchain/tools/google_places/tool.py | 2 +- .../langchain/tools/google_serper/tool.py | 2 +- libs/langchain/langchain/tools/human/tool.py | 2 +- libs/langchain/langchain/tools/jira/tool.py | 2 +- libs/langchain/langchain/tools/json/tool.py | 2 +- .../langchain/tools/multion/create_session.py | 2 +- .../langchain/tools/multion/update_session.py | 2 +- libs/langchain/langchain/tools/nuclia/tool.py | 2 +- .../langchain/tools/office365/base.py | 2 +- .../tools/office365/create_draft_message.py | 2 +- .../tools/office365/events_search.py | 2 +- .../tools/office365/messages_search.py | 2 +- .../langchain/tools/office365/send_event.py | 2 +- .../langchain/tools/office365/send_message.py | 2 +- .../tools/openapi/utils/api_models.py | 2 +- .../langchain/tools/openweathermap/tool.py | 2 +- .../langchain/tools/playwright/base.py | 2 +- .../langchain/tools/playwright/click.py | 2 +- .../tools/playwright/current_page.py | 2 +- .../tools/playwright/extract_hyperlinks.py | 2 +- .../tools/playwright/extract_text.py | 2 +- .../tools/playwright/get_elements.py | 2 +- .../langchain/tools/playwright/navigate.py | 2 +- .../tools/playwright/navigate_back.py | 2 +- libs/langchain/langchain/tools/plugin.py | 2 +- .../langchain/langchain/tools/powerbi/tool.py | 2 +- libs/langchain/langchain/tools/pubmed/tool.py | 2 +- libs/langchain/langchain/tools/python/tool.py | 2 +- .../langchain/tools/requests/tool.py | 2 +- .../langchain/tools/scenexplain/tool.py | 2 +- .../langchain/tools/searx_search/tool.py | 2 +- libs/langchain/langchain/tools/shell/tool.py | 2 +- libs/langchain/langchain/tools/sleep/tool.py | 2 +- .../langchain/tools/spark_sql/tool.py | 2 +- .../langchain/tools/sql_database/tool.py | 2 +- .../tools/steamship_image_generation/tool.py | 2 +- .../langchain/tools/vectorstore/tool.py | 2 +- libs/langchain/langchain/tools/zapier/tool.py | 2 +- libs/langchain/langchain/utilities/arxiv.py | 2 +- .../langchain/utilities/awslambda.py | 2 +- libs/langchain/langchain/utilities/bibtex.py | 2 +- .../langchain/utilities/bing_search.py | 2 +- .../langchain/utilities/brave_search.py | 2 +- .../utilities/dalle_image_generator.py | 2 +- .../utilities/dataforseo_api_search.py | 2 +- .../langchain/utilities/duckduckgo_search.py | 4 +- libs/langchain/langchain/utilities/github.py | 2 +- .../langchain/utilities/golden_query.py | 2 +- .../langchain/utilities/google_places_api.py | 2 +- .../langchain/utilities/google_search.py | 2 +- .../langchain/utilities/google_serper.py | 4 +- libs/langchain/langchain/utilities/graphql.py | 2 +- libs/langchain/langchain/utilities/jira.py | 2 +- .../langchain/utilities/metaphor_search.py | 2 +- libs/langchain/langchain/utilities/openapi.py | 2 +- .../langchain/utilities/openweathermap.py | 2 +- libs/langchain/langchain/utilities/powerbi.py | 2 +- libs/langchain/langchain/utilities/pubmed.py | 4 +- libs/langchain/langchain/utilities/python.py | 2 +- .../langchain/langchain/utilities/requests.py | 2 +- .../langchain/utilities/scenexplain.py | 2 +- .../langchain/utilities/searx_search.py | 2 +- libs/langchain/langchain/utilities/serpapi.py | 2 +- .../utilities/tensorflow_datasets.py | 2 +- libs/langchain/langchain/utilities/twilio.py | 2 +- .../langchain/utilities/wikipedia.py | 2 +- .../langchain/utilities/wolfram_alpha.py | 2 +- libs/langchain/langchain/utilities/zapier.py | 2 +- libs/langchain/langchain/utils/pydantic.py | 14 ++++++ .../langchain/vectorstores/azuresearch.py | 2 +- libs/langchain/langchain/vectorstores/base.py | 2 +- .../langchain/vectorstores/clickhouse.py | 2 +- .../langchain/vectorstores/docarray/base.py | 2 +- .../langchain/vectorstores/myscale.py | 2 +- .../langchain/langchain/vectorstores/redis.py | 2 +- .../langchain/vectorstores/starrocks.py | 2 +- .../langchain/vectorstores/vectara.py | 2 +- .../test_tensorflow_datasets.py | 2 +- .../retrievers/docarray/fixtures.py | 2 +- .../utilities/test_tensorflow_datasets.py | 2 +- .../tests/mock_servers/robot/server.py | 2 +- .../tests/unit_tests/_api/test_deprecation.py | 2 +- .../callbacks/fake_callback_handler.py | 2 +- .../evaluation/agents/test_eval_chain.py | 2 +- .../tests/unit_tests/llms/fake_llm.py | 2 +- .../output_parsers/test_pydantic_parser.py | 2 +- .../tests/unit_tests/schema/test_runnable.py | 45 ++++++++++++++++--- .../langchain/tests/unit_tests/test_schema.py | 33 ++++++-------- .../tests/unit_tests/tools/test_base.py | 2 +- 358 files changed, 509 insertions(+), 402 deletions(-) create mode 100644 libs/langchain/langchain/utils/pydantic.py diff --git a/libs/langchain/langchain/__init__.py b/libs/langchain/langchain/__init__.py index 00935e0288..fe82bc343f 100644 --- a/libs/langchain/langchain/__init__.py +++ b/libs/langchain/langchain/__init__.py @@ -1,8 +1,28 @@ +# ruff: noqa: E402 """Main entrypoint into package.""" - +import importlib +import sys from importlib import metadata from typing import Optional +## Create namespaces for pydantic v1 and v2. +# This code must stay at the top of the file before other modules may +# attempt to import pydantic since it adds pydantic_v1 and pydantic_v2 to sys.modules. +# +# This hack is done for the following reasons: +# * Langchain will attempt to remain compatible with both pydantic v1 and v2 since +# both dependencies and dependents may be stuck on either version of v1 or v2. +# * Creating namespaces for pydantic v1 and v2 should allow us to write code that +# unambiguously uses either v1 or v2 API. +# * This change is easier to roll out and roll back. + +try: + pydantic_v1 = importlib.import_module("pydantic.v1") +except ImportError: + pydantic_v1 = importlib.import_module("pydantic") + +sys.modules["pydantic_v1"] = pydantic_v1 + from langchain.agents import MRKLChain, ReActChain, SelfAskWithSearchChain from langchain.cache import BaseCache from langchain.chains import ( @@ -67,6 +87,7 @@ llm_cache: Optional[BaseCache] = None # For backwards compatibility SerpAPIChain = SerpAPIWrapper + __all__ = [ "LLMChain", "LLMBashChain", diff --git a/libs/langchain/langchain/agents/agent.py b/libs/langchain/langchain/agents/agent.py index 9ac57726fd..3935d05252 100644 --- a/libs/langchain/langchain/agents/agent.py +++ b/libs/langchain/langchain/agents/agent.py @@ -10,7 +10,7 @@ from pathlib import Path from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import yaml -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.agents.agent_iterator import AgentExecutorIterator from langchain.agents.agent_types import AgentType diff --git a/libs/langchain/langchain/agents/agent_toolkits/amadeus/toolkit.py b/libs/langchain/langchain/agents/agent_toolkits/amadeus/toolkit.py index 28db53bdcb..652d71211f 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/amadeus/toolkit.py +++ b/libs/langchain/langchain/agents/agent_toolkits/amadeus/toolkit.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, List -from pydantic import Field +from pydantic_v1 import Field from langchain.agents.agent_toolkits.base import BaseToolkit from langchain.tools import BaseTool diff --git a/libs/langchain/langchain/agents/agent_toolkits/azure_cognitive_services.py b/libs/langchain/langchain/agents/agent_toolkits/azure_cognitive_services.py index 366444707a..c733927cd4 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/azure_cognitive_services.py +++ b/libs/langchain/langchain/agents/agent_toolkits/azure_cognitive_services.py @@ -19,7 +19,7 @@ class AzureCognitiveServicesToolkit(BaseToolkit): def get_tools(self) -> List[BaseTool]: """Get the tools in the toolkit.""" - tools = [ + tools: List[BaseTool] = [ AzureCogsFormRecognizerTool(), AzureCogsSpeech2TextTool(), AzureCogsText2SpeechTool(), diff --git a/libs/langchain/langchain/agents/agent_toolkits/base.py b/libs/langchain/langchain/agents/agent_toolkits/base.py index f8624cf7e7..580354d6e2 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/base.py +++ b/libs/langchain/langchain/agents/agent_toolkits/base.py @@ -2,7 +2,7 @@ from abc import ABC, abstractmethod from typing import List -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.tools import BaseTool diff --git a/libs/langchain/langchain/agents/agent_toolkits/file_management/toolkit.py b/libs/langchain/langchain/agents/agent_toolkits/file_management/toolkit.py index c78a37c18a..25232d37e9 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/file_management/toolkit.py +++ b/libs/langchain/langchain/agents/agent_toolkits/file_management/toolkit.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import List, Optional -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.agents.agent_toolkits.base import BaseToolkit from langchain.tools import BaseTool @@ -15,7 +15,8 @@ from langchain.tools.file_management.read import ReadFileTool from langchain.tools.file_management.write import WriteFileTool _FILE_TOOLS = { - tool_cls.__fields__["name"].default: tool_cls + # "Type[Runnable[Any, Any]]" has no attribute "__fields__" [attr-defined] + tool_cls.__fields__["name"].default: tool_cls # type: ignore[attr-defined] for tool_cls in [ CopyFileTool, DeleteFileTool, diff --git a/libs/langchain/langchain/agents/agent_toolkits/gmail/toolkit.py b/libs/langchain/langchain/agents/agent_toolkits/gmail/toolkit.py index e95f2e6862..096d32c0d1 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/gmail/toolkit.py +++ b/libs/langchain/langchain/agents/agent_toolkits/gmail/toolkit.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, List -from pydantic import Field +from pydantic_v1 import Field from langchain.agents.agent_toolkits.base import BaseToolkit from langchain.tools import BaseTool diff --git a/libs/langchain/langchain/agents/agent_toolkits/nla/toolkit.py b/libs/langchain/langchain/agents/agent_toolkits/nla/toolkit.py index 523b392954..314e041932 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/nla/toolkit.py +++ b/libs/langchain/langchain/agents/agent_toolkits/nla/toolkit.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Any, List, Optional, Sequence -from pydantic import Field +from pydantic_v1 import Field from langchain.agents.agent_toolkits.base import BaseToolkit from langchain.agents.agent_toolkits.nla.tool import NLATool diff --git a/libs/langchain/langchain/agents/agent_toolkits/office365/toolkit.py b/libs/langchain/langchain/agents/agent_toolkits/office365/toolkit.py index 3e3151e780..536ce7307b 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/office365/toolkit.py +++ b/libs/langchain/langchain/agents/agent_toolkits/office365/toolkit.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, List -from pydantic import Field +from pydantic_v1 import Field from langchain.agents.agent_toolkits.base import BaseToolkit from langchain.tools import BaseTool diff --git a/libs/langchain/langchain/agents/agent_toolkits/openapi/planner.py b/libs/langchain/langchain/agents/agent_toolkits/openapi/planner.py index 5a5e920e2c..3dcecc2fe5 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/openapi/planner.py +++ b/libs/langchain/langchain/agents/agent_toolkits/openapi/planner.py @@ -5,7 +5,7 @@ from functools import partial from typing import Any, Callable, Dict, List, Optional import yaml -from pydantic import Field +from pydantic_v1 import Field from langchain.agents.agent import AgentExecutor from langchain.agents.agent_toolkits.openapi.planner_prompt import ( diff --git a/libs/langchain/langchain/agents/agent_toolkits/playwright/toolkit.py b/libs/langchain/langchain/agents/agent_toolkits/playwright/toolkit.py index af010e1e22..b8ef6407f8 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/playwright/toolkit.py +++ b/libs/langchain/langchain/agents/agent_toolkits/playwright/toolkit.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, List, Optional, Type, cast -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.agents.agent_toolkits.base import BaseToolkit from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/agents/agent_toolkits/powerbi/toolkit.py b/libs/langchain/langchain/agents/agent_toolkits/powerbi/toolkit.py index e7e66c6a41..0caa237733 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/powerbi/toolkit.py +++ b/libs/langchain/langchain/agents/agent_toolkits/powerbi/toolkit.py @@ -1,7 +1,7 @@ """Toolkit for interacting with a Power BI dataset.""" from typing import List, Optional, Union -from pydantic import Field +from pydantic_v1 import Field from langchain.agents.agent_toolkits.base import BaseToolkit from langchain.callbacks.base import BaseCallbackManager diff --git a/libs/langchain/langchain/agents/agent_toolkits/spark_sql/toolkit.py b/libs/langchain/langchain/agents/agent_toolkits/spark_sql/toolkit.py index 7c89c7dc5f..8b94dfb501 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/spark_sql/toolkit.py +++ b/libs/langchain/langchain/agents/agent_toolkits/spark_sql/toolkit.py @@ -1,7 +1,7 @@ """Toolkit for interacting with Spark SQL.""" from typing import List -from pydantic import Field +from pydantic_v1 import Field from langchain.agents.agent_toolkits.base import BaseToolkit from langchain.schema.language_model import BaseLanguageModel diff --git a/libs/langchain/langchain/agents/agent_toolkits/sql/toolkit.py b/libs/langchain/langchain/agents/agent_toolkits/sql/toolkit.py index 5fe6e07863..2e851f625d 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/sql/toolkit.py +++ b/libs/langchain/langchain/agents/agent_toolkits/sql/toolkit.py @@ -1,7 +1,7 @@ """Toolkit for interacting with an SQL database.""" from typing import List -from pydantic import Field +from pydantic_v1 import Field from langchain.agents.agent_toolkits.base import BaseToolkit from langchain.schema.language_model import BaseLanguageModel diff --git a/libs/langchain/langchain/agents/agent_toolkits/vectorstore/toolkit.py b/libs/langchain/langchain/agents/agent_toolkits/vectorstore/toolkit.py index f706ed215b..557c2619e7 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/vectorstore/toolkit.py +++ b/libs/langchain/langchain/agents/agent_toolkits/vectorstore/toolkit.py @@ -1,7 +1,7 @@ """Toolkit for interacting with a vector store.""" from typing import List -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.agents.agent_toolkits.base import BaseToolkit from langchain.llms.openai import OpenAI diff --git a/libs/langchain/langchain/agents/chat/base.py b/libs/langchain/langchain/agents/chat/base.py index 3217ff1fbb..cf871ad94e 100644 --- a/libs/langchain/langchain/agents/chat/base.py +++ b/libs/langchain/langchain/agents/chat/base.py @@ -1,6 +1,6 @@ from typing import Any, List, Optional, Sequence, Tuple -from pydantic import Field +from pydantic_v1 import Field from langchain.agents.agent import Agent, AgentOutputParser from langchain.agents.chat.output_parser import ChatOutputParser diff --git a/libs/langchain/langchain/agents/conversational/base.py b/libs/langchain/langchain/agents/conversational/base.py index 6b9b939410..324059f98b 100644 --- a/libs/langchain/langchain/agents/conversational/base.py +++ b/libs/langchain/langchain/agents/conversational/base.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any, List, Optional, Sequence -from pydantic import Field +from pydantic_v1 import Field from langchain.agents.agent import Agent, AgentOutputParser from langchain.agents.agent_types import AgentType diff --git a/libs/langchain/langchain/agents/conversational_chat/base.py b/libs/langchain/langchain/agents/conversational_chat/base.py index 1ffb7ff124..521c67caf4 100644 --- a/libs/langchain/langchain/agents/conversational_chat/base.py +++ b/libs/langchain/langchain/agents/conversational_chat/base.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any, List, Optional, Sequence, Tuple -from pydantic import Field +from pydantic_v1 import Field from langchain.agents.agent import Agent, AgentOutputParser from langchain.agents.conversational_chat.output_parser import ConvoOutputParser diff --git a/libs/langchain/langchain/agents/mrkl/base.py b/libs/langchain/langchain/agents/mrkl/base.py index a3939cbeec..90b6d35167 100644 --- a/libs/langchain/langchain/agents/mrkl/base.py +++ b/libs/langchain/langchain/agents/mrkl/base.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any, Callable, List, NamedTuple, Optional, Sequence -from pydantic import Field +from pydantic_v1 import Field from langchain.agents.agent import Agent, AgentExecutor, AgentOutputParser from langchain.agents.agent_types import AgentType diff --git a/libs/langchain/langchain/agents/openai_functions_agent/base.py b/libs/langchain/langchain/agents/openai_functions_agent/base.py index f3e2fc095c..52e74c96d3 100644 --- a/libs/langchain/langchain/agents/openai_functions_agent/base.py +++ b/libs/langchain/langchain/agents/openai_functions_agent/base.py @@ -4,7 +4,7 @@ from dataclasses import dataclass from json import JSONDecodeError from typing import Any, List, Optional, Sequence, Tuple, Union -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.agents import BaseSingleActionAgent from langchain.callbacks.base import BaseCallbackManager diff --git a/libs/langchain/langchain/agents/openai_functions_multi_agent/base.py b/libs/langchain/langchain/agents/openai_functions_multi_agent/base.py index 8cf16d8122..b80cfc0194 100644 --- a/libs/langchain/langchain/agents/openai_functions_multi_agent/base.py +++ b/libs/langchain/langchain/agents/openai_functions_multi_agent/base.py @@ -4,7 +4,7 @@ from dataclasses import dataclass from json import JSONDecodeError from typing import Any, List, Optional, Sequence, Tuple, Union -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.agents import BaseMultiActionAgent from langchain.callbacks.base import BaseCallbackManager diff --git a/libs/langchain/langchain/agents/react/base.py b/libs/langchain/langchain/agents/react/base.py index db4d67370a..f2d3687c9a 100644 --- a/libs/langchain/langchain/agents/react/base.py +++ b/libs/langchain/langchain/agents/react/base.py @@ -1,7 +1,7 @@ """Chain that implements the ReAct paper from https://arxiv.org/pdf/2210.03629.pdf.""" from typing import Any, List, Optional, Sequence -from pydantic import Field +from pydantic_v1 import Field from langchain.agents.agent import Agent, AgentExecutor, AgentOutputParser from langchain.agents.agent_types import AgentType diff --git a/libs/langchain/langchain/agents/self_ask_with_search/base.py b/libs/langchain/langchain/agents/self_ask_with_search/base.py index 23071af8c9..db4c09230a 100644 --- a/libs/langchain/langchain/agents/self_ask_with_search/base.py +++ b/libs/langchain/langchain/agents/self_ask_with_search/base.py @@ -1,7 +1,7 @@ """Chain that does self-ask with search.""" from typing import Any, Sequence, Union -from pydantic import Field +from pydantic_v1 import Field from langchain.agents.agent import Agent, AgentExecutor, AgentOutputParser from langchain.agents.agent_types import AgentType diff --git a/libs/langchain/langchain/agents/structured_chat/base.py b/libs/langchain/langchain/agents/structured_chat/base.py index 8e0eb3725f..3650fb89a5 100644 --- a/libs/langchain/langchain/agents/structured_chat/base.py +++ b/libs/langchain/langchain/agents/structured_chat/base.py @@ -1,7 +1,7 @@ import re from typing import Any, List, Optional, Sequence, Tuple -from pydantic import Field +from pydantic_v1 import Field from langchain.agents.agent import Agent, AgentOutputParser from langchain.agents.structured_chat.output_parser import ( diff --git a/libs/langchain/langchain/agents/structured_chat/output_parser.py b/libs/langchain/langchain/agents/structured_chat/output_parser.py index 5b1b598aca..a73492204b 100644 --- a/libs/langchain/langchain/agents/structured_chat/output_parser.py +++ b/libs/langchain/langchain/agents/structured_chat/output_parser.py @@ -5,7 +5,7 @@ import logging import re from typing import Optional, Union -from pydantic import Field +from pydantic_v1 import Field from langchain.agents.agent import AgentOutputParser from langchain.agents.structured_chat.prompt import FORMAT_INSTRUCTIONS diff --git a/libs/langchain/langchain/callbacks/tracers/schemas.py b/libs/langchain/langchain/callbacks/tracers/schemas.py index 41061e7364..6e7de65b8f 100644 --- a/libs/langchain/langchain/callbacks/tracers/schemas.py +++ b/libs/langchain/langchain/callbacks/tracers/schemas.py @@ -8,7 +8,7 @@ from uuid import UUID from langsmith.schemas import RunBase as BaseRunV2 from langsmith.schemas import RunTypeEnum as RunTypeEnumDep -from pydantic import BaseModel, Field, root_validator +from pydantic_v1 import BaseModel, Field, root_validator from langchain.schema import LLMResult diff --git a/libs/langchain/langchain/chains/api/base.py b/libs/langchain/langchain/chains/api/base.py index d3e548f395..b8c841b289 100644 --- a/libs/langchain/langchain/chains/api/base.py +++ b/libs/langchain/langchain/chains/api/base.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForChainRun, diff --git a/libs/langchain/langchain/chains/api/openapi/chain.py b/libs/langchain/langchain/chains/api/openapi/chain.py index d3bf442d5c..14ca4abc58 100644 --- a/libs/langchain/langchain/chains/api/openapi/chain.py +++ b/libs/langchain/langchain/chains/api/openapi/chain.py @@ -4,7 +4,7 @@ from __future__ import annotations import json from typing import Any, Dict, List, NamedTuple, Optional, cast -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from requests import Response from langchain.callbacks.manager import CallbackManagerForChainRun, Callbacks diff --git a/libs/langchain/langchain/chains/base.py b/libs/langchain/langchain/chains/base.py index bfdee82249..e4ea0d37f0 100644 --- a/libs/langchain/langchain/chains/base.py +++ b/libs/langchain/langchain/chains/base.py @@ -10,7 +10,7 @@ from pathlib import Path from typing import Any, Dict, List, Optional, Union import yaml -from pydantic import Field, root_validator, validator +from pydantic_v1 import Field, root_validator, validator import langchain from langchain.callbacks.base import BaseCallbackManager diff --git a/libs/langchain/langchain/chains/combine_documents/base.py b/libs/langchain/langchain/chains/combine_documents/base.py index 0693aac44a..43805382a9 100644 --- a/libs/langchain/langchain/chains/combine_documents/base.py +++ b/libs/langchain/langchain/chains/combine_documents/base.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from typing import Any, Dict, List, Optional, Tuple -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import ( AsyncCallbackManagerForChainRun, diff --git a/libs/langchain/langchain/chains/combine_documents/map_reduce.py b/libs/langchain/langchain/chains/combine_documents/map_reduce.py index 9afed3e7e8..9b38ceaa17 100644 --- a/libs/langchain/langchain/chains/combine_documents/map_reduce.py +++ b/libs/langchain/langchain/chains/combine_documents/map_reduce.py @@ -4,7 +4,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional, Tuple -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import Callbacks from langchain.chains.combine_documents.base import BaseCombineDocumentsChain diff --git a/libs/langchain/langchain/chains/combine_documents/map_rerank.py b/libs/langchain/langchain/chains/combine_documents/map_rerank.py index e2d656d07e..afc12fe6bb 100644 --- a/libs/langchain/langchain/chains/combine_documents/map_rerank.py +++ b/libs/langchain/langchain/chains/combine_documents/map_rerank.py @@ -4,7 +4,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional, Sequence, Tuple, Union, cast -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import Callbacks from langchain.chains.combine_documents.base import BaseCombineDocumentsChain diff --git a/libs/langchain/langchain/chains/combine_documents/reduce.py b/libs/langchain/langchain/chains/combine_documents/reduce.py index b70f301ed2..3475d8c25a 100644 --- a/libs/langchain/langchain/chains/combine_documents/reduce.py +++ b/libs/langchain/langchain/chains/combine_documents/reduce.py @@ -4,7 +4,7 @@ from __future__ import annotations from typing import Any, Callable, List, Optional, Protocol, Tuple -from pydantic import Extra +from pydantic_v1 import Extra from langchain.callbacks.manager import Callbacks from langchain.chains.combine_documents.base import BaseCombineDocumentsChain diff --git a/libs/langchain/langchain/chains/combine_documents/refine.py b/libs/langchain/langchain/chains/combine_documents/refine.py index 025e264165..628b0ceba0 100644 --- a/libs/langchain/langchain/chains/combine_documents/refine.py +++ b/libs/langchain/langchain/chains/combine_documents/refine.py @@ -4,7 +4,7 @@ from __future__ import annotations from typing import Any, Dict, List, Tuple -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import Callbacks from langchain.chains.combine_documents.base import ( diff --git a/libs/langchain/langchain/chains/combine_documents/stuff.py b/libs/langchain/langchain/chains/combine_documents/stuff.py index 996a5ef713..0670fb63f2 100644 --- a/libs/langchain/langchain/chains/combine_documents/stuff.py +++ b/libs/langchain/langchain/chains/combine_documents/stuff.py @@ -2,7 +2,7 @@ from typing import Any, Dict, List, Optional, Tuple -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import Callbacks from langchain.chains.combine_documents.base import ( diff --git a/libs/langchain/langchain/chains/constitutional_ai/models.py b/libs/langchain/langchain/chains/constitutional_ai/models.py index 912b23a6f9..6431828108 100644 --- a/libs/langchain/langchain/chains/constitutional_ai/models.py +++ b/libs/langchain/langchain/chains/constitutional_ai/models.py @@ -1,5 +1,5 @@ """Models for the Constitutional AI chain.""" -from pydantic import BaseModel +from pydantic_v1 import BaseModel class ConstitutionalPrinciple(BaseModel): diff --git a/libs/langchain/langchain/chains/conversation/base.py b/libs/langchain/langchain/chains/conversation/base.py index 43d72f91e7..e55bbf3e55 100644 --- a/libs/langchain/langchain/chains/conversation/base.py +++ b/libs/langchain/langchain/chains/conversation/base.py @@ -1,7 +1,7 @@ """Chain that carries on a conversation and calls an LLM.""" from typing import Dict, List -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.chains.conversation.prompt import PROMPT from langchain.chains.llm import LLMChain diff --git a/libs/langchain/langchain/chains/conversational_retrieval/base.py b/libs/langchain/langchain/chains/conversational_retrieval/base.py index 7f6891ff22..eb1e396c62 100644 --- a/libs/langchain/langchain/chains/conversational_retrieval/base.py +++ b/libs/langchain/langchain/chains/conversational_retrieval/base.py @@ -7,7 +7,7 @@ from abc import abstractmethod from pathlib import Path from typing import Any, Callable, Dict, List, Optional, Tuple, Union -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForChainRun, diff --git a/libs/langchain/langchain/chains/elasticsearch_database/base.py b/libs/langchain/langchain/chains/elasticsearch_database/base.py index 17f8ddcdb7..956aac7812 100644 --- a/libs/langchain/langchain/chains/elasticsearch_database/base.py +++ b/libs/langchain/langchain/chains/elasticsearch_database/base.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, Any, Dict, List, Optional -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain diff --git a/libs/langchain/langchain/chains/flare/base.py b/libs/langchain/langchain/chains/flare/base.py index 11595dda4f..e3008c3330 100644 --- a/libs/langchain/langchain/chains/flare/base.py +++ b/libs/langchain/langchain/chains/flare/base.py @@ -5,7 +5,7 @@ from abc import abstractmethod from typing import Any, Dict, List, Optional, Sequence, Tuple import numpy as np -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import ( CallbackManagerForChainRun, diff --git a/libs/langchain/langchain/chains/graph_qa/arangodb.py b/libs/langchain/langchain/chains/graph_qa/arangodb.py index 42eba0b34f..f9d4fb382f 100644 --- a/libs/langchain/langchain/chains/graph_qa/arangodb.py +++ b/libs/langchain/langchain/chains/graph_qa/arangodb.py @@ -4,7 +4,7 @@ from __future__ import annotations import re from typing import Any, Dict, List, Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.base_language import BaseLanguageModel from langchain.callbacks.manager import CallbackManagerForChainRun diff --git a/libs/langchain/langchain/chains/graph_qa/base.py b/libs/langchain/langchain/chains/graph_qa/base.py index 428104496e..24e076a2ad 100644 --- a/libs/langchain/langchain/chains/graph_qa/base.py +++ b/libs/langchain/langchain/chains/graph_qa/base.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain diff --git a/libs/langchain/langchain/chains/graph_qa/cypher.py b/libs/langchain/langchain/chains/graph_qa/cypher.py index a3852dc705..f6faffe639 100644 --- a/libs/langchain/langchain/chains/graph_qa/cypher.py +++ b/libs/langchain/langchain/chains/graph_qa/cypher.py @@ -4,7 +4,7 @@ from __future__ import annotations import re from typing import Any, Dict, List, Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain diff --git a/libs/langchain/langchain/chains/graph_qa/hugegraph.py b/libs/langchain/langchain/chains/graph_qa/hugegraph.py index a1f2f6b815..4c3577bd7a 100644 --- a/libs/langchain/langchain/chains/graph_qa/hugegraph.py +++ b/libs/langchain/langchain/chains/graph_qa/hugegraph.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain diff --git a/libs/langchain/langchain/chains/graph_qa/kuzu.py b/libs/langchain/langchain/chains/graph_qa/kuzu.py index e532fa64ca..f5750e4d04 100644 --- a/libs/langchain/langchain/chains/graph_qa/kuzu.py +++ b/libs/langchain/langchain/chains/graph_qa/kuzu.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain diff --git a/libs/langchain/langchain/chains/graph_qa/nebulagraph.py b/libs/langchain/langchain/chains/graph_qa/nebulagraph.py index 9cfcc960a4..487efedd3a 100644 --- a/libs/langchain/langchain/chains/graph_qa/nebulagraph.py +++ b/libs/langchain/langchain/chains/graph_qa/nebulagraph.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain diff --git a/libs/langchain/langchain/chains/graph_qa/neptune_cypher.py b/libs/langchain/langchain/chains/graph_qa/neptune_cypher.py index ae7baa9b21..e8d6ddf6fe 100644 --- a/libs/langchain/langchain/chains/graph_qa/neptune_cypher.py +++ b/libs/langchain/langchain/chains/graph_qa/neptune_cypher.py @@ -3,7 +3,7 @@ from __future__ import annotations import re from typing import Any, Dict, List, Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.base_language import BaseLanguageModel from langchain.callbacks.manager import CallbackManagerForChainRun diff --git a/libs/langchain/langchain/chains/graph_qa/sparql.py b/libs/langchain/langchain/chains/graph_qa/sparql.py index f1a8ff1f8e..3efef4f252 100644 --- a/libs/langchain/langchain/chains/graph_qa/sparql.py +++ b/libs/langchain/langchain/chains/graph_qa/sparql.py @@ -5,7 +5,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain diff --git a/libs/langchain/langchain/chains/hyde/base.py b/libs/langchain/langchain/chains/hyde/base.py index 1fb2f3ac4c..62d11cf729 100644 --- a/libs/langchain/langchain/chains/hyde/base.py +++ b/libs/langchain/langchain/chains/hyde/base.py @@ -7,7 +7,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional import numpy as np -from pydantic import Extra +from pydantic_v1 import Extra from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain diff --git a/libs/langchain/langchain/chains/llm.py b/libs/langchain/langchain/chains/llm.py index 18029309b6..6d6f679433 100644 --- a/libs/langchain/langchain/chains/llm.py +++ b/libs/langchain/langchain/chains/llm.py @@ -4,7 +4,7 @@ from __future__ import annotations import warnings from typing import Any, Dict, List, Optional, Sequence, Tuple, Union -from pydantic import Extra, Field +from pydantic_v1 import Extra, Field from langchain.callbacks.manager import ( AsyncCallbackManager, diff --git a/libs/langchain/langchain/chains/llm_bash/base.py b/libs/langchain/langchain/chains/llm_bash/base.py index 2c7cadf838..19c0b1356b 100644 --- a/libs/langchain/langchain/chains/llm_bash/base.py +++ b/libs/langchain/langchain/chains/llm_bash/base.py @@ -5,7 +5,7 @@ import logging import warnings from typing import Any, Dict, List, Optional -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain diff --git a/libs/langchain/langchain/chains/llm_checker/base.py b/libs/langchain/langchain/chains/llm_checker/base.py index e32a93fc4a..f72df0e986 100644 --- a/libs/langchain/langchain/chains/llm_checker/base.py +++ b/libs/langchain/langchain/chains/llm_checker/base.py @@ -4,7 +4,7 @@ from __future__ import annotations import warnings from typing import Any, Dict, List, Optional -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain diff --git a/libs/langchain/langchain/chains/llm_math/base.py b/libs/langchain/langchain/chains/llm_math/base.py index b5e92620d4..39cb8cc6a4 100644 --- a/libs/langchain/langchain/chains/llm_math/base.py +++ b/libs/langchain/langchain/chains/llm_math/base.py @@ -7,7 +7,7 @@ import warnings from typing import Any, Dict, List, Optional import numexpr -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForChainRun, diff --git a/libs/langchain/langchain/chains/llm_requests.py b/libs/langchain/langchain/chains/llm_requests.py index 2e1a6dd430..3920e397b5 100644 --- a/libs/langchain/langchain/chains/llm_requests.py +++ b/libs/langchain/langchain/chains/llm_requests.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains import LLMChain diff --git a/libs/langchain/langchain/chains/llm_summarization_checker/base.py b/libs/langchain/langchain/chains/llm_summarization_checker/base.py index 30e7f8ea85..b3f9bdd4fb 100644 --- a/libs/langchain/langchain/chains/llm_summarization_checker/base.py +++ b/libs/langchain/langchain/chains/llm_summarization_checker/base.py @@ -6,7 +6,7 @@ import warnings from pathlib import Path from typing import Any, Dict, List, Optional -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain diff --git a/libs/langchain/langchain/chains/llm_symbolic_math/base.py b/libs/langchain/langchain/chains/llm_symbolic_math/base.py index 8193085b4f..95fba36464 100644 --- a/libs/langchain/langchain/chains/llm_symbolic_math/base.py +++ b/libs/langchain/langchain/chains/llm_symbolic_math/base.py @@ -4,7 +4,7 @@ from __future__ import annotations import re from typing import Any, Dict, List, Optional -from pydantic import Extra +from pydantic_v1 import Extra from langchain.base_language import BaseLanguageModel from langchain.callbacks.manager import ( diff --git a/libs/langchain/langchain/chains/mapreduce.py b/libs/langchain/langchain/chains/mapreduce.py index e7ba46ba60..d404f6afc9 100644 --- a/libs/langchain/langchain/chains/mapreduce.py +++ b/libs/langchain/langchain/chains/mapreduce.py @@ -7,7 +7,7 @@ from __future__ import annotations from typing import Any, Dict, List, Mapping, Optional -from pydantic import Extra +from pydantic_v1 import Extra from langchain.callbacks.manager import CallbackManagerForChainRun, Callbacks from langchain.chains import ReduceDocumentsChain diff --git a/libs/langchain/langchain/chains/moderation.py b/libs/langchain/langchain/chains/moderation.py index e59dfa0cf6..c07eda1477 100644 --- a/libs/langchain/langchain/chains/moderation.py +++ b/libs/langchain/langchain/chains/moderation.py @@ -1,7 +1,7 @@ """Pass input through a moderation endpoint.""" from typing import Any, Dict, List, Optional -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain diff --git a/libs/langchain/langchain/chains/natbot/base.py b/libs/langchain/langchain/chains/natbot/base.py index 2adcea4fd7..8eec84d0d2 100644 --- a/libs/langchain/langchain/chains/natbot/base.py +++ b/libs/langchain/langchain/chains/natbot/base.py @@ -4,7 +4,7 @@ from __future__ import annotations import warnings from typing import Any, Dict, List, Optional -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain diff --git a/libs/langchain/langchain/chains/openai_functions/base.py b/libs/langchain/langchain/chains/openai_functions/base.py index ad457d537c..bbef94d4da 100644 --- a/libs/langchain/langchain/chains/openai_functions/base.py +++ b/libs/langchain/langchain/chains/openai_functions/base.py @@ -12,7 +12,7 @@ from typing import ( Union, ) -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.base_language import BaseLanguageModel from langchain.chains import LLMChain @@ -87,7 +87,9 @@ def _get_python_function_arguments(function: Callable, arg_descriptions: dict) - if arg == "return": continue if isinstance(arg_type, type) and issubclass(arg_type, BaseModel): - properties[arg] = arg_type.schema() + # Mypy error: + # "type" has no attribute "schema" + properties[arg] = arg_type.schema() # type: ignore[attr-defined] elif arg_type.__name__ in PYTHON_TO_JSON_TYPES: properties[arg] = {"type": PYTHON_TO_JSON_TYPES[arg_type.__name__]} if arg in arg_descriptions: @@ -147,7 +149,9 @@ def convert_to_openai_function( if isinstance(function, dict): return function elif isinstance(function, type) and issubclass(function, BaseModel): - schema = function.schema() + # Mypy error: + # "type" has no attribute "schema" + schema = function.schema() # type: ignore[attr-defined] return { "name": schema["title"], "description": schema["description"], @@ -224,7 +228,7 @@ def create_openai_fn_chain( from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate - from pydantic import BaseModel, Field + from pydantic_v1 import BaseModel, Field class RecordPerson(BaseModel): @@ -310,7 +314,7 @@ def create_structured_output_chain( from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate - from pydantic import BaseModel, Field + from pydantic_v1 import BaseModel, Field class Dog(BaseModel): \"\"\"Identifying information about a dog.\"\"\" diff --git a/libs/langchain/langchain/chains/openai_functions/citation_fuzzy_match.py b/libs/langchain/langchain/chains/openai_functions/citation_fuzzy_match.py index 2ea974d331..def8414a26 100644 --- a/libs/langchain/langchain/chains/openai_functions/citation_fuzzy_match.py +++ b/libs/langchain/langchain/chains/openai_functions/citation_fuzzy_match.py @@ -1,6 +1,6 @@ from typing import Iterator, List -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.chains.llm import LLMChain from langchain.chains.openai_functions.utils import get_llm_kwargs diff --git a/libs/langchain/langchain/chains/openai_functions/extraction.py b/libs/langchain/langchain/chains/openai_functions/extraction.py index ab4528ca86..f1eb13790f 100644 --- a/libs/langchain/langchain/chains/openai_functions/extraction.py +++ b/libs/langchain/langchain/chains/openai_functions/extraction.py @@ -1,6 +1,6 @@ from typing import Any, List -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.chains.base import Chain from langchain.chains.llm import LLMChain diff --git a/libs/langchain/langchain/chains/openai_functions/qa_with_structure.py b/libs/langchain/langchain/chains/openai_functions/qa_with_structure.py index b65296436b..21a6bfa338 100644 --- a/libs/langchain/langchain/chains/openai_functions/qa_with_structure.py +++ b/libs/langchain/langchain/chains/openai_functions/qa_with_structure.py @@ -1,6 +1,6 @@ from typing import Any, List, Optional, Type, Union -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.chains.llm import LLMChain from langchain.chains.openai_functions.utils import get_llm_kwargs diff --git a/libs/langchain/langchain/chains/prompt_selector.py b/libs/langchain/langchain/chains/prompt_selector.py index d2f6c0554b..e39124c5e6 100644 --- a/libs/langchain/langchain/chains/prompt_selector.py +++ b/libs/langchain/langchain/chains/prompt_selector.py @@ -1,7 +1,7 @@ from abc import ABC, abstractmethod from typing import Callable, List, Tuple -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.chat_models.base import BaseChatModel from langchain.llms.base import BaseLLM diff --git a/libs/langchain/langchain/chains/qa_generation/base.py b/libs/langchain/langchain/chains/qa_generation/base.py index e5efc3d73e..142f6670cc 100644 --- a/libs/langchain/langchain/chains/qa_generation/base.py +++ b/libs/langchain/langchain/chains/qa_generation/base.py @@ -3,7 +3,7 @@ from __future__ import annotations import json from typing import Any, Dict, List, Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain diff --git a/libs/langchain/langchain/chains/qa_with_sources/base.py b/libs/langchain/langchain/chains/qa_with_sources/base.py index d0f762afbd..46eb141932 100644 --- a/libs/langchain/langchain/chains/qa_with_sources/base.py +++ b/libs/langchain/langchain/chains/qa_with_sources/base.py @@ -7,7 +7,7 @@ import re from abc import ABC, abstractmethod from typing import Any, Dict, List, Optional -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForChainRun, diff --git a/libs/langchain/langchain/chains/qa_with_sources/retrieval.py b/libs/langchain/langchain/chains/qa_with_sources/retrieval.py index beb36322c9..da67bdc5d8 100644 --- a/libs/langchain/langchain/chains/qa_with_sources/retrieval.py +++ b/libs/langchain/langchain/chains/qa_with_sources/retrieval.py @@ -2,7 +2,7 @@ from typing import Any, Dict, List -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import ( AsyncCallbackManagerForChainRun, diff --git a/libs/langchain/langchain/chains/qa_with_sources/vector_db.py b/libs/langchain/langchain/chains/qa_with_sources/vector_db.py index 5d1689a9b1..8f92a2749f 100644 --- a/libs/langchain/langchain/chains/qa_with_sources/vector_db.py +++ b/libs/langchain/langchain/chains/qa_with_sources/vector_db.py @@ -3,7 +3,7 @@ import warnings from typing import Any, Dict, List -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForChainRun, diff --git a/libs/langchain/langchain/chains/query_constructor/ir.py b/libs/langchain/langchain/chains/query_constructor/ir.py index 73707e589f..7bf0aa9cb0 100644 --- a/libs/langchain/langchain/chains/query_constructor/ir.py +++ b/libs/langchain/langchain/chains/query_constructor/ir.py @@ -5,7 +5,7 @@ from abc import ABC, abstractmethod from enum import Enum from typing import Any, List, Optional, Sequence, Union -from pydantic import BaseModel +from pydantic_v1 import BaseModel class Visitor(ABC): diff --git a/libs/langchain/langchain/chains/query_constructor/schema.py b/libs/langchain/langchain/chains/query_constructor/schema.py index 557ad5ea2a..90447be48c 100644 --- a/libs/langchain/langchain/chains/query_constructor/schema.py +++ b/libs/langchain/langchain/chains/query_constructor/schema.py @@ -1,4 +1,4 @@ -from pydantic import BaseModel +from pydantic_v1 import BaseModel class AttributeInfo(BaseModel): diff --git a/libs/langchain/langchain/chains/retrieval_qa/base.py b/libs/langchain/langchain/chains/retrieval_qa/base.py index e8385d6fe7..cd6faa0955 100644 --- a/libs/langchain/langchain/chains/retrieval_qa/base.py +++ b/libs/langchain/langchain/chains/retrieval_qa/base.py @@ -6,7 +6,7 @@ import warnings from abc import abstractmethod from typing import Any, Dict, List, Optional -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForChainRun, diff --git a/libs/langchain/langchain/chains/router/base.py b/libs/langchain/langchain/chains/router/base.py index 5ee6fb16a5..f8c156c331 100644 --- a/libs/langchain/langchain/chains/router/base.py +++ b/libs/langchain/langchain/chains/router/base.py @@ -4,7 +4,7 @@ from __future__ import annotations from abc import ABC from typing import Any, Dict, List, Mapping, NamedTuple, Optional -from pydantic import Extra +from pydantic_v1 import Extra from langchain.callbacks.manager import ( AsyncCallbackManagerForChainRun, diff --git a/libs/langchain/langchain/chains/router/embedding_router.py b/libs/langchain/langchain/chains/router/embedding_router.py index 53704a987a..b8d9d8d9fa 100644 --- a/libs/langchain/langchain/chains/router/embedding_router.py +++ b/libs/langchain/langchain/chains/router/embedding_router.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional, Sequence, Tuple, Type -from pydantic import Extra +from pydantic_v1 import Extra from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.router.base import RouterChain diff --git a/libs/langchain/langchain/chains/router/llm_router.py b/libs/langchain/langchain/chains/router/llm_router.py index b097864613..e5f4c69c4b 100644 --- a/libs/langchain/langchain/chains/router/llm_router.py +++ b/libs/langchain/langchain/chains/router/llm_router.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional, Type, cast -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForChainRun, diff --git a/libs/langchain/langchain/chains/sequential.py b/libs/langchain/langchain/chains/sequential.py index 26cbaf7021..7a48577fe2 100644 --- a/libs/langchain/langchain/chains/sequential.py +++ b/libs/langchain/langchain/chains/sequential.py @@ -1,7 +1,7 @@ """Chain pipeline where the outputs of one step feed directly into next.""" from typing import Any, Dict, List, Optional -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForChainRun, diff --git a/libs/langchain/langchain/chains/transform.py b/libs/langchain/langchain/chains/transform.py index b03bbe22c3..fb1965f9e8 100644 --- a/libs/langchain/langchain/chains/transform.py +++ b/libs/langchain/langchain/chains/transform.py @@ -3,7 +3,7 @@ import functools import logging from typing import Any, Awaitable, Callable, Dict, List, Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import ( AsyncCallbackManagerForChainRun, diff --git a/libs/langchain/langchain/chat_models/anyscale.py b/libs/langchain/langchain/chat_models/anyscale.py index 4362d28e0e..4426766f74 100644 --- a/libs/langchain/langchain/chat_models/anyscale.py +++ b/libs/langchain/langchain/chat_models/anyscale.py @@ -7,7 +7,7 @@ import sys from typing import TYPE_CHECKING, Optional, Set import requests -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from langchain.adapters.openai import convert_message_to_dict from langchain.chat_models.openai import ( diff --git a/libs/langchain/langchain/chat_models/azure_openai.py b/libs/langchain/langchain/chat_models/azure_openai.py index 71ca287484..7d70acc99e 100644 --- a/libs/langchain/langchain/chat_models/azure_openai.py +++ b/libs/langchain/langchain/chat_models/azure_openai.py @@ -4,7 +4,7 @@ from __future__ import annotations import logging from typing import Any, Dict, Mapping -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.chat_models.openai import ChatOpenAI from langchain.schema import ChatResult diff --git a/libs/langchain/langchain/chat_models/azureml_endpoint.py b/libs/langchain/langchain/chat_models/azureml_endpoint.py index 78a1b3b17a..bd01d39ac2 100644 --- a/libs/langchain/langchain/chat_models/azureml_endpoint.py +++ b/libs/langchain/langchain/chat_models/azureml_endpoint.py @@ -1,7 +1,7 @@ import json from typing import Any, Dict, List, Optional -from pydantic import validator +from pydantic_v1 import validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.chat_models.base import SimpleChatModel diff --git a/libs/langchain/langchain/chat_models/base.py b/libs/langchain/langchain/chat_models/base.py index 8ef1479e1f..ec2d8d3426 100644 --- a/libs/langchain/langchain/chat_models/base.py +++ b/libs/langchain/langchain/chat_models/base.py @@ -14,7 +14,7 @@ from typing import ( cast, ) -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator import langchain from langchain.callbacks.base import BaseCallbackManager diff --git a/libs/langchain/langchain/chat_models/google_palm.py b/libs/langchain/langchain/chat_models/google_palm.py index e180030e74..da450ea488 100644 --- a/libs/langchain/langchain/chat_models/google_palm.py +++ b/libs/langchain/langchain/chat_models/google_palm.py @@ -4,7 +4,7 @@ from __future__ import annotations import logging from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from tenacity import ( before_sleep_log, retry, diff --git a/libs/langchain/langchain/chat_models/human.py b/libs/langchain/langchain/chat_models/human.py index 1f9bf6eaf1..2c99ff8a1b 100644 --- a/libs/langchain/langchain/chat_models/human.py +++ b/libs/langchain/langchain/chat_models/human.py @@ -5,7 +5,7 @@ from io import StringIO from typing import Any, Callable, Dict, List, Mapping, Optional import yaml -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, diff --git a/libs/langchain/langchain/chat_models/jinachat.py b/libs/langchain/langchain/chat_models/jinachat.py index fd1225a9ff..23450c12cf 100644 --- a/libs/langchain/langchain/chat_models/jinachat.py +++ b/libs/langchain/langchain/chat_models/jinachat.py @@ -15,7 +15,7 @@ from typing import ( Union, ) -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from tenacity import ( before_sleep_log, retry, diff --git a/libs/langchain/langchain/chat_models/mlflow_ai_gateway.py b/libs/langchain/langchain/chat_models/mlflow_ai_gateway.py index 188093463c..42d4fa0d96 100644 --- a/libs/langchain/langchain/chat_models/mlflow_ai_gateway.py +++ b/libs/langchain/langchain/chat_models/mlflow_ai_gateway.py @@ -3,7 +3,7 @@ import logging from functools import partial from typing import Any, Dict, List, Mapping, Optional -from pydantic import BaseModel, Extra +from pydantic_v1 import BaseModel, Extra from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, @@ -26,7 +26,9 @@ from langchain.schema.messages import ( logger = logging.getLogger(__name__) -class ChatParams(BaseModel, extra=Extra.allow): +# Ignoring type because below is valid pydantic code +# Unexpected keyword argument "extra" for "__init_subclass__" of "object" [call-arg] +class ChatParams(BaseModel, extra=Extra.allow): # type: ignore[call-arg] """Parameters for the MLflow AI Gateway LLM.""" temperature: float = 0.0 diff --git a/libs/langchain/langchain/chat_models/openai.py b/libs/langchain/langchain/chat_models/openai.py index 56d3eec390..9b4f306db0 100644 --- a/libs/langchain/langchain/chat_models/openai.py +++ b/libs/langchain/langchain/chat_models/openai.py @@ -17,7 +17,7 @@ from typing import ( Union, ) -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from langchain.adapters.openai import convert_dict_to_message, convert_message_to_dict from langchain.callbacks.manager import ( diff --git a/libs/langchain/langchain/chat_models/vertexai.py b/libs/langchain/langchain/chat_models/vertexai.py index e7b5bfbee9..d8e5e1fd7a 100644 --- a/libs/langchain/langchain/chat_models/vertexai.py +++ b/libs/langchain/langchain/chat_models/vertexai.py @@ -2,7 +2,7 @@ from dataclasses import dataclass, field from typing import TYPE_CHECKING, Any, Dict, List, Optional -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.chat_models.base import BaseChatModel diff --git a/libs/langchain/langchain/document_loaders/apify_dataset.py b/libs/langchain/langchain/document_loaders/apify_dataset.py index 2a155424e3..b923ddac3a 100644 --- a/libs/langchain/langchain/document_loaders/apify_dataset.py +++ b/libs/langchain/langchain/document_loaders/apify_dataset.py @@ -1,6 +1,6 @@ from typing import Any, Callable, Dict, List -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader diff --git a/libs/langchain/langchain/document_loaders/blob_loaders/schema.py b/libs/langchain/langchain/document_loaders/blob_loaders/schema.py index 6548352c4c..4435075d50 100644 --- a/libs/langchain/langchain/document_loaders/blob_loaders/schema.py +++ b/libs/langchain/langchain/document_loaders/blob_loaders/schema.py @@ -13,7 +13,7 @@ from io import BufferedReader, BytesIO from pathlib import PurePath from typing import Any, Generator, Iterable, Mapping, Optional, Union -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator PathLike = Union[str, PurePath] diff --git a/libs/langchain/langchain/document_loaders/docugami.py b/libs/langchain/langchain/document_loaders/docugami.py index 23f293010b..db4c8ee7a1 100644 --- a/libs/langchain/langchain/document_loaders/docugami.py +++ b/libs/langchain/langchain/document_loaders/docugami.py @@ -6,7 +6,7 @@ from pathlib import Path from typing import Any, Dict, List, Mapping, Optional, Sequence, Union import requests -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader diff --git a/libs/langchain/langchain/document_loaders/dropbox.py b/libs/langchain/langchain/document_loaders/dropbox.py index 123956274e..1296e29b2e 100644 --- a/libs/langchain/langchain/document_loaders/dropbox.py +++ b/libs/langchain/langchain/document_loaders/dropbox.py @@ -11,7 +11,7 @@ import tempfile from pathlib import Path from typing import Any, Dict, List, Optional -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader diff --git a/libs/langchain/langchain/document_loaders/embaas.py b/libs/langchain/langchain/document_loaders/embaas.py index da8b2afe6d..9efa6c4c5a 100644 --- a/libs/langchain/langchain/document_loaders/embaas.py +++ b/libs/langchain/langchain/document_loaders/embaas.py @@ -3,7 +3,7 @@ import warnings from typing import Any, Dict, Iterator, List, Optional import requests -from pydantic import BaseModel, root_validator, validator +from pydantic_v1 import BaseModel, root_validator, validator from typing_extensions import NotRequired, TypedDict from langchain.docstore.document import Document diff --git a/libs/langchain/langchain/document_loaders/github.py b/libs/langchain/langchain/document_loaders/github.py index eaa10f0955..e5e840f810 100644 --- a/libs/langchain/langchain/document_loaders/github.py +++ b/libs/langchain/langchain/document_loaders/github.py @@ -3,7 +3,7 @@ from datetime import datetime from typing import Dict, Iterator, List, Literal, Optional, Union import requests -from pydantic import BaseModel, root_validator, validator +from pydantic_v1 import BaseModel, root_validator, validator from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader diff --git a/libs/langchain/langchain/document_loaders/googledrive.py b/libs/langchain/langchain/document_loaders/googledrive.py index dd0dde3fc3..4da466f866 100644 --- a/libs/langchain/langchain/document_loaders/googledrive.py +++ b/libs/langchain/langchain/document_loaders/googledrive.py @@ -11,7 +11,7 @@ import os from pathlib import Path from typing import Any, Dict, List, Optional, Sequence, Union -from pydantic import BaseModel, root_validator, validator +from pydantic_v1 import BaseModel, root_validator, validator from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader diff --git a/libs/langchain/langchain/document_loaders/onedrive.py b/libs/langchain/langchain/document_loaders/onedrive.py index 2da8a1c4da..87d4f3b7d0 100644 --- a/libs/langchain/langchain/document_loaders/onedrive.py +++ b/libs/langchain/langchain/document_loaders/onedrive.py @@ -8,7 +8,7 @@ from enum import Enum from pathlib import Path from typing import TYPE_CHECKING, Dict, List, Optional, Type, Union -from pydantic import BaseModel, BaseSettings, Field, FilePath, SecretStr +from pydantic_v1 import BaseModel, BaseSettings, Field, FilePath, SecretStr from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader diff --git a/libs/langchain/langchain/document_loaders/onedrive_file.py b/libs/langchain/langchain/document_loaders/onedrive_file.py index afebe2a4b0..067a618901 100644 --- a/libs/langchain/langchain/document_loaders/onedrive_file.py +++ b/libs/langchain/langchain/document_loaders/onedrive_file.py @@ -3,7 +3,7 @@ from __future__ import annotations import tempfile from typing import TYPE_CHECKING, List -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader diff --git a/libs/langchain/langchain/document_loaders/youtube.py b/libs/langchain/langchain/document_loaders/youtube.py index 99f2df56c6..9724ffda09 100644 --- a/libs/langchain/langchain/document_loaders/youtube.py +++ b/libs/langchain/langchain/document_loaders/youtube.py @@ -6,8 +6,8 @@ from pathlib import Path from typing import Any, Dict, List, Optional, Sequence, Union from urllib.parse import parse_qs, urlparse -from pydantic import root_validator -from pydantic.dataclasses import dataclass +from pydantic_v1 import root_validator +from pydantic_v1.dataclasses import dataclass from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader diff --git a/libs/langchain/langchain/document_transformers/embeddings_redundant_filter.py b/libs/langchain/langchain/document_transformers/embeddings_redundant_filter.py index a108ce7300..f3afb2871d 100644 --- a/libs/langchain/langchain/document_transformers/embeddings_redundant_filter.py +++ b/libs/langchain/langchain/document_transformers/embeddings_redundant_filter.py @@ -2,7 +2,7 @@ from typing import Any, Callable, List, Sequence import numpy as np -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.embeddings.base import Embeddings from langchain.schema import BaseDocumentTransformer, Document diff --git a/libs/langchain/langchain/document_transformers/long_context_reorder.py b/libs/langchain/langchain/document_transformers/long_context_reorder.py index 5debbed5ee..ca126534b2 100644 --- a/libs/langchain/langchain/document_transformers/long_context_reorder.py +++ b/libs/langchain/langchain/document_transformers/long_context_reorder.py @@ -1,7 +1,7 @@ """Reorder documents""" from typing import Any, List, Sequence -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.schema import BaseDocumentTransformer, Document diff --git a/libs/langchain/langchain/document_transformers/openai_functions.py b/libs/langchain/langchain/document_transformers/openai_functions.py index 8b2d11467f..bf2c136271 100644 --- a/libs/langchain/langchain/document_transformers/openai_functions.py +++ b/libs/langchain/langchain/document_transformers/openai_functions.py @@ -1,7 +1,7 @@ """Document transformers that use OpenAI Functions models""" from typing import Any, Dict, Optional, Sequence, Type, Union -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.chains.llm import LLMChain from langchain.chains.openai_functions import create_tagging_chain diff --git a/libs/langchain/langchain/embeddings/aleph_alpha.py b/libs/langchain/langchain/embeddings/aleph_alpha.py index 1f5c4b8b19..8c3c831a9e 100644 --- a/libs/langchain/langchain/embeddings/aleph_alpha.py +++ b/libs/langchain/langchain/embeddings/aleph_alpha.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.embeddings.base import Embeddings from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/embeddings/awa.py b/libs/langchain/langchain/embeddings/awa.py index d854eb2f63..44905617a3 100644 --- a/libs/langchain/langchain/embeddings/awa.py +++ b/libs/langchain/langchain/embeddings/awa.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/embeddings/bedrock.py b/libs/langchain/langchain/embeddings/bedrock.py index 9396b320c4..ef087ee207 100644 --- a/libs/langchain/langchain/embeddings/bedrock.py +++ b/libs/langchain/langchain/embeddings/bedrock.py @@ -4,7 +4,7 @@ import os from functools import partial from typing import Any, Dict, List, Optional -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/embeddings/clarifai.py b/libs/langchain/langchain/embeddings/clarifai.py index 6d97fc075e..c11e967a0a 100644 --- a/libs/langchain/langchain/embeddings/clarifai.py +++ b/libs/langchain/langchain/embeddings/clarifai.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Optional -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.embeddings.base import Embeddings from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/embeddings/cohere.py b/libs/langchain/langchain/embeddings/cohere.py index 28a3b6cc2a..f23544770a 100644 --- a/libs/langchain/langchain/embeddings/cohere.py +++ b/libs/langchain/langchain/embeddings/cohere.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.embeddings.base import Embeddings from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/embeddings/dashscope.py b/libs/langchain/langchain/embeddings/dashscope.py index 475c7a5940..5fb0c5d571 100644 --- a/libs/langchain/langchain/embeddings/dashscope.py +++ b/libs/langchain/langchain/embeddings/dashscope.py @@ -9,7 +9,7 @@ from typing import ( Optional, ) -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from requests.exceptions import HTTPError from tenacity import ( before_sleep_log, diff --git a/libs/langchain/langchain/embeddings/deepinfra.py b/libs/langchain/langchain/embeddings/deepinfra.py index 2fb15ce188..8c7a4c7ec5 100644 --- a/libs/langchain/langchain/embeddings/deepinfra.py +++ b/libs/langchain/langchain/embeddings/deepinfra.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Mapping, Optional import requests -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.embeddings.base import Embeddings from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/embeddings/edenai.py b/libs/langchain/langchain/embeddings/edenai.py index 0f3fe08d9b..59d3b28829 100644 --- a/libs/langchain/langchain/embeddings/edenai.py +++ b/libs/langchain/langchain/embeddings/edenai.py @@ -1,6 +1,6 @@ from typing import Dict, List, Optional -from pydantic import BaseModel, Extra, Field, root_validator +from pydantic_v1 import BaseModel, Extra, Field, root_validator from langchain.embeddings.base import Embeddings from langchain.requests import Requests diff --git a/libs/langchain/langchain/embeddings/embaas.py b/libs/langchain/langchain/embeddings/embaas.py index d6985fc68c..37261453c3 100644 --- a/libs/langchain/langchain/embeddings/embaas.py +++ b/libs/langchain/langchain/embeddings/embaas.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Mapping, Optional import requests -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from typing_extensions import NotRequired, TypedDict from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/embeddings/fake.py b/libs/langchain/langchain/embeddings/fake.py index 1b8311dec7..4df6b0239c 100644 --- a/libs/langchain/langchain/embeddings/fake.py +++ b/libs/langchain/langchain/embeddings/fake.py @@ -2,7 +2,7 @@ import hashlib from typing import List import numpy as np -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/embeddings/google_palm.py b/libs/langchain/langchain/embeddings/google_palm.py index 8633ce7a94..6bcec015a7 100644 --- a/libs/langchain/langchain/embeddings/google_palm.py +++ b/libs/langchain/langchain/embeddings/google_palm.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Any, Callable, Dict, List, Optional -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from tenacity import ( before_sleep_log, retry, diff --git a/libs/langchain/langchain/embeddings/gpt4all.py b/libs/langchain/langchain/embeddings/gpt4all.py index 0f109b8453..cd8fdb8fc7 100644 --- a/libs/langchain/langchain/embeddings/gpt4all.py +++ b/libs/langchain/langchain/embeddings/gpt4all.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/embeddings/huggingface.py b/libs/langchain/langchain/embeddings/huggingface.py index 72243705d2..cc8012a8e2 100644 --- a/libs/langchain/langchain/embeddings/huggingface.py +++ b/libs/langchain/langchain/embeddings/huggingface.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional -from pydantic import BaseModel, Extra, Field +from pydantic_v1 import BaseModel, Extra, Field from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/embeddings/huggingface_hub.py b/libs/langchain/langchain/embeddings/huggingface_hub.py index 0ca9985a15..db2e563698 100644 --- a/libs/langchain/langchain/embeddings/huggingface_hub.py +++ b/libs/langchain/langchain/embeddings/huggingface_hub.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.embeddings.base import Embeddings from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/embeddings/jina.py b/libs/langchain/langchain/embeddings/jina.py index 1931a9c4ee..6b8f2e3232 100644 --- a/libs/langchain/langchain/embeddings/jina.py +++ b/libs/langchain/langchain/embeddings/jina.py @@ -2,7 +2,7 @@ import os from typing import Any, Dict, List, Optional import requests -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.embeddings.base import Embeddings from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/embeddings/llamacpp.py b/libs/langchain/langchain/embeddings/llamacpp.py index 5c31d53bf3..750c22cce7 100644 --- a/libs/langchain/langchain/embeddings/llamacpp.py +++ b/libs/langchain/langchain/embeddings/llamacpp.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional -from pydantic import BaseModel, Extra, Field, root_validator +from pydantic_v1 import BaseModel, Extra, Field, root_validator from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/embeddings/localai.py b/libs/langchain/langchain/embeddings/localai.py index 532cd49ead..025e16c7fd 100644 --- a/libs/langchain/langchain/embeddings/localai.py +++ b/libs/langchain/langchain/embeddings/localai.py @@ -15,7 +15,7 @@ from typing import ( Union, ) -from pydantic import BaseModel, Extra, Field, root_validator +from pydantic_v1 import BaseModel, Extra, Field, root_validator from tenacity import ( AsyncRetrying, before_sleep_log, diff --git a/libs/langchain/langchain/embeddings/minimax.py b/libs/langchain/langchain/embeddings/minimax.py index 3ac9a7ef43..1253a5569c 100644 --- a/libs/langchain/langchain/embeddings/minimax.py +++ b/libs/langchain/langchain/embeddings/minimax.py @@ -4,7 +4,7 @@ import logging from typing import Any, Callable, Dict, List, Optional import requests -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from tenacity import ( before_sleep_log, retry, diff --git a/libs/langchain/langchain/embeddings/mlflow_gateway.py b/libs/langchain/langchain/embeddings/mlflow_gateway.py index 16d8f29d68..d3cf14a08b 100644 --- a/libs/langchain/langchain/embeddings/mlflow_gateway.py +++ b/libs/langchain/langchain/embeddings/mlflow_gateway.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Any, Iterator, List, Optional -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/embeddings/modelscope_hub.py b/libs/langchain/langchain/embeddings/modelscope_hub.py index 541aeaa358..7af0385479 100644 --- a/libs/langchain/langchain/embeddings/modelscope_hub.py +++ b/libs/langchain/langchain/embeddings/modelscope_hub.py @@ -1,6 +1,6 @@ from typing import Any, List, Optional -from pydantic import BaseModel, Extra +from pydantic_v1 import BaseModel, Extra from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/embeddings/mosaicml.py b/libs/langchain/langchain/embeddings/mosaicml.py index d2e448da7c..0def394878 100644 --- a/libs/langchain/langchain/embeddings/mosaicml.py +++ b/libs/langchain/langchain/embeddings/mosaicml.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Mapping, Optional, Tuple import requests -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.embeddings.base import Embeddings from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/embeddings/nlpcloud.py b/libs/langchain/langchain/embeddings/nlpcloud.py index 5a65768a94..ce3d6defff 100644 --- a/libs/langchain/langchain/embeddings/nlpcloud.py +++ b/libs/langchain/langchain/embeddings/nlpcloud.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.embeddings.base import Embeddings from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/embeddings/octoai_embeddings.py b/libs/langchain/langchain/embeddings/octoai_embeddings.py index 4a9d0a5120..285f0dabeb 100644 --- a/libs/langchain/langchain/embeddings/octoai_embeddings.py +++ b/libs/langchain/langchain/embeddings/octoai_embeddings.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Mapping, Optional -from pydantic import BaseModel, Extra, Field, root_validator +from pydantic_v1 import BaseModel, Extra, Field, root_validator from langchain.embeddings.base import Embeddings from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/embeddings/openai.py b/libs/langchain/langchain/embeddings/openai.py index 038b8bfde8..59f70f64c1 100644 --- a/libs/langchain/langchain/embeddings/openai.py +++ b/libs/langchain/langchain/embeddings/openai.py @@ -16,7 +16,7 @@ from typing import ( ) import numpy as np -from pydantic import BaseModel, Extra, Field, root_validator +from pydantic_v1 import BaseModel, Extra, Field, root_validator from tenacity import ( AsyncRetrying, before_sleep_log, diff --git a/libs/langchain/langchain/embeddings/sagemaker_endpoint.py b/libs/langchain/langchain/embeddings/sagemaker_endpoint.py index d0fd864a6b..29f33b036d 100644 --- a/libs/langchain/langchain/embeddings/sagemaker_endpoint.py +++ b/libs/langchain/langchain/embeddings/sagemaker_endpoint.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.embeddings.base import Embeddings from langchain.llms.sagemaker_endpoint import ContentHandlerBase diff --git a/libs/langchain/langchain/embeddings/self_hosted.py b/libs/langchain/langchain/embeddings/self_hosted.py index 3ef3136692..1239e57dcf 100644 --- a/libs/langchain/langchain/embeddings/self_hosted.py +++ b/libs/langchain/langchain/embeddings/self_hosted.py @@ -1,6 +1,6 @@ from typing import Any, Callable, List -from pydantic import Extra +from pydantic_v1 import Extra from langchain.embeddings.base import Embeddings from langchain.llms import SelfHostedPipeline diff --git a/libs/langchain/langchain/embeddings/spacy_embeddings.py b/libs/langchain/langchain/embeddings/spacy_embeddings.py index ded1fbbd8a..d3d5a55f87 100644 --- a/libs/langchain/langchain/embeddings/spacy_embeddings.py +++ b/libs/langchain/langchain/embeddings/spacy_embeddings.py @@ -1,7 +1,7 @@ import importlib.util from typing import Any, Dict, List -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/embeddings/tensorflow_hub.py b/libs/langchain/langchain/embeddings/tensorflow_hub.py index 514c7e1c1f..b7542e47aa 100644 --- a/libs/langchain/langchain/embeddings/tensorflow_hub.py +++ b/libs/langchain/langchain/embeddings/tensorflow_hub.py @@ -1,6 +1,6 @@ from typing import Any, List -from pydantic import BaseModel, Extra +from pydantic_v1 import BaseModel, Extra from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/embeddings/vertexai.py b/libs/langchain/langchain/embeddings/vertexai.py index 6ea6d02303..140797d63f 100644 --- a/libs/langchain/langchain/embeddings/vertexai.py +++ b/libs/langchain/langchain/embeddings/vertexai.py @@ -1,6 +1,6 @@ from typing import Dict, List -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.embeddings.base import Embeddings from langchain.llms.vertexai import _VertexAICommon diff --git a/libs/langchain/langchain/evaluation/agents/trajectory_eval_chain.py b/libs/langchain/langchain/evaluation/agents/trajectory_eval_chain.py index 55d0ac1fbc..39e4d8fe15 100644 --- a/libs/langchain/langchain/evaluation/agents/trajectory_eval_chain.py +++ b/libs/langchain/langchain/evaluation/agents/trajectory_eval_chain.py @@ -18,7 +18,7 @@ from typing import ( cast, ) -from pydantic import Extra, Field +from pydantic_v1 import Extra, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForChainRun, diff --git a/libs/langchain/langchain/evaluation/comparison/eval_chain.py b/libs/langchain/langchain/evaluation/comparison/eval_chain.py index 3ca215324b..795f6760e5 100644 --- a/libs/langchain/langchain/evaluation/comparison/eval_chain.py +++ b/libs/langchain/langchain/evaluation/comparison/eval_chain.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional, Union -from pydantic import Extra, Field +from pydantic_v1 import Extra, Field from langchain.callbacks.manager import Callbacks from langchain.chains.constitutional_ai.models import ConstitutionalPrinciple diff --git a/libs/langchain/langchain/evaluation/criteria/eval_chain.py b/libs/langchain/langchain/evaluation/criteria/eval_chain.py index 09359cf79e..99fd0226d9 100644 --- a/libs/langchain/langchain/evaluation/criteria/eval_chain.py +++ b/libs/langchain/langchain/evaluation/criteria/eval_chain.py @@ -3,7 +3,7 @@ from __future__ import annotations from enum import Enum from typing import Any, Dict, List, Mapping, Optional, Union -from pydantic import Extra, Field +from pydantic_v1 import Extra, Field from langchain.callbacks.manager import Callbacks from langchain.chains.constitutional_ai.models import ConstitutionalPrinciple diff --git a/libs/langchain/langchain/evaluation/embedding_distance/base.py b/libs/langchain/langchain/evaluation/embedding_distance/base.py index 3591f45d8b..4c426f06cb 100644 --- a/libs/langchain/langchain/evaluation/embedding_distance/base.py +++ b/libs/langchain/langchain/evaluation/embedding_distance/base.py @@ -3,7 +3,7 @@ from enum import Enum from typing import Any, Dict, List, Optional import numpy as np -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForChainRun, diff --git a/libs/langchain/langchain/evaluation/qa/eval_chain.py b/libs/langchain/langchain/evaluation/qa/eval_chain.py index 90b5e8d5dc..4190dee0d3 100644 --- a/libs/langchain/langchain/evaluation/qa/eval_chain.py +++ b/libs/langchain/langchain/evaluation/qa/eval_chain.py @@ -4,7 +4,7 @@ from __future__ import annotations import re from typing import Any, List, Optional, Sequence -from pydantic import Extra +from pydantic_v1 import Extra from langchain import PromptTemplate from langchain.callbacks.manager import Callbacks diff --git a/libs/langchain/langchain/evaluation/qa/generate_chain.py b/libs/langchain/langchain/evaluation/qa/generate_chain.py index 7891ccccbd..595ed4af0e 100644 --- a/libs/langchain/langchain/evaluation/qa/generate_chain.py +++ b/libs/langchain/langchain/evaluation/qa/generate_chain.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any -from pydantic import Field +from pydantic_v1 import Field from langchain.chains.llm import LLMChain from langchain.evaluation.qa.generate_prompt import PROMPT diff --git a/libs/langchain/langchain/evaluation/string_distance/base.py b/libs/langchain/langchain/evaluation/string_distance/base.py index 57f2958fe5..57e37be7ee 100644 --- a/libs/langchain/langchain/evaluation/string_distance/base.py +++ b/libs/langchain/langchain/evaluation/string_distance/base.py @@ -3,7 +3,7 @@ from enum import Enum from typing import Any, Callable, Dict, List, Optional -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForChainRun, diff --git a/libs/langchain/langchain/indexes/graph.py b/libs/langchain/langchain/indexes/graph.py index 64536e003c..e1b01c112f 100644 --- a/libs/langchain/langchain/indexes/graph.py +++ b/libs/langchain/langchain/indexes/graph.py @@ -1,7 +1,7 @@ """Graph Index Creator.""" from typing import Optional, Type -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain import BasePromptTemplate from langchain.chains.llm import LLMChain diff --git a/libs/langchain/langchain/indexes/vectorstore.py b/libs/langchain/langchain/indexes/vectorstore.py index c9229f9d7b..3cdc481725 100644 --- a/libs/langchain/langchain/indexes/vectorstore.py +++ b/libs/langchain/langchain/indexes/vectorstore.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional, Type -from pydantic import BaseModel, Extra, Field +from pydantic_v1 import BaseModel, Extra, Field from langchain.chains.qa_with_sources.retrieval import RetrievalQAWithSourcesChain from langchain.chains.retrieval_qa.base import RetrievalQA diff --git a/libs/langchain/langchain/llms/ai21.py b/libs/langchain/langchain/llms/ai21.py index 5d2562a6af..1502a47353 100644 --- a/libs/langchain/langchain/llms/ai21.py +++ b/libs/langchain/langchain/llms/ai21.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Optional import requests -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/aleph_alpha.py b/libs/langchain/langchain/llms/aleph_alpha.py index 1df17c3a87..c3c9502639 100644 --- a/libs/langchain/langchain/llms/aleph_alpha.py +++ b/libs/langchain/langchain/llms/aleph_alpha.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional, Sequence -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/amazon_api_gateway.py b/libs/langchain/langchain/llms/amazon_api_gateway.py index 1ba81c1189..766649174d 100644 --- a/libs/langchain/langchain/llms/amazon_api_gateway.py +++ b/libs/langchain/langchain/llms/amazon_api_gateway.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Mapping, Optional import requests -from pydantic import Extra +from pydantic_v1 import Extra from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/anthropic.py b/libs/langchain/langchain/llms/anthropic.py index 5e5695762f..93d8fb737f 100644 --- a/libs/langchain/langchain/llms/anthropic.py +++ b/libs/langchain/langchain/llms/anthropic.py @@ -2,7 +2,7 @@ import re import warnings from typing import Any, AsyncIterator, Callable, Dict, Iterator, List, Mapping, Optional -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, diff --git a/libs/langchain/langchain/llms/anyscale.py b/libs/langchain/langchain/llms/anyscale.py index 5a440b97d4..85e33ed4e7 100644 --- a/libs/langchain/langchain/llms/anyscale.py +++ b/libs/langchain/langchain/llms/anyscale.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Mapping, Optional import requests -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/aviary.py b/libs/langchain/langchain/llms/aviary.py index 5e2a38cf71..96780b6518 100644 --- a/libs/langchain/langchain/llms/aviary.py +++ b/libs/langchain/langchain/llms/aviary.py @@ -3,7 +3,7 @@ import os from typing import Any, Dict, List, Mapping, Optional, Union, cast import requests -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/azureml_endpoint.py b/libs/langchain/langchain/llms/azureml_endpoint.py index 7432e79e87..5bf5ba6c2f 100644 --- a/libs/langchain/langchain/llms/azureml_endpoint.py +++ b/libs/langchain/langchain/llms/azureml_endpoint.py @@ -4,7 +4,7 @@ import warnings from abc import abstractmethod from typing import Any, Dict, List, Mapping, Optional -from pydantic import BaseModel, validator +from pydantic_v1 import BaseModel, validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/bananadev.py b/libs/langchain/langchain/llms/bananadev.py index 76dcb7b8af..24d5cc8394 100644 --- a/libs/langchain/langchain/llms/bananadev.py +++ b/libs/langchain/langchain/llms/bananadev.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/base.py b/libs/langchain/langchain/llms/base.py index 3fa006ea72..b30afe8551 100644 --- a/libs/langchain/langchain/llms/base.py +++ b/libs/langchain/langchain/llms/base.py @@ -27,7 +27,7 @@ from typing import ( ) import yaml -from pydantic import Field, root_validator, validator +from pydantic_v1 import Field, root_validator, validator from tenacity import ( RetryCallState, before_sleep_log, diff --git a/libs/langchain/langchain/llms/baseten.py b/libs/langchain/langchain/llms/baseten.py index d07fd63366..1ce71ed410 100644 --- a/libs/langchain/langchain/llms/baseten.py +++ b/libs/langchain/langchain/llms/baseten.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/beam.py b/libs/langchain/langchain/llms/beam.py index 47bc017dad..82670491ad 100644 --- a/libs/langchain/langchain/llms/beam.py +++ b/libs/langchain/langchain/llms/beam.py @@ -7,7 +7,7 @@ import time from typing import Any, Dict, List, Mapping, Optional import requests -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/bedrock.py b/libs/langchain/langchain/llms/bedrock.py index 481de7f568..6bfc2ffc89 100644 --- a/libs/langchain/langchain/llms/bedrock.py +++ b/libs/langchain/langchain/llms/bedrock.py @@ -1,7 +1,7 @@ import json from typing import Any, Dict, List, Mapping, Optional -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/cerebriumai.py b/libs/langchain/langchain/llms/cerebriumai.py index 02db1cf33e..b08aa42774 100644 --- a/libs/langchain/langchain/llms/cerebriumai.py +++ b/libs/langchain/langchain/llms/cerebriumai.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/clarifai.py b/libs/langchain/langchain/llms/clarifai.py index 2eead83592..edfc7d739d 100644 --- a/libs/langchain/langchain/llms/clarifai.py +++ b/libs/langchain/langchain/llms/clarifai.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Optional -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/cohere.py b/libs/langchain/langchain/llms/cohere.py index bad5a15651..f57300ac16 100644 --- a/libs/langchain/langchain/llms/cohere.py +++ b/libs/langchain/langchain/llms/cohere.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Any, Callable, Dict, List, Optional -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from tenacity import ( before_sleep_log, retry, diff --git a/libs/langchain/langchain/llms/ctransformers.py b/libs/langchain/langchain/llms/ctransformers.py index 86c657f618..af071d5cee 100644 --- a/libs/langchain/langchain/llms/ctransformers.py +++ b/libs/langchain/langchain/llms/ctransformers.py @@ -1,7 +1,7 @@ from functools import partial from typing import Any, Dict, List, Optional, Sequence -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, diff --git a/libs/langchain/langchain/llms/databricks.py b/libs/langchain/langchain/llms/databricks.py index 6ed2a6fa7d..b88e6f86c9 100644 --- a/libs/langchain/langchain/llms/databricks.py +++ b/libs/langchain/langchain/llms/databricks.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from typing import Any, Callable, Dict, List, Optional import requests -from pydantic import BaseModel, Extra, Field, PrivateAttr, root_validator, validator +from pydantic_v1 import BaseModel, Extra, Field, PrivateAttr, root_validator, validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/deepinfra.py b/libs/langchain/langchain/llms/deepinfra.py index 533c236284..9d763eff23 100644 --- a/libs/langchain/langchain/llms/deepinfra.py +++ b/libs/langchain/langchain/llms/deepinfra.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Mapping, Optional import requests -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/edenai.py b/libs/langchain/langchain/llms/edenai.py index 6b0f365b6f..f3dcc02093 100644 --- a/libs/langchain/langchain/llms/edenai.py +++ b/libs/langchain/langchain/llms/edenai.py @@ -3,7 +3,7 @@ import logging from typing import Any, Dict, List, Literal, Optional from aiohttp import ClientSession -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, diff --git a/libs/langchain/langchain/llms/fireworks.py b/libs/langchain/langchain/llms/fireworks.py index 941cfb62c1..fb9eb27828 100644 --- a/libs/langchain/langchain/llms/fireworks.py +++ b/libs/langchain/langchain/llms/fireworks.py @@ -12,7 +12,7 @@ from typing import ( ) import requests -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, diff --git a/libs/langchain/langchain/llms/forefrontai.py b/libs/langchain/langchain/llms/forefrontai.py index b6c70d5c43..c7ff6dee3e 100644 --- a/libs/langchain/langchain/llms/forefrontai.py +++ b/libs/langchain/langchain/llms/forefrontai.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Mapping, Optional import requests -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/google_palm.py b/libs/langchain/langchain/llms/google_palm.py index 8f45950a29..df5dcd3517 100644 --- a/libs/langchain/langchain/llms/google_palm.py +++ b/libs/langchain/langchain/llms/google_palm.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Any, Callable, Dict, List, Optional -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from tenacity import ( before_sleep_log, retry, diff --git a/libs/langchain/langchain/llms/gooseai.py b/libs/langchain/langchain/llms/gooseai.py index cde043ce22..8259bdc036 100644 --- a/libs/langchain/langchain/llms/gooseai.py +++ b/libs/langchain/langchain/llms/gooseai.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/gpt4all.py b/libs/langchain/langchain/llms/gpt4all.py index c88374c1c0..2239beaba5 100644 --- a/libs/langchain/langchain/llms/gpt4all.py +++ b/libs/langchain/langchain/llms/gpt4all.py @@ -1,7 +1,7 @@ from functools import partial from typing import Any, Dict, List, Mapping, Optional, Set -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/huggingface_endpoint.py b/libs/langchain/langchain/llms/huggingface_endpoint.py index ff38a2025a..f9e88f3723 100644 --- a/libs/langchain/langchain/llms/huggingface_endpoint.py +++ b/libs/langchain/langchain/llms/huggingface_endpoint.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Mapping, Optional import requests -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/huggingface_hub.py b/libs/langchain/langchain/llms/huggingface_hub.py index 745f0fdccb..ef2fac0906 100644 --- a/libs/langchain/langchain/llms/huggingface_hub.py +++ b/libs/langchain/langchain/llms/huggingface_hub.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Mapping, Optional -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/huggingface_pipeline.py b/libs/langchain/langchain/llms/huggingface_pipeline.py index ef7d428949..18910c4c5e 100644 --- a/libs/langchain/langchain/llms/huggingface_pipeline.py +++ b/libs/langchain/langchain/llms/huggingface_pipeline.py @@ -2,7 +2,7 @@ import importlib.util import logging from typing import Any, List, Mapping, Optional -from pydantic import Extra +from pydantic_v1 import Extra from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/huggingface_text_gen_inference.py b/libs/langchain/langchain/llms/huggingface_text_gen_inference.py index befe813480..08d2f0c8f5 100644 --- a/libs/langchain/langchain/llms/huggingface_text_gen_inference.py +++ b/libs/langchain/langchain/llms/huggingface_text_gen_inference.py @@ -1,6 +1,6 @@ from typing import Any, AsyncIterator, Dict, Iterator, List, Optional -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, diff --git a/libs/langchain/langchain/llms/human.py b/libs/langchain/langchain/llms/human.py index 87ce68f152..ac6206f943 100644 --- a/libs/langchain/langchain/llms/human.py +++ b/libs/langchain/langchain/llms/human.py @@ -1,6 +1,6 @@ from typing import Any, Callable, List, Mapping, Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/llamacpp.py b/libs/langchain/langchain/llms/llamacpp.py index 518206462a..26f02f34c3 100644 --- a/libs/langchain/langchain/llms/llamacpp.py +++ b/libs/langchain/langchain/llms/llamacpp.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, Iterator, List, Optional -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/manifest.py b/libs/langchain/langchain/llms/manifest.py index 71a89ed00f..9527e609af 100644 --- a/libs/langchain/langchain/llms/manifest.py +++ b/libs/langchain/langchain/llms/manifest.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Mapping, Optional -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/minimax.py b/libs/langchain/langchain/llms/minimax.py index dfcc3c656c..f723e94da3 100644 --- a/libs/langchain/langchain/llms/minimax.py +++ b/libs/langchain/langchain/llms/minimax.py @@ -10,7 +10,7 @@ from typing import ( ) import requests -from pydantic import BaseModel, Extra, Field, PrivateAttr, root_validator +from pydantic_v1 import BaseModel, Extra, Field, PrivateAttr, root_validator from langchain.callbacks.manager import ( CallbackManagerForLLMRun, diff --git a/libs/langchain/langchain/llms/mlflow_ai_gateway.py b/libs/langchain/langchain/llms/mlflow_ai_gateway.py index da20a62978..59def90b5e 100644 --- a/libs/langchain/langchain/llms/mlflow_ai_gateway.py +++ b/libs/langchain/langchain/llms/mlflow_ai_gateway.py @@ -2,13 +2,15 @@ from __future__ import annotations from typing import Any, Dict, List, Mapping, Optional -from pydantic import BaseModel, Extra +from pydantic_v1 import BaseModel, Extra from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM -class Params(BaseModel, extra=Extra.allow): +# Ignoring type because below is valid pydantic code +# Unexpected keyword argument "extra" for "__init_subclass__" of "object" +class Params(BaseModel, extra=Extra.allow): # type: ignore[call-arg] """Parameters for the MLflow AI Gateway LLM.""" temperature: float = 0.0 diff --git a/libs/langchain/langchain/llms/modal.py b/libs/langchain/langchain/llms/modal.py index bf03947bc5..e4ae2f417e 100644 --- a/libs/langchain/langchain/llms/modal.py +++ b/libs/langchain/langchain/llms/modal.py @@ -2,7 +2,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional import requests -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/mosaicml.py b/libs/langchain/langchain/llms/mosaicml.py index 226b5c3b8b..615a23df92 100644 --- a/libs/langchain/langchain/llms/mosaicml.py +++ b/libs/langchain/langchain/llms/mosaicml.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Mapping, Optional import requests -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/nlpcloud.py b/libs/langchain/langchain/llms/nlpcloud.py index 9e5070acf7..ec56b4458b 100644 --- a/libs/langchain/langchain/llms/nlpcloud.py +++ b/libs/langchain/langchain/llms/nlpcloud.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Mapping, Optional -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/octoai_endpoint.py b/libs/langchain/langchain/llms/octoai_endpoint.py index 46c88d51ac..76519ed703 100644 --- a/libs/langchain/langchain/llms/octoai_endpoint.py +++ b/libs/langchain/langchain/llms/octoai_endpoint.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Mapping, Optional -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/ollama.py b/libs/langchain/langchain/llms/ollama.py index 8adbfd997e..5be1c38479 100644 --- a/libs/langchain/langchain/llms/ollama.py +++ b/libs/langchain/langchain/llms/ollama.py @@ -2,7 +2,7 @@ import json from typing import Any, Dict, Iterator, List, Mapping, Optional import requests -from pydantic import Extra +from pydantic_v1 import Extra from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import BaseLLM diff --git a/libs/langchain/langchain/llms/openai.py b/libs/langchain/langchain/llms/openai.py index 082067615a..2d368737ec 100644 --- a/libs/langchain/langchain/llms/openai.py +++ b/libs/langchain/langchain/llms/openai.py @@ -20,7 +20,7 @@ from typing import ( Union, ) -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, diff --git a/libs/langchain/langchain/llms/openllm.py b/libs/langchain/langchain/llms/openllm.py index 62b1dde03f..c478ff0471 100644 --- a/libs/langchain/langchain/llms/openllm.py +++ b/libs/langchain/langchain/llms/openllm.py @@ -15,7 +15,7 @@ from typing import ( overload, ) -from pydantic import PrivateAttr +from pydantic_v1 import PrivateAttr from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, diff --git a/libs/langchain/langchain/llms/openlm.py b/libs/langchain/langchain/llms/openlm.py index c77badaa3a..2192901c73 100644 --- a/libs/langchain/langchain/llms/openlm.py +++ b/libs/langchain/langchain/llms/openlm.py @@ -1,6 +1,6 @@ from typing import Any, Dict -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.llms.openai import BaseOpenAI diff --git a/libs/langchain/langchain/llms/petals.py b/libs/langchain/langchain/llms/petals.py index 1b74734cd5..f3c02900a7 100644 --- a/libs/langchain/langchain/llms/petals.py +++ b/libs/langchain/langchain/llms/petals.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/pipelineai.py b/libs/langchain/langchain/llms/pipelineai.py index b145cc4947..52591db848 100644 --- a/libs/langchain/langchain/llms/pipelineai.py +++ b/libs/langchain/langchain/llms/pipelineai.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional -from pydantic import BaseModel, Extra, Field, root_validator +from pydantic_v1 import BaseModel, Extra, Field, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/predibase.py b/libs/langchain/langchain/llms/predibase.py index 0ab549236e..4c3a0c8a89 100644 --- a/libs/langchain/langchain/llms/predibase.py +++ b/libs/langchain/langchain/llms/predibase.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Mapping, Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/predictionguard.py b/libs/langchain/langchain/llms/predictionguard.py index f91541508f..f116b54d85 100644 --- a/libs/langchain/langchain/llms/predictionguard.py +++ b/libs/langchain/langchain/llms/predictionguard.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Optional -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/replicate.py b/libs/langchain/langchain/llms/replicate.py index c8706a6f8a..e2abf64e53 100644 --- a/libs/langchain/langchain/llms/replicate.py +++ b/libs/langchain/langchain/llms/replicate.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/rwkv.py b/libs/langchain/langchain/llms/rwkv.py index 6b717d4a12..b3530250d2 100644 --- a/libs/langchain/langchain/llms/rwkv.py +++ b/libs/langchain/langchain/llms/rwkv.py @@ -5,7 +5,7 @@ Based on https://github.com/saharNooby/rwkv.cpp/blob/master/rwkv/chat_with_bot.p """ from typing import Any, Dict, List, Mapping, Optional, Set -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/sagemaker_endpoint.py b/libs/langchain/langchain/llms/sagemaker_endpoint.py index 1e28435684..a122aafb59 100644 --- a/libs/langchain/langchain/llms/sagemaker_endpoint.py +++ b/libs/langchain/langchain/llms/sagemaker_endpoint.py @@ -2,7 +2,7 @@ from abc import abstractmethod from typing import Any, Dict, Generic, List, Mapping, Optional, TypeVar, Union -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/self_hosted.py b/libs/langchain/langchain/llms/self_hosted.py index 42d45c9c54..a4ca677c01 100644 --- a/libs/langchain/langchain/llms/self_hosted.py +++ b/libs/langchain/langchain/llms/self_hosted.py @@ -3,7 +3,7 @@ import logging import pickle from typing import Any, Callable, List, Mapping, Optional -from pydantic import Extra +from pydantic_v1 import Extra from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/self_hosted_hugging_face.py b/libs/langchain/langchain/llms/self_hosted_hugging_face.py index 2e55aaf1d2..06b54198f8 100644 --- a/libs/langchain/langchain/llms/self_hosted_hugging_face.py +++ b/libs/langchain/langchain/llms/self_hosted_hugging_face.py @@ -2,7 +2,7 @@ import importlib.util import logging from typing import Any, Callable, List, Mapping, Optional -from pydantic import Extra +from pydantic_v1 import Extra from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.self_hosted import SelfHostedPipeline diff --git a/libs/langchain/langchain/llms/stochasticai.py b/libs/langchain/langchain/llms/stochasticai.py index 391d9e8c40..b6e4c37ed4 100644 --- a/libs/langchain/langchain/llms/stochasticai.py +++ b/libs/langchain/langchain/llms/stochasticai.py @@ -3,7 +3,7 @@ import time from typing import Any, Dict, List, Mapping, Optional import requests -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/symblai_nebula.py b/libs/langchain/langchain/llms/symblai_nebula.py index cec64b5516..892269abc3 100644 --- a/libs/langchain/langchain/llms/symblai_nebula.py +++ b/libs/langchain/langchain/llms/symblai_nebula.py @@ -2,7 +2,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional import requests -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/textgen.py b/libs/langchain/langchain/llms/textgen.py index 4e4880b82a..dc93d88cc3 100644 --- a/libs/langchain/langchain/llms/textgen.py +++ b/libs/langchain/langchain/llms/textgen.py @@ -2,7 +2,7 @@ import logging from typing import Any, Dict, List, Optional import requests -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/llms/tongyi.py b/libs/langchain/langchain/llms/tongyi.py index 57973861b9..e2b9943f47 100644 --- a/libs/langchain/langchain/llms/tongyi.py +++ b/libs/langchain/langchain/llms/tongyi.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Any, Callable, Dict, List, Optional -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from requests.exceptions import HTTPError from tenacity import ( before_sleep_log, diff --git a/libs/langchain/langchain/llms/vertexai.py b/libs/langchain/langchain/llms/vertexai.py index 35fa573466..5a5f037b84 100644 --- a/libs/langchain/langchain/llms/vertexai.py +++ b/libs/langchain/langchain/llms/vertexai.py @@ -4,7 +4,7 @@ import asyncio from concurrent.futures import Executor, ThreadPoolExecutor from typing import TYPE_CHECKING, Any, Callable, ClassVar, Dict, List, Optional -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, diff --git a/libs/langchain/langchain/llms/vllm.py b/libs/langchain/langchain/llms/vllm.py index 61fa5e6666..e7a0b0c363 100644 --- a/libs/langchain/langchain/llms/vllm.py +++ b/libs/langchain/langchain/llms/vllm.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import BaseLLM diff --git a/libs/langchain/langchain/llms/writer.py b/libs/langchain/langchain/llms/writer.py index 546d09b04c..308ccc30ba 100644 --- a/libs/langchain/langchain/llms/writer.py +++ b/libs/langchain/langchain/llms/writer.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Mapping, Optional import requests -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/langchain/load/serializable.py b/libs/langchain/langchain/load/serializable.py index 8f0e5ccf8d..76352e2871 100644 --- a/libs/langchain/langchain/load/serializable.py +++ b/libs/langchain/langchain/load/serializable.py @@ -1,7 +1,7 @@ from abc import ABC from typing import Any, Dict, List, Literal, TypedDict, Union, cast -from pydantic import BaseModel, PrivateAttr +from pydantic_v1 import BaseModel, PrivateAttr class BaseSerialized(TypedDict): diff --git a/libs/langchain/langchain/memory/buffer.py b/libs/langchain/langchain/memory/buffer.py index 3809577d06..b35373749f 100644 --- a/libs/langchain/langchain/memory/buffer.py +++ b/libs/langchain/langchain/memory/buffer.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.memory.chat_memory import BaseChatMemory, BaseMemory from langchain.memory.utils import get_prompt_input_key diff --git a/libs/langchain/langchain/memory/chat_memory.py b/libs/langchain/langchain/memory/chat_memory.py index e322c6ddb2..0e2ef543e3 100644 --- a/libs/langchain/langchain/memory/chat_memory.py +++ b/libs/langchain/langchain/memory/chat_memory.py @@ -1,7 +1,7 @@ from abc import ABC from typing import Any, Dict, Optional, Tuple -from pydantic import Field +from pydantic_v1 import Field from langchain.memory.chat_message_histories.in_memory import ChatMessageHistory from langchain.memory.utils import get_prompt_input_key diff --git a/libs/langchain/langchain/memory/chat_message_histories/in_memory.py b/libs/langchain/langchain/memory/chat_message_histories/in_memory.py index 38aea5a39e..19ae89105e 100644 --- a/libs/langchain/langchain/memory/chat_message_histories/in_memory.py +++ b/libs/langchain/langchain/memory/chat_message_histories/in_memory.py @@ -1,6 +1,6 @@ from typing import List -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.schema import ( BaseChatMessageHistory, diff --git a/libs/langchain/langchain/memory/combined.py b/libs/langchain/langchain/memory/combined.py index 80316755ae..1b9cc5cd64 100644 --- a/libs/langchain/langchain/memory/combined.py +++ b/libs/langchain/langchain/memory/combined.py @@ -1,7 +1,7 @@ import warnings from typing import Any, Dict, List, Set -from pydantic import validator +from pydantic_v1 import validator from langchain.memory.chat_memory import BaseChatMemory from langchain.schema import BaseMemory diff --git a/libs/langchain/langchain/memory/entity.py b/libs/langchain/langchain/memory/entity.py index 54b9574b0d..a8cdd15445 100644 --- a/libs/langchain/langchain/memory/entity.py +++ b/libs/langchain/langchain/memory/entity.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from itertools import islice from typing import Any, Dict, Iterable, List, Optional -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.chains.llm import LLMChain from langchain.memory.chat_memory import BaseChatMemory diff --git a/libs/langchain/langchain/memory/kg.py b/libs/langchain/langchain/memory/kg.py index 400ed34987..5775171850 100644 --- a/libs/langchain/langchain/memory/kg.py +++ b/libs/langchain/langchain/memory/kg.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Type, Union -from pydantic import Field +from pydantic_v1 import Field from langchain.chains.llm import LLMChain from langchain.graphs import NetworkxEntityGraph diff --git a/libs/langchain/langchain/memory/summary.py b/libs/langchain/langchain/memory/summary.py index afa0f9c8ef..77d24bc013 100644 --- a/libs/langchain/langchain/memory/summary.py +++ b/libs/langchain/langchain/memory/summary.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Any, Dict, List, Type -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.chains.llm import LLMChain from langchain.memory.chat_memory import BaseChatMemory diff --git a/libs/langchain/langchain/memory/summary_buffer.py b/libs/langchain/langchain/memory/summary_buffer.py index 0b49797f59..bec6076214 100644 --- a/libs/langchain/langchain/memory/summary_buffer.py +++ b/libs/langchain/langchain/memory/summary_buffer.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.memory.chat_memory import BaseChatMemory from langchain.memory.summary import SummarizerMixin diff --git a/libs/langchain/langchain/memory/vectorstore.py b/libs/langchain/langchain/memory/vectorstore.py index 41f0d8c671..c367b47073 100644 --- a/libs/langchain/langchain/memory/vectorstore.py +++ b/libs/langchain/langchain/memory/vectorstore.py @@ -2,7 +2,7 @@ from typing import Any, Dict, List, Optional, Sequence, Union -from pydantic import Field +from pydantic_v1 import Field from langchain.memory.chat_memory import BaseMemory from langchain.memory.utils import get_prompt_input_key diff --git a/libs/langchain/langchain/output_parsers/combining.py b/libs/langchain/langchain/output_parsers/combining.py index 511d9398f0..a6f3dab84f 100644 --- a/libs/langchain/langchain/output_parsers/combining.py +++ b/libs/langchain/langchain/output_parsers/combining.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Any, Dict, List -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.schema import BaseOutputParser diff --git a/libs/langchain/langchain/output_parsers/enum.py b/libs/langchain/langchain/output_parsers/enum.py index ee3daecfee..c1469bfb99 100644 --- a/libs/langchain/langchain/output_parsers/enum.py +++ b/libs/langchain/langchain/output_parsers/enum.py @@ -1,7 +1,7 @@ from enum import Enum from typing import Any, Dict, List, Type -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.schema import BaseOutputParser, OutputParserException diff --git a/libs/langchain/langchain/output_parsers/openai_functions.py b/libs/langchain/langchain/output_parsers/openai_functions.py index 646d895962..20913c3688 100644 --- a/libs/langchain/langchain/output_parsers/openai_functions.py +++ b/libs/langchain/langchain/output_parsers/openai_functions.py @@ -2,7 +2,7 @@ import copy import json from typing import Any, Dict, List, Type, Union -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.schema import ( ChatGeneration, diff --git a/libs/langchain/langchain/output_parsers/pydantic.py b/libs/langchain/langchain/output_parsers/pydantic.py index b35943e6e2..ea2bf33482 100644 --- a/libs/langchain/langchain/output_parsers/pydantic.py +++ b/libs/langchain/langchain/output_parsers/pydantic.py @@ -2,7 +2,7 @@ import json import re from typing import Type, TypeVar -from pydantic import BaseModel, ValidationError +from pydantic_v1 import BaseModel, ValidationError from langchain.output_parsers.format_instructions import PYDANTIC_FORMAT_INSTRUCTIONS from langchain.schema import BaseOutputParser, OutputParserException diff --git a/libs/langchain/langchain/output_parsers/structured.py b/libs/langchain/langchain/output_parsers/structured.py index 5733c896f6..eecd8de69a 100644 --- a/libs/langchain/langchain/output_parsers/structured.py +++ b/libs/langchain/langchain/output_parsers/structured.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Any, List -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.output_parsers.format_instructions import ( STRUCTURED_FORMAT_INSTRUCTIONS, diff --git a/libs/langchain/langchain/prompts/chat.py b/libs/langchain/langchain/prompts/chat.py index fabdfe2248..72925e1cb4 100644 --- a/libs/langchain/langchain/prompts/chat.py +++ b/libs/langchain/langchain/prompts/chat.py @@ -3,9 +3,20 @@ from __future__ import annotations from abc import ABC, abstractmethod from pathlib import Path -from typing import Any, Callable, List, Sequence, Tuple, Type, TypeVar, Union, overload +from typing import ( + Any, + Callable, + List, + Sequence, + Set, + Tuple, + Type, + TypeVar, + Union, + overload, +) -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from langchain._api import deprecated from langchain.load.serializable import Serializable @@ -507,7 +518,7 @@ class ChatPromptTemplate(BaseChatPromptTemplate, ABC): _messages = [_convert_to_message(message) for message in messages] # Automatically infer input variables from messages - input_vars = set() + input_vars: Set[str] = set() for _message in _messages: if isinstance( _message, (BaseChatPromptTemplate, BaseMessagePromptTemplate) diff --git a/libs/langchain/langchain/prompts/example_selector/length_based.py b/libs/langchain/langchain/prompts/example_selector/length_based.py index f6c665de32..b2af714159 100644 --- a/libs/langchain/langchain/prompts/example_selector/length_based.py +++ b/libs/langchain/langchain/prompts/example_selector/length_based.py @@ -2,7 +2,7 @@ import re from typing import Callable, Dict, List -from pydantic import BaseModel, validator +from pydantic_v1 import BaseModel, validator from langchain.prompts.example_selector.base import BaseExampleSelector from langchain.prompts.prompt import PromptTemplate diff --git a/libs/langchain/langchain/prompts/example_selector/ngram_overlap.py b/libs/langchain/langchain/prompts/example_selector/ngram_overlap.py index 9dd68f00a7..6697a07c1f 100644 --- a/libs/langchain/langchain/prompts/example_selector/ngram_overlap.py +++ b/libs/langchain/langchain/prompts/example_selector/ngram_overlap.py @@ -6,7 +6,7 @@ https://aclanthology.org/P02-1040.pdf from typing import Dict, List import numpy as np -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.prompts.example_selector.base import BaseExampleSelector from langchain.prompts.prompt import PromptTemplate diff --git a/libs/langchain/langchain/prompts/example_selector/semantic_similarity.py b/libs/langchain/langchain/prompts/example_selector/semantic_similarity.py index 0d66c13673..7f224324b7 100644 --- a/libs/langchain/langchain/prompts/example_selector/semantic_similarity.py +++ b/libs/langchain/langchain/prompts/example_selector/semantic_similarity.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional, Type -from pydantic import BaseModel, Extra +from pydantic_v1 import BaseModel, Extra from langchain.embeddings.base import Embeddings from langchain.prompts.example_selector.base import BaseExampleSelector diff --git a/libs/langchain/langchain/prompts/few_shot.py b/libs/langchain/langchain/prompts/few_shot.py index 7a28f10066..873f732d4b 100644 --- a/libs/langchain/langchain/prompts/few_shot.py +++ b/libs/langchain/langchain/prompts/few_shot.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional, Union -from pydantic import BaseModel, Extra, Field, root_validator +from pydantic_v1 import BaseModel, Extra, Field, root_validator from langchain.prompts.base import ( DEFAULT_FORMATTER_MAPPING, diff --git a/libs/langchain/langchain/prompts/few_shot_with_templates.py b/libs/langchain/langchain/prompts/few_shot_with_templates.py index 5e5330cf94..15c967bb18 100644 --- a/libs/langchain/langchain/prompts/few_shot_with_templates.py +++ b/libs/langchain/langchain/prompts/few_shot_with_templates.py @@ -1,7 +1,7 @@ """Prompt template that contains few shot examples.""" from typing import Any, Dict, List, Optional -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.prompts.base import DEFAULT_FORMATTER_MAPPING, StringPromptTemplate from langchain.prompts.example_selector.base import BaseExampleSelector diff --git a/libs/langchain/langchain/prompts/loading.py b/libs/langchain/langchain/prompts/loading.py index dc8a1bc32a..55d2013ecd 100644 --- a/libs/langchain/langchain/prompts/loading.py +++ b/libs/langchain/langchain/prompts/loading.py @@ -26,7 +26,10 @@ def load_prompt_from_config(config: dict) -> BasePromptTemplate: raise ValueError(f"Loading {config_type} prompt not supported") prompt_loader = type_to_loader_dict[config_type] - return prompt_loader(config) + # Unclear why type error is being thrown here. + # Incompatible return value type (got "Runnable[Dict[Any, Any], PromptValue]", + # expected "BasePromptTemplate") [return-value] + return prompt_loader(config) # type: ignore[return-value] def _load_template(var_name: str, config: dict) -> dict: diff --git a/libs/langchain/langchain/prompts/pipeline.py b/libs/langchain/langchain/prompts/pipeline.py index 28364766a7..75a56f5d2c 100644 --- a/libs/langchain/langchain/prompts/pipeline.py +++ b/libs/langchain/langchain/prompts/pipeline.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Tuple -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.prompts.chat import BaseChatPromptTemplate from langchain.schema import BasePromptTemplate, PromptValue diff --git a/libs/langchain/langchain/prompts/prompt.py b/libs/langchain/langchain/prompts/prompt.py index 11cae9f51a..b5e26b33b1 100644 --- a/libs/langchain/langchain/prompts/prompt.py +++ b/libs/langchain/langchain/prompts/prompt.py @@ -5,7 +5,7 @@ from pathlib import Path from string import Formatter from typing import Any, Dict, List, Optional, Union -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.prompts.base import ( DEFAULT_FORMATTER_MAPPING, diff --git a/libs/langchain/langchain/retrievers/azure_cognitive_search.py b/libs/langchain/langchain/retrievers/azure_cognitive_search.py index 214f663e95..cf5c6b9538 100644 --- a/libs/langchain/langchain/retrievers/azure_cognitive_search.py +++ b/libs/langchain/langchain/retrievers/azure_cognitive_search.py @@ -7,7 +7,7 @@ from typing import Dict, List, Optional import aiohttp import requests -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForRetrieverRun, diff --git a/libs/langchain/langchain/retrievers/document_compressors/base.py b/libs/langchain/langchain/retrievers/document_compressors/base.py index 1e0587c59c..10ba7494a8 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/base.py +++ b/libs/langchain/langchain/retrievers/document_compressors/base.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from inspect import signature from typing import List, Optional, Sequence, Union -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.callbacks.manager import Callbacks from langchain.schema import BaseDocumentTransformer, Document diff --git a/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py b/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py index a9fad10c8b..e02ddadd52 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py +++ b/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, Dict, Optional, Sequence -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import Callbacks from langchain.retrievers.document_compressors.base import BaseDocumentCompressor diff --git a/libs/langchain/langchain/retrievers/document_compressors/embeddings_filter.py b/libs/langchain/langchain/retrievers/document_compressors/embeddings_filter.py index f004a17969..d8ac0de13f 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/embeddings_filter.py +++ b/libs/langchain/langchain/retrievers/document_compressors/embeddings_filter.py @@ -1,7 +1,7 @@ from typing import Callable, Dict, Optional, Sequence import numpy as np -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import Callbacks from langchain.document_transformers.embeddings_redundant_filter import ( diff --git a/libs/langchain/langchain/retrievers/ensemble.py b/libs/langchain/langchain/retrievers/ensemble.py index b01a33fab6..89e49aaedc 100644 --- a/libs/langchain/langchain/retrievers/ensemble.py +++ b/libs/langchain/langchain/retrievers/ensemble.py @@ -4,7 +4,7 @@ multiple retrievers by using weighted Reciprocal Rank Fusion """ from typing import Any, Dict, List -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForRetrieverRun, diff --git a/libs/langchain/langchain/retrievers/google_cloud_enterprise_search.py b/libs/langchain/langchain/retrievers/google_cloud_enterprise_search.py index 0d76022ef7..8c869e7fdb 100644 --- a/libs/langchain/langchain/retrievers/google_cloud_enterprise_search.py +++ b/libs/langchain/langchain/retrievers/google_cloud_enterprise_search.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence -from pydantic import Extra, Field, root_validator +from pydantic_v1 import Extra, Field, root_validator from langchain.callbacks.manager import CallbackManagerForRetrieverRun from langchain.schema import BaseRetriever, Document diff --git a/libs/langchain/langchain/retrievers/kendra.py b/libs/langchain/langchain/retrievers/kendra.py index c1656a3a6c..17b176d666 100644 --- a/libs/langchain/langchain/retrievers/kendra.py +++ b/libs/langchain/langchain/retrievers/kendra.py @@ -2,7 +2,7 @@ import re from abc import ABC, abstractmethod from typing import Any, Callable, Dict, List, Literal, Optional, Sequence, Union -from pydantic import BaseModel, Extra, root_validator, validator +from pydantic_v1 import BaseModel, Extra, root_validator, validator from langchain.callbacks.manager import CallbackManagerForRetrieverRun from langchain.docstore.document import Document @@ -49,7 +49,8 @@ DocumentAttributeValueType = Union[str, int, List[str], None] """Possible types of a DocumentAttributeValue. Dates are also represented as str.""" -class Highlight(BaseModel, extra=Extra.allow): +# Unexpected keyword argument "extra" for "__init_subclass__" of "object" +class Highlight(BaseModel, extra=Extra.allow): # type: ignore[call-arg] """ Represents the information that can be used to highlight key words in the excerpt. @@ -65,7 +66,8 @@ class Highlight(BaseModel, extra=Extra.allow): """The highlight type: STANDARD or THESAURUS_SYNONYM.""" -class TextWithHighLights(BaseModel, extra=Extra.allow): +# Unexpected keyword argument "extra" for "__init_subclass__" of "object" +class TextWithHighLights(BaseModel, extra=Extra.allow): # type: ignore[call-arg] """Text with highlights.""" Text: str @@ -74,14 +76,18 @@ class TextWithHighLights(BaseModel, extra=Extra.allow): """The highlights.""" -class AdditionalResultAttributeValue(BaseModel, extra=Extra.allow): +# Unexpected keyword argument "extra" for "__init_subclass__" of "object" +class AdditionalResultAttributeValue( # type: ignore[call-arg] + BaseModel, extra=Extra.allow +): """The value of an additional result attribute.""" TextWithHighlightsValue: TextWithHighLights """The text with highlights value.""" -class AdditionalResultAttribute(BaseModel, extra=Extra.allow): +# Unexpected keyword argument "extra" for "__init_subclass__" of "object" +class AdditionalResultAttribute(BaseModel, extra=Extra.allow): # type: ignore[call-arg] """An additional result attribute.""" Key: str @@ -95,7 +101,8 @@ class AdditionalResultAttribute(BaseModel, extra=Extra.allow): return self.Value.TextWithHighlightsValue.Text -class DocumentAttributeValue(BaseModel, extra=Extra.allow): +# Unexpected keyword argument "extra" for "__init_subclass__" of "object" +class DocumentAttributeValue(BaseModel, extra=Extra.allow): # type: ignore[call-arg] """The value of a document attribute.""" DateValue: Optional[str] @@ -125,7 +132,8 @@ class DocumentAttributeValue(BaseModel, extra=Extra.allow): return None -class DocumentAttribute(BaseModel, extra=Extra.allow): +# Unexpected keyword argument "extra" for "__init_subclass__" of "object" +class DocumentAttribute(BaseModel, extra=Extra.allow): # type: ignore[call-arg] """A document attribute.""" Key: str @@ -134,7 +142,8 @@ class DocumentAttribute(BaseModel, extra=Extra.allow): """The value of the attribute.""" -class ResultItem(BaseModel, ABC, extra=Extra.allow): +# Unexpected keyword argument "extra" for "__init_subclass__" of "object" +class ResultItem(BaseModel, ABC, extra=Extra.allow): # type: ignore[call-arg] """Abstract class that represents a result item.""" Id: Optional[str] @@ -254,7 +263,8 @@ class RetrieveResultItem(ResultItem): return self.Content or "" -class QueryResult(BaseModel, extra=Extra.allow): +# Unexpected keyword argument "extra" for "__init_subclass__" of "object" +class QueryResult(BaseModel, extra=Extra.allow): # type: ignore[call-arg] """ Represents an Amazon Kendra Query API search result, which is composed of: * Relevant suggested answers: either a text excerpt or table excerpt. @@ -266,7 +276,8 @@ class QueryResult(BaseModel, extra=Extra.allow): """The result items.""" -class RetrieveResult(BaseModel, extra=Extra.allow): +# Unexpected keyword argument "extra" for "__init_subclass__" of "object" +class RetrieveResult(BaseModel, extra=Extra.allow): # type: ignore[call-arg] """ Represents an Amazon Kendra Retrieve API search result, which is composed of: * relevant passages or text excerpts given an input query. diff --git a/libs/langchain/langchain/retrievers/llama_index.py b/libs/langchain/langchain/retrievers/llama_index.py index fe8e4f8b0f..e839ecb57c 100644 --- a/libs/langchain/langchain/retrievers/llama_index.py +++ b/libs/langchain/langchain/retrievers/llama_index.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, cast -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForRetrieverRun from langchain.schema import BaseRetriever, Document diff --git a/libs/langchain/langchain/retrievers/metal.py b/libs/langchain/langchain/retrievers/metal.py index b4faaeab3d..f5cddf20a9 100644 --- a/libs/langchain/langchain/retrievers/metal.py +++ b/libs/langchain/langchain/retrievers/metal.py @@ -1,6 +1,6 @@ from typing import Any, List, Optional -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import CallbackManagerForRetrieverRun from langchain.schema import BaseRetriever, Document diff --git a/libs/langchain/langchain/retrievers/milvus.py b/libs/langchain/langchain/retrievers/milvus.py index bc35e73184..3f6c9d9b5e 100644 --- a/libs/langchain/langchain/retrievers/milvus.py +++ b/libs/langchain/langchain/retrievers/milvus.py @@ -2,7 +2,7 @@ import warnings from typing import Any, Dict, List, Optional -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import CallbackManagerForRetrieverRun from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/retrievers/multi_query.py b/libs/langchain/langchain/retrievers/multi_query.py index 4d9520c026..eb93ca6dd9 100644 --- a/libs/langchain/langchain/retrievers/multi_query.py +++ b/libs/langchain/langchain/retrievers/multi_query.py @@ -1,7 +1,7 @@ import logging from typing import List -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForRetrieverRun from langchain.chains.llm import LLMChain diff --git a/libs/langchain/langchain/retrievers/pinecone_hybrid_search.py b/libs/langchain/langchain/retrievers/pinecone_hybrid_search.py index 97d562421d..956c84b540 100644 --- a/libs/langchain/langchain/retrievers/pinecone_hybrid_search.py +++ b/libs/langchain/langchain/retrievers/pinecone_hybrid_search.py @@ -3,7 +3,7 @@ import hashlib from typing import Any, Dict, List, Optional -from pydantic import Extra, root_validator +from pydantic_v1 import Extra, root_validator from langchain.callbacks.manager import CallbackManagerForRetrieverRun from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/retrievers/self_query/base.py b/libs/langchain/langchain/retrievers/self_query/base.py index 15463751b4..d444a043c2 100644 --- a/libs/langchain/langchain/retrievers/self_query/base.py +++ b/libs/langchain/langchain/retrievers/self_query/base.py @@ -2,7 +2,7 @@ from typing import Any, Dict, List, Optional, Type, cast -from pydantic import BaseModel, Field, root_validator +from pydantic_v1 import BaseModel, Field, root_validator from langchain import LLMChain from langchain.callbacks.manager import CallbackManagerForRetrieverRun diff --git a/libs/langchain/langchain/retrievers/time_weighted_retriever.py b/libs/langchain/langchain/retrievers/time_weighted_retriever.py index b2aebfa913..169d101157 100644 --- a/libs/langchain/langchain/retrievers/time_weighted_retriever.py +++ b/libs/langchain/langchain/retrievers/time_weighted_retriever.py @@ -2,7 +2,7 @@ import datetime from copy import deepcopy from typing import Any, Dict, List, Optional, Tuple -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForRetrieverRun from langchain.schema import BaseRetriever, Document diff --git a/libs/langchain/langchain/retrievers/weaviate_hybrid_search.py b/libs/langchain/langchain/retrievers/weaviate_hybrid_search.py index 2bd64ed3f1..b53e1df160 100644 --- a/libs/langchain/langchain/retrievers/weaviate_hybrid_search.py +++ b/libs/langchain/langchain/retrievers/weaviate_hybrid_search.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional, cast from uuid import uuid4 -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import CallbackManagerForRetrieverRun from langchain.docstore.document import Document diff --git a/libs/langchain/langchain/retrievers/web_research.py b/libs/langchain/langchain/retrievers/web_research.py index 478005cb35..abc4daeb6b 100644 --- a/libs/langchain/langchain/retrievers/web_research.py +++ b/libs/langchain/langchain/retrievers/web_research.py @@ -2,7 +2,7 @@ import logging import re from typing import List, Optional -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForRetrieverRun, diff --git a/libs/langchain/langchain/retrievers/zep.py b/libs/langchain/langchain/retrievers/zep.py index 6e8876b82e..e8469185b1 100644 --- a/libs/langchain/langchain/retrievers/zep.py +++ b/libs/langchain/langchain/retrievers/zep.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, Any, Dict, List, Optional -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForRetrieverRun, diff --git a/libs/langchain/langchain/retrievers/zilliz.py b/libs/langchain/langchain/retrievers/zilliz.py index e023bac771..81cdfc5257 100644 --- a/libs/langchain/langchain/retrievers/zilliz.py +++ b/libs/langchain/langchain/retrievers/zilliz.py @@ -1,7 +1,7 @@ import warnings from typing import Any, Dict, List, Optional -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import CallbackManagerForRetrieverRun from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/runnables/openai_functions.py b/libs/langchain/langchain/runnables/openai_functions.py index 55c9765d20..b97c9f213c 100644 --- a/libs/langchain/langchain/runnables/openai_functions.py +++ b/libs/langchain/langchain/runnables/openai_functions.py @@ -38,7 +38,7 @@ class OpenAIFunctionsRouter(RunnableBinding[ChatGeneration, Any]): if functions is not None: assert len(functions) == len(runnables) assert all(func["name"] in runnables for func in functions) - router = ( + router: Runnable[ChatGeneration, Any] = ( JsonOutputFunctionsParser(args_only=False) | {"key": itemgetter("name"), "input": itemgetter("arguments")} | RouterRunnable(runnables) diff --git a/libs/langchain/langchain/schema/document.py b/libs/langchain/langchain/schema/document.py index a05df15db6..518d390f78 100644 --- a/libs/langchain/langchain/schema/document.py +++ b/libs/langchain/langchain/schema/document.py @@ -3,7 +3,7 @@ from __future__ import annotations from abc import ABC, abstractmethod from typing import Any, Sequence -from pydantic import Field +from pydantic_v1 import Field from langchain.load.serializable import Serializable diff --git a/libs/langchain/langchain/schema/messages.py b/libs/langchain/langchain/schema/messages.py index 3d6219f7d0..5f00bf32bb 100644 --- a/libs/langchain/langchain/schema/messages.py +++ b/libs/langchain/langchain/schema/messages.py @@ -3,7 +3,7 @@ from __future__ import annotations from abc import abstractmethod from typing import TYPE_CHECKING, Any, Dict, List, Sequence -from pydantic import Field +from pydantic_v1 import Field from langchain.load.serializable import Serializable diff --git a/libs/langchain/langchain/schema/output.py b/libs/langchain/langchain/schema/output.py index 10b9923bad..990af336bf 100644 --- a/libs/langchain/langchain/schema/output.py +++ b/libs/langchain/langchain/schema/output.py @@ -4,7 +4,7 @@ from copy import deepcopy from typing import Any, Dict, List, Optional from uuid import UUID -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.load.serializable import Serializable from langchain.schema.messages import BaseMessage, BaseMessageChunk diff --git a/libs/langchain/langchain/schema/prompt_template.py b/libs/langchain/langchain/schema/prompt_template.py index b8eed33319..3434fd42f8 100644 --- a/libs/langchain/langchain/schema/prompt_template.py +++ b/libs/langchain/langchain/schema/prompt_template.py @@ -6,7 +6,7 @@ from pathlib import Path from typing import Any, Callable, Dict, List, Mapping, Optional, Union import yaml -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from langchain.load.serializable import Serializable from langchain.schema.document import Document diff --git a/libs/langchain/langchain/schema/runnable/base.py b/libs/langchain/langchain/schema/runnable/base.py index 95344cdf0a..2deb87e4de 100644 --- a/libs/langchain/langchain/schema/runnable/base.py +++ b/libs/langchain/langchain/schema/runnable/base.py @@ -23,7 +23,7 @@ from typing import ( cast, ) -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.base import BaseCallbackManager from langchain.load.dump import dumpd diff --git a/libs/langchain/langchain/smith/evaluation/config.py b/libs/langchain/langchain/smith/evaluation/config.py index 21cb484821..3bddffd2cb 100644 --- a/libs/langchain/langchain/smith/evaluation/config.py +++ b/libs/langchain/langchain/smith/evaluation/config.py @@ -3,7 +3,7 @@ from typing import Any, Dict, List, Optional, Union from langsmith import RunEvaluator -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.embeddings.base import Embeddings from langchain.evaluation.criteria.eval_chain import CRITERIA_TYPE diff --git a/libs/langchain/langchain/tools/amadeus/base.py b/libs/langchain/langchain/tools/amadeus/base.py index fc0c907e9c..90e0ff35e3 100644 --- a/libs/langchain/langchain/tools/amadeus/base.py +++ b/libs/langchain/langchain/tools/amadeus/base.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import TYPE_CHECKING -from pydantic import Field +from pydantic_v1 import Field from langchain.tools.amadeus.utils import authenticate from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/amadeus/closest_airport.py b/libs/langchain/langchain/tools/amadeus/closest_airport.py index a92066e402..22133b106a 100644 --- a/libs/langchain/langchain/tools/amadeus/closest_airport.py +++ b/libs/langchain/langchain/tools/amadeus/closest_airport.py @@ -1,6 +1,6 @@ from typing import Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.chains import LLMChain diff --git a/libs/langchain/langchain/tools/amadeus/flight_search.py b/libs/langchain/langchain/tools/amadeus/flight_search.py index 819cd1d296..bd88cd3a07 100644 --- a/libs/langchain/langchain/tools/amadeus/flight_search.py +++ b/libs/langchain/langchain/tools/amadeus/flight_search.py @@ -2,7 +2,7 @@ import logging from datetime import datetime as dt from typing import Dict, Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.amadeus.base import AmadeusBaseTool diff --git a/libs/langchain/langchain/tools/arxiv/tool.py b/libs/langchain/langchain/tools/arxiv/tool.py index 768e4eb2a2..224c043270 100644 --- a/libs/langchain/langchain/tools/arxiv/tool.py +++ b/libs/langchain/langchain/tools/arxiv/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/azure_cognitive_services/form_recognizer.py b/libs/langchain/langchain/tools/azure_cognitive_services/form_recognizer.py index 0dfb4d2b57..be5cd20629 100644 --- a/libs/langchain/langchain/tools/azure_cognitive_services/form_recognizer.py +++ b/libs/langchain/langchain/tools/azure_cognitive_services/form_recognizer.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Any, Dict, List, Optional -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.azure_cognitive_services.utils import detect_file_src_type diff --git a/libs/langchain/langchain/tools/azure_cognitive_services/image_analysis.py b/libs/langchain/langchain/tools/azure_cognitive_services/image_analysis.py index ecac290e39..c39b219096 100644 --- a/libs/langchain/langchain/tools/azure_cognitive_services/image_analysis.py +++ b/libs/langchain/langchain/tools/azure_cognitive_services/image_analysis.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Any, Dict, Optional -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.azure_cognitive_services.utils import detect_file_src_type diff --git a/libs/langchain/langchain/tools/azure_cognitive_services/speech2text.py b/libs/langchain/langchain/tools/azure_cognitive_services/speech2text.py index 98b3e76055..f3a9bf46b0 100644 --- a/libs/langchain/langchain/tools/azure_cognitive_services/speech2text.py +++ b/libs/langchain/langchain/tools/azure_cognitive_services/speech2text.py @@ -4,7 +4,7 @@ import logging import time from typing import Any, Dict, Optional -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.azure_cognitive_services.utils import ( diff --git a/libs/langchain/langchain/tools/azure_cognitive_services/text2speech.py b/libs/langchain/langchain/tools/azure_cognitive_services/text2speech.py index cd51a78c12..78250f39b8 100644 --- a/libs/langchain/langchain/tools/azure_cognitive_services/text2speech.py +++ b/libs/langchain/langchain/tools/azure_cognitive_services/text2speech.py @@ -4,7 +4,7 @@ import logging import tempfile from typing import Any, Dict, Optional -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/base.py b/libs/langchain/langchain/tools/base.py index 732940bd06..40b061e542 100644 --- a/libs/langchain/langchain/tools/base.py +++ b/libs/langchain/langchain/tools/base.py @@ -8,7 +8,7 @@ from functools import partial from inspect import signature from typing import Any, Awaitable, Callable, Dict, List, Optional, Tuple, Type, Union -from pydantic import ( +from pydantic_v1 import ( BaseModel, Extra, Field, @@ -16,7 +16,15 @@ from pydantic import ( root_validator, validate_arguments, ) -from pydantic.main import ModelMetaclass + +# The metaclass must be imported directly from the pydantic module rather than +# from the proxy module, otherwise it looks like inconsistent metaclasses are +# used raising an exception. +try: + from pydantic.v1.main import ModelMetaclass +except ImportError: + from pydantic.main import ModelMetaclass + from langchain.callbacks.base import BaseCallbackManager from langchain.callbacks.manager import ( diff --git a/libs/langchain/langchain/tools/dataforseo_api_search/tool.py b/libs/langchain/langchain/tools/dataforseo_api_search/tool.py index c22c7254ea..9dfc3c306f 100644 --- a/libs/langchain/langchain/tools/dataforseo_api_search/tool.py +++ b/libs/langchain/langchain/tools/dataforseo_api_search/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from pydantic.fields import Field +from pydantic_v1.fields import Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/ddg_search/tool.py b/libs/langchain/langchain/tools/ddg_search/tool.py index 53aef10aee..e66aaa2569 100644 --- a/libs/langchain/langchain/tools/ddg_search/tool.py +++ b/libs/langchain/langchain/tools/ddg_search/tool.py @@ -3,7 +3,7 @@ import warnings from typing import Any, Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/file_management/copy.py b/libs/langchain/langchain/tools/file_management/copy.py index 525e03a4fe..fabd94d9c6 100644 --- a/libs/langchain/langchain/tools/file_management/copy.py +++ b/libs/langchain/langchain/tools/file_management/copy.py @@ -1,7 +1,7 @@ import shutil from typing import Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/file_management/delete.py b/libs/langchain/langchain/tools/file_management/delete.py index f1a097641c..8db201a5fc 100644 --- a/libs/langchain/langchain/tools/file_management/delete.py +++ b/libs/langchain/langchain/tools/file_management/delete.py @@ -1,7 +1,7 @@ import os from typing import Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/file_management/file_search.py b/libs/langchain/langchain/tools/file_management/file_search.py index c197f03a49..f8844c3301 100644 --- a/libs/langchain/langchain/tools/file_management/file_search.py +++ b/libs/langchain/langchain/tools/file_management/file_search.py @@ -2,7 +2,7 @@ import fnmatch import os from typing import Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/file_management/list_dir.py b/libs/langchain/langchain/tools/file_management/list_dir.py index 621a11947d..54e35b68a9 100644 --- a/libs/langchain/langchain/tools/file_management/list_dir.py +++ b/libs/langchain/langchain/tools/file_management/list_dir.py @@ -1,7 +1,7 @@ import os from typing import Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/file_management/move.py b/libs/langchain/langchain/tools/file_management/move.py index 6d9c441daa..246a2b6bf5 100644 --- a/libs/langchain/langchain/tools/file_management/move.py +++ b/libs/langchain/langchain/tools/file_management/move.py @@ -1,7 +1,7 @@ import shutil from typing import Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/file_management/read.py b/libs/langchain/langchain/tools/file_management/read.py index 11a7a923ee..016ed40104 100644 --- a/libs/langchain/langchain/tools/file_management/read.py +++ b/libs/langchain/langchain/tools/file_management/read.py @@ -1,6 +1,6 @@ from typing import Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/file_management/utils.py b/libs/langchain/langchain/tools/file_management/utils.py index 788823fecd..9fccad2204 100644 --- a/libs/langchain/langchain/tools/file_management/utils.py +++ b/libs/langchain/langchain/tools/file_management/utils.py @@ -2,7 +2,7 @@ import sys from pathlib import Path from typing import Optional -from pydantic import BaseModel +from pydantic_v1 import BaseModel def is_relative_to(path: Path, root: Path) -> bool: diff --git a/libs/langchain/langchain/tools/file_management/write.py b/libs/langchain/langchain/tools/file_management/write.py index 478fca2cc1..81bbd7ba83 100644 --- a/libs/langchain/langchain/tools/file_management/write.py +++ b/libs/langchain/langchain/tools/file_management/write.py @@ -1,6 +1,6 @@ from typing import Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/github/tool.py b/libs/langchain/langchain/tools/github/tool.py index 524b2a4f88..d053689910 100644 --- a/libs/langchain/langchain/tools/github/tool.py +++ b/libs/langchain/langchain/tools/github/tool.py @@ -9,7 +9,7 @@ To use this tool, you must first set as environment variables: """ from typing import Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/gmail/base.py b/libs/langchain/langchain/tools/gmail/base.py index c306dce912..b55d6ac212 100644 --- a/libs/langchain/langchain/tools/gmail/base.py +++ b/libs/langchain/langchain/tools/gmail/base.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import TYPE_CHECKING -from pydantic import Field +from pydantic_v1 import Field from langchain.tools.base import BaseTool from langchain.tools.gmail.utils import build_resource_service diff --git a/libs/langchain/langchain/tools/gmail/create_draft.py b/libs/langchain/langchain/tools/gmail/create_draft.py index 2c944270b6..d7213f965f 100644 --- a/libs/langchain/langchain/tools/gmail/create_draft.py +++ b/libs/langchain/langchain/tools/gmail/create_draft.py @@ -2,7 +2,7 @@ import base64 from email.message import EmailMessage from typing import List, Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.gmail.base import GmailBaseTool diff --git a/libs/langchain/langchain/tools/gmail/get_message.py b/libs/langchain/langchain/tools/gmail/get_message.py index 262dbd063b..3089839de2 100644 --- a/libs/langchain/langchain/tools/gmail/get_message.py +++ b/libs/langchain/langchain/tools/gmail/get_message.py @@ -2,7 +2,7 @@ import base64 import email from typing import Dict, Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.gmail.base import GmailBaseTool diff --git a/libs/langchain/langchain/tools/gmail/get_thread.py b/libs/langchain/langchain/tools/gmail/get_thread.py index 0db1f8cd58..83626148ac 100644 --- a/libs/langchain/langchain/tools/gmail/get_thread.py +++ b/libs/langchain/langchain/tools/gmail/get_thread.py @@ -1,6 +1,6 @@ from typing import Dict, Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.gmail.base import GmailBaseTool diff --git a/libs/langchain/langchain/tools/gmail/search.py b/libs/langchain/langchain/tools/gmail/search.py index 16041a4aaf..c10b71a24a 100644 --- a/libs/langchain/langchain/tools/gmail/search.py +++ b/libs/langchain/langchain/tools/gmail/search.py @@ -3,7 +3,7 @@ import email from enum import Enum from typing import Any, Dict, List, Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.gmail.base import GmailBaseTool diff --git a/libs/langchain/langchain/tools/gmail/send_message.py b/libs/langchain/langchain/tools/gmail/send_message.py index 76576149fa..6916f9d887 100644 --- a/libs/langchain/langchain/tools/gmail/send_message.py +++ b/libs/langchain/langchain/tools/gmail/send_message.py @@ -4,7 +4,7 @@ from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from typing import Any, Dict, List, Optional, Union -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.gmail.base import GmailBaseTool diff --git a/libs/langchain/langchain/tools/google_places/tool.py b/libs/langchain/langchain/tools/google_places/tool.py index 644ba134c7..c738c5eb8b 100644 --- a/libs/langchain/langchain/tools/google_places/tool.py +++ b/libs/langchain/langchain/tools/google_places/tool.py @@ -2,7 +2,7 @@ from typing import Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/google_serper/tool.py b/libs/langchain/langchain/tools/google_serper/tool.py index f139263edd..7773249d61 100644 --- a/libs/langchain/langchain/tools/google_serper/tool.py +++ b/libs/langchain/langchain/tools/google_serper/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from pydantic.fields import Field +from pydantic_v1.fields import Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/human/tool.py b/libs/langchain/langchain/tools/human/tool.py index 4d8f5fd901..d16e62a158 100644 --- a/libs/langchain/langchain/tools/human/tool.py +++ b/libs/langchain/langchain/tools/human/tool.py @@ -2,7 +2,7 @@ from typing import Callable, Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/jira/tool.py b/libs/langchain/langchain/tools/jira/tool.py index 26a9c0d914..fa493cc23e 100644 --- a/libs/langchain/langchain/tools/jira/tool.py +++ b/libs/langchain/langchain/tools/jira/tool.py @@ -30,7 +30,7 @@ agent = initialize_agent( """ from typing import Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/json/tool.py b/libs/langchain/langchain/tools/json/tool.py index 6c75de20ce..ad909a1471 100644 --- a/libs/langchain/langchain/tools/json/tool.py +++ b/libs/langchain/langchain/tools/json/tool.py @@ -7,7 +7,7 @@ import re from pathlib import Path from typing import Dict, List, Optional, Union -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/multion/create_session.py b/libs/langchain/langchain/tools/multion/create_session.py index b0551e49ca..a434d5edb0 100644 --- a/libs/langchain/langchain/tools/multion/create_session.py +++ b/libs/langchain/langchain/tools/multion/create_session.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/multion/update_session.py b/libs/langchain/langchain/tools/multion/update_session.py index 1f20d70d65..0a2f304127 100644 --- a/libs/langchain/langchain/tools/multion/update_session.py +++ b/libs/langchain/langchain/tools/multion/update_session.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/nuclia/tool.py b/libs/langchain/langchain/tools/nuclia/tool.py index 054a439dbb..0d40a43b3d 100644 --- a/libs/langchain/langchain/tools/nuclia/tool.py +++ b/libs/langchain/langchain/tools/nuclia/tool.py @@ -16,7 +16,7 @@ import os from typing import Any, Dict, Optional, Type, Union import requests -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/office365/base.py b/libs/langchain/langchain/tools/office365/base.py index f7f6659e12..90d2db401f 100644 --- a/libs/langchain/langchain/tools/office365/base.py +++ b/libs/langchain/langchain/tools/office365/base.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import TYPE_CHECKING -from pydantic import Field +from pydantic_v1 import Field from langchain.tools.base import BaseTool from langchain.tools.office365.utils import authenticate diff --git a/libs/langchain/langchain/tools/office365/create_draft_message.py b/libs/langchain/langchain/tools/office365/create_draft_message.py index 68b161310b..0d109ffbc2 100644 --- a/libs/langchain/langchain/tools/office365/create_draft_message.py +++ b/libs/langchain/langchain/tools/office365/create_draft_message.py @@ -1,6 +1,6 @@ from typing import List, Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.office365.base import O365BaseTool diff --git a/libs/langchain/langchain/tools/office365/events_search.py b/libs/langchain/langchain/tools/office365/events_search.py index fba8fcb4f0..ec3ab19c52 100644 --- a/libs/langchain/langchain/tools/office365/events_search.py +++ b/libs/langchain/langchain/tools/office365/events_search.py @@ -7,7 +7,7 @@ https://learn.microsoft.com/en-us/graph/auth/ from datetime import datetime as dt from typing import Any, Dict, List, Optional, Type -from pydantic import BaseModel, Extra, Field +from pydantic_v1 import BaseModel, Extra, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.office365.base import O365BaseTool diff --git a/libs/langchain/langchain/tools/office365/messages_search.py b/libs/langchain/langchain/tools/office365/messages_search.py index 435ba58d6a..67182664fb 100644 --- a/libs/langchain/langchain/tools/office365/messages_search.py +++ b/libs/langchain/langchain/tools/office365/messages_search.py @@ -6,7 +6,7 @@ https://learn.microsoft.com/en-us/graph/auth/ from typing import Any, Dict, List, Optional, Type -from pydantic import BaseModel, Extra, Field +from pydantic_v1 import BaseModel, Extra, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.office365.base import O365BaseTool diff --git a/libs/langchain/langchain/tools/office365/send_event.py b/libs/langchain/langchain/tools/office365/send_event.py index f19992b321..8d925c28e1 100644 --- a/libs/langchain/langchain/tools/office365/send_event.py +++ b/libs/langchain/langchain/tools/office365/send_event.py @@ -7,7 +7,7 @@ https://learn.microsoft.com/en-us/graph/auth/ from datetime import datetime as dt from typing import List, Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.office365.base import O365BaseTool diff --git a/libs/langchain/langchain/tools/office365/send_message.py b/libs/langchain/langchain/tools/office365/send_message.py index 9104d1685c..b420ec0f3b 100644 --- a/libs/langchain/langchain/tools/office365/send_message.py +++ b/libs/langchain/langchain/tools/office365/send_message.py @@ -1,6 +1,6 @@ from typing import List, Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.office365.base import O365BaseTool diff --git a/libs/langchain/langchain/tools/openapi/utils/api_models.py b/libs/langchain/langchain/tools/openapi/utils/api_models.py index 42e8f13a35..b40dde124d 100644 --- a/libs/langchain/langchain/tools/openapi/utils/api_models.py +++ b/libs/langchain/langchain/tools/openapi/utils/api_models.py @@ -4,7 +4,7 @@ from enum import Enum from typing import Any, Dict, List, Optional, Sequence, Tuple, Type, Union from openapi_schema_pydantic import MediaType, Parameter, Reference, RequestBody, Schema -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.tools.openapi.utils.openapi_utils import HTTPVerb, OpenAPISpec diff --git a/libs/langchain/langchain/tools/openweathermap/tool.py b/libs/langchain/langchain/tools/openweathermap/tool.py index 0290e144a7..2d8b9e5777 100644 --- a/libs/langchain/langchain/tools/openweathermap/tool.py +++ b/libs/langchain/langchain/tools/openweathermap/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/playwright/base.py b/libs/langchain/langchain/tools/playwright/base.py index 7930a29fca..139195994d 100644 --- a/libs/langchain/langchain/tools/playwright/base.py +++ b/libs/langchain/langchain/tools/playwright/base.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, Optional, Tuple, Type -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/playwright/click.py b/libs/langchain/langchain/tools/playwright/click.py index d87248f73a..b5191733ce 100644 --- a/libs/langchain/langchain/tools/playwright/click.py +++ b/libs/langchain/langchain/tools/playwright/click.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/playwright/current_page.py b/libs/langchain/langchain/tools/playwright/current_page.py index 6ac77e3145..4446090579 100644 --- a/libs/langchain/langchain/tools/playwright/current_page.py +++ b/libs/langchain/langchain/tools/playwright/current_page.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Optional, Type -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/playwright/extract_hyperlinks.py b/libs/langchain/langchain/tools/playwright/extract_hyperlinks.py index 885059786a..f1ddca25df 100644 --- a/libs/langchain/langchain/tools/playwright/extract_hyperlinks.py +++ b/libs/langchain/langchain/tools/playwright/extract_hyperlinks.py @@ -3,7 +3,7 @@ from __future__ import annotations import json from typing import TYPE_CHECKING, Any, Optional, Type -from pydantic import BaseModel, Field, root_validator +from pydantic_v1 import BaseModel, Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/playwright/extract_text.py b/libs/langchain/langchain/tools/playwright/extract_text.py index 210cde907e..82cc707f64 100644 --- a/libs/langchain/langchain/tools/playwright/extract_text.py +++ b/libs/langchain/langchain/tools/playwright/extract_text.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Optional, Type -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/playwright/get_elements.py b/libs/langchain/langchain/tools/playwright/get_elements.py index 9a7c33d848..6684055441 100644 --- a/libs/langchain/langchain/tools/playwright/get_elements.py +++ b/libs/langchain/langchain/tools/playwright/get_elements.py @@ -3,7 +3,7 @@ from __future__ import annotations import json from typing import TYPE_CHECKING, List, Optional, Sequence, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/playwright/navigate.py b/libs/langchain/langchain/tools/playwright/navigate.py index 14065d6c7b..d59f4558a4 100644 --- a/libs/langchain/langchain/tools/playwright/navigate.py +++ b/libs/langchain/langchain/tools/playwright/navigate.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/playwright/navigate_back.py b/libs/langchain/langchain/tools/playwright/navigate_back.py index da4d357754..16c8532513 100644 --- a/libs/langchain/langchain/tools/playwright/navigate_back.py +++ b/libs/langchain/langchain/tools/playwright/navigate_back.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Optional, Type -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/plugin.py b/libs/langchain/langchain/tools/plugin.py index eafca8491a..f54d7dc40e 100644 --- a/libs/langchain/langchain/tools/plugin.py +++ b/libs/langchain/langchain/tools/plugin.py @@ -5,7 +5,7 @@ from typing import Optional, Type import requests import yaml -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/powerbi/tool.py b/libs/langchain/langchain/tools/powerbi/tool.py index a201875cd9..c9f7ee835e 100644 --- a/libs/langchain/langchain/tools/powerbi/tool.py +++ b/libs/langchain/langchain/tools/powerbi/tool.py @@ -3,7 +3,7 @@ import logging from time import perf_counter from typing import Any, Dict, Optional, Tuple -from pydantic import Field, validator +from pydantic_v1 import Field, validator from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/pubmed/tool.py b/libs/langchain/langchain/tools/pubmed/tool.py index dac103de73..6a82eef66e 100644 --- a/libs/langchain/langchain/tools/pubmed/tool.py +++ b/libs/langchain/langchain/tools/pubmed/tool.py @@ -1,6 +1,6 @@ from typing import Optional -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/python/tool.py b/libs/langchain/langchain/tools/python/tool.py index a820ba6140..8c8bb11ef7 100644 --- a/libs/langchain/langchain/tools/python/tool.py +++ b/libs/langchain/langchain/tools/python/tool.py @@ -8,7 +8,7 @@ from contextlib import redirect_stdout from io import StringIO from typing import Any, Dict, Optional -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/requests/tool.py b/libs/langchain/langchain/tools/requests/tool.py index bc032cbd16..e3abf8a0a3 100644 --- a/libs/langchain/langchain/tools/requests/tool.py +++ b/libs/langchain/langchain/tools/requests/tool.py @@ -3,7 +3,7 @@ import json from typing import Any, Dict, Optional -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/scenexplain/tool.py b/libs/langchain/langchain/tools/scenexplain/tool.py index 7ad619c1e8..9858e2b1e1 100644 --- a/libs/langchain/langchain/tools/scenexplain/tool.py +++ b/libs/langchain/langchain/tools/scenexplain/tool.py @@ -1,7 +1,7 @@ """Tool for the SceneXplain API.""" from typing import Optional -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool diff --git a/libs/langchain/langchain/tools/searx_search/tool.py b/libs/langchain/langchain/tools/searx_search/tool.py index 3de5521c65..422ef73941 100644 --- a/libs/langchain/langchain/tools/searx_search/tool.py +++ b/libs/langchain/langchain/tools/searx_search/tool.py @@ -1,7 +1,7 @@ """Tool for the SearxNG search API.""" from typing import Optional -from pydantic import Extra +from pydantic_v1 import Extra from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/shell/tool.py b/libs/langchain/langchain/tools/shell/tool.py index 28f2edcf22..82125e013a 100644 --- a/libs/langchain/langchain/tools/shell/tool.py +++ b/libs/langchain/langchain/tools/shell/tool.py @@ -3,7 +3,7 @@ import platform import warnings from typing import List, Optional, Type, Union -from pydantic import BaseModel, Field, root_validator +from pydantic_v1 import BaseModel, Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/sleep/tool.py b/libs/langchain/langchain/tools/sleep/tool.py index 707cc329b7..348b9366c7 100644 --- a/libs/langchain/langchain/tools/sleep/tool.py +++ b/libs/langchain/langchain/tools/sleep/tool.py @@ -3,7 +3,7 @@ from asyncio import sleep as asleep from time import sleep from typing import Optional, Type -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/tools/spark_sql/tool.py b/libs/langchain/langchain/tools/spark_sql/tool.py index 89ea7dbf75..4b23d5305b 100644 --- a/libs/langchain/langchain/tools/spark_sql/tool.py +++ b/libs/langchain/langchain/tools/spark_sql/tool.py @@ -2,7 +2,7 @@ """Tools for interacting with Spark SQL.""" from typing import Any, Dict, Optional -from pydantic import BaseModel, Extra, Field, root_validator +from pydantic_v1 import BaseModel, Extra, Field, root_validator from langchain.schema.language_model import BaseLanguageModel from langchain.callbacks.manager import ( diff --git a/libs/langchain/langchain/tools/sql_database/tool.py b/libs/langchain/langchain/tools/sql_database/tool.py index 7ea40eb4b1..f9597df962 100644 --- a/libs/langchain/langchain/tools/sql_database/tool.py +++ b/libs/langchain/langchain/tools/sql_database/tool.py @@ -2,7 +2,7 @@ """Tools for interacting with a SQL database.""" from typing import Any, Dict, Optional -from pydantic import BaseModel, Extra, Field, root_validator +from pydantic_v1 import BaseModel, Extra, Field, root_validator from langchain.schema.language_model import BaseLanguageModel from langchain.callbacks.manager import ( diff --git a/libs/langchain/langchain/tools/steamship_image_generation/tool.py b/libs/langchain/langchain/tools/steamship_image_generation/tool.py index 1c9188a207..9184506088 100644 --- a/libs/langchain/langchain/tools/steamship_image_generation/tool.py +++ b/libs/langchain/langchain/tools/steamship_image_generation/tool.py @@ -16,7 +16,7 @@ from __future__ import annotations from enum import Enum from typing import TYPE_CHECKING, Dict, Optional -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools import BaseTool diff --git a/libs/langchain/langchain/tools/vectorstore/tool.py b/libs/langchain/langchain/tools/vectorstore/tool.py index ae77fa12f2..9fa0e0e420 100644 --- a/libs/langchain/langchain/tools/vectorstore/tool.py +++ b/libs/langchain/langchain/tools/vectorstore/tool.py @@ -3,7 +3,7 @@ import json from typing import Any, Dict, Optional -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.chains import RetrievalQA, RetrievalQAWithSourcesChain diff --git a/libs/langchain/langchain/tools/zapier/tool.py b/libs/langchain/langchain/tools/zapier/tool.py index 96b6209287..ec611836e0 100644 --- a/libs/langchain/langchain/tools/zapier/tool.py +++ b/libs/langchain/langchain/tools/zapier/tool.py @@ -79,7 +79,7 @@ agent.run(("Summarize the last email I received regarding Silicon Valley Bank. " """ from typing import Any, Dict, Optional -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, diff --git a/libs/langchain/langchain/utilities/arxiv.py b/libs/langchain/langchain/utilities/arxiv.py index bd4aa2f152..4c9ea6300e 100644 --- a/libs/langchain/langchain/utilities/arxiv.py +++ b/libs/langchain/langchain/utilities/arxiv.py @@ -3,7 +3,7 @@ import logging import os from typing import Any, Dict, List, Optional -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.schema import Document diff --git a/libs/langchain/langchain/utilities/awslambda.py b/libs/langchain/langchain/utilities/awslambda.py index 64782905e3..7bbb619b82 100644 --- a/libs/langchain/langchain/utilities/awslambda.py +++ b/libs/langchain/langchain/utilities/awslambda.py @@ -2,7 +2,7 @@ import json from typing import Any, Dict, Optional -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator class LambdaWrapper(BaseModel): diff --git a/libs/langchain/langchain/utilities/bibtex.py b/libs/langchain/langchain/utilities/bibtex.py index afafaef220..84e749eb19 100644 --- a/libs/langchain/langchain/utilities/bibtex.py +++ b/libs/langchain/langchain/utilities/bibtex.py @@ -2,7 +2,7 @@ import logging from typing import Any, Dict, List, Mapping -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/utilities/bing_search.py b/libs/langchain/langchain/utilities/bing_search.py index 6dc2fe4073..eb6d99dad1 100644 --- a/libs/langchain/langchain/utilities/bing_search.py +++ b/libs/langchain/langchain/utilities/bing_search.py @@ -6,7 +6,7 @@ https://levelup.gitconnected.com/api-tutorial-how-to-use-bing-web-search-api-in- from typing import Dict, List import requests -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utilities/brave_search.py b/libs/langchain/langchain/utilities/brave_search.py index 0e870b8f62..3932dbc08d 100644 --- a/libs/langchain/langchain/utilities/brave_search.py +++ b/libs/langchain/langchain/utilities/brave_search.py @@ -2,7 +2,7 @@ import json from typing import List import requests -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.schema import Document diff --git a/libs/langchain/langchain/utilities/dalle_image_generator.py b/libs/langchain/langchain/utilities/dalle_image_generator.py index 8042f4cf6d..29286aaac2 100644 --- a/libs/langchain/langchain/utilities/dalle_image_generator.py +++ b/libs/langchain/langchain/utilities/dalle_image_generator.py @@ -1,7 +1,7 @@ """Utility that calls OpenAI's Dall-E Image Generator.""" from typing import Any, Dict, Optional -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utilities/dataforseo_api_search.py b/libs/langchain/langchain/utilities/dataforseo_api_search.py index b8fc9ce864..4f46faf86b 100644 --- a/libs/langchain/langchain/utilities/dataforseo_api_search.py +++ b/libs/langchain/langchain/utilities/dataforseo_api_search.py @@ -4,7 +4,7 @@ from urllib.parse import quote import aiohttp import requests -from pydantic import BaseModel, Extra, Field, root_validator +from pydantic_v1 import BaseModel, Extra, Field, root_validator from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utilities/duckduckgo_search.py b/libs/langchain/langchain/utilities/duckduckgo_search.py index 0d9e127058..78073ffa4d 100644 --- a/libs/langchain/langchain/utilities/duckduckgo_search.py +++ b/libs/langchain/langchain/utilities/duckduckgo_search.py @@ -5,8 +5,8 @@ https://pypi.org/project/duckduckgo-search/ """ from typing import Dict, List, Optional -from pydantic import BaseModel, Extra -from pydantic.class_validators import root_validator +from pydantic_v1 import BaseModel, Extra +from pydantic_v1.class_validators import root_validator class DuckDuckGoSearchAPIWrapper(BaseModel): diff --git a/libs/langchain/langchain/utilities/github.py b/libs/langchain/langchain/utilities/github.py index 7d350a5592..ae16aa671d 100644 --- a/libs/langchain/langchain/utilities/github.py +++ b/libs/langchain/langchain/utilities/github.py @@ -4,7 +4,7 @@ from __future__ import annotations import json from typing import TYPE_CHECKING, Any, Dict, List, Optional -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utilities/golden_query.py b/libs/langchain/langchain/utilities/golden_query.py index df7e505faa..5a68430050 100644 --- a/libs/langchain/langchain/utilities/golden_query.py +++ b/libs/langchain/langchain/utilities/golden_query.py @@ -3,7 +3,7 @@ import json from typing import Dict, Optional import requests -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utilities/google_places_api.py b/libs/langchain/langchain/utilities/google_places_api.py index 8b8ea7a93a..9b8e4f9fa8 100644 --- a/libs/langchain/langchain/utilities/google_places_api.py +++ b/libs/langchain/langchain/utilities/google_places_api.py @@ -4,7 +4,7 @@ import logging from typing import Any, Dict, Optional -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utilities/google_search.py b/libs/langchain/langchain/utilities/google_search.py index 2c118dd165..bdbf71e495 100644 --- a/libs/langchain/langchain/utilities/google_search.py +++ b/libs/langchain/langchain/utilities/google_search.py @@ -1,7 +1,7 @@ """Util that calls Google Search.""" from typing import Any, Dict, List, Optional -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utilities/google_serper.py b/libs/langchain/langchain/utilities/google_serper.py index 9db376c479..6c1f31fa78 100644 --- a/libs/langchain/langchain/utilities/google_serper.py +++ b/libs/langchain/langchain/utilities/google_serper.py @@ -3,8 +3,8 @@ from typing import Any, Dict, List, Optional import aiohttp import requests -from pydantic.class_validators import root_validator -from pydantic.main import BaseModel +from pydantic_v1.class_validators import root_validator +from pydantic_v1.main import BaseModel from typing_extensions import Literal from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utilities/graphql.py b/libs/langchain/langchain/utilities/graphql.py index 1e8a7b2039..6b2dd309b3 100644 --- a/libs/langchain/langchain/utilities/graphql.py +++ b/libs/langchain/langchain/utilities/graphql.py @@ -1,7 +1,7 @@ import json from typing import Any, Callable, Dict, Optional -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator class GraphQLAPIWrapper(BaseModel): diff --git a/libs/langchain/langchain/utilities/jira.py b/libs/langchain/langchain/utilities/jira.py index d59a76b472..d246a12dc6 100644 --- a/libs/langchain/langchain/utilities/jira.py +++ b/libs/langchain/langchain/utilities/jira.py @@ -1,7 +1,7 @@ """Util that calls Jira.""" from typing import Any, Dict, List, Optional -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utilities/metaphor_search.py b/libs/langchain/langchain/utilities/metaphor_search.py index 2b5e2dbd3b..b05844bb0e 100644 --- a/libs/langchain/langchain/utilities/metaphor_search.py +++ b/libs/langchain/langchain/utilities/metaphor_search.py @@ -7,7 +7,7 @@ from typing import Dict, List, Optional import aiohttp import requests -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utilities/openapi.py b/libs/langchain/langchain/utilities/openapi.py index 06d0f66632..5a1f8d4a8c 100644 --- a/libs/langchain/langchain/utilities/openapi.py +++ b/libs/langchain/langchain/utilities/openapi.py @@ -20,7 +20,7 @@ from openapi_schema_pydantic import ( RequestBody, Schema, ) -from pydantic import ValidationError +from pydantic_v1 import ValidationError logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/utilities/openweathermap.py b/libs/langchain/langchain/utilities/openweathermap.py index 7b157625e0..b6703427e8 100644 --- a/libs/langchain/langchain/utilities/openweathermap.py +++ b/libs/langchain/langchain/utilities/openweathermap.py @@ -1,7 +1,7 @@ """Util that calls OpenWeatherMap using PyOWM.""" from typing import Any, Dict, Optional -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utilities/powerbi.py b/libs/langchain/langchain/utilities/powerbi.py index 5c00d017b1..67b532ef93 100644 --- a/libs/langchain/langchain/utilities/powerbi.py +++ b/libs/langchain/langchain/utilities/powerbi.py @@ -9,7 +9,7 @@ from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Union import aiohttp import requests from aiohttp import ServerTimeoutError -from pydantic import BaseModel, Field, root_validator, validator +from pydantic_v1 import BaseModel, Field, root_validator, validator from requests.exceptions import Timeout _LOGGER = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/utilities/pubmed.py b/libs/langchain/langchain/utilities/pubmed.py index 261358a6b3..4c099e4b2e 100644 --- a/libs/langchain/langchain/utilities/pubmed.py +++ b/libs/langchain/langchain/utilities/pubmed.py @@ -5,8 +5,8 @@ import urllib.error import urllib.request from typing import Any, Dict, Iterator, List -from pydantic import BaseModel -from pydantic.class_validators import root_validator +from pydantic_v1 import BaseModel +from pydantic_v1.class_validators import root_validator from langchain.schema import Document diff --git a/libs/langchain/langchain/utilities/python.py b/libs/langchain/langchain/utilities/python.py index 348fd274b6..441233da7f 100644 --- a/libs/langchain/langchain/utilities/python.py +++ b/libs/langchain/langchain/utilities/python.py @@ -5,7 +5,7 @@ import sys from io import StringIO from typing import Dict, Optional -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/utilities/requests.py b/libs/langchain/langchain/utilities/requests.py index 2891701c49..ac46cf307d 100644 --- a/libs/langchain/langchain/utilities/requests.py +++ b/libs/langchain/langchain/utilities/requests.py @@ -4,7 +4,7 @@ from typing import Any, AsyncGenerator, Dict, Optional import aiohttp import requests -from pydantic import BaseModel, Extra +from pydantic_v1 import BaseModel, Extra class Requests(BaseModel): diff --git a/libs/langchain/langchain/utilities/scenexplain.py b/libs/langchain/langchain/utilities/scenexplain.py index 1150a34dc3..0b769b95aa 100644 --- a/libs/langchain/langchain/utilities/scenexplain.py +++ b/libs/langchain/langchain/utilities/scenexplain.py @@ -8,7 +8,7 @@ You can obtain a key by following the steps below. from typing import Dict import requests -from pydantic import BaseModel, BaseSettings, Field, root_validator +from pydantic_v1 import BaseModel, BaseSettings, Field, root_validator from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utilities/searx_search.py b/libs/langchain/langchain/utilities/searx_search.py index e73e81c380..3a025e6207 100644 --- a/libs/langchain/langchain/utilities/searx_search.py +++ b/libs/langchain/langchain/utilities/searx_search.py @@ -132,7 +132,7 @@ from typing import Any, Dict, List, Optional import aiohttp import requests -from pydantic import BaseModel, Extra, Field, PrivateAttr, root_validator, validator +from pydantic_v1 import BaseModel, Extra, Field, PrivateAttr, root_validator, validator from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utilities/serpapi.py b/libs/langchain/langchain/utilities/serpapi.py index 98f4214ce0..05a410381a 100644 --- a/libs/langchain/langchain/utilities/serpapi.py +++ b/libs/langchain/langchain/utilities/serpapi.py @@ -7,7 +7,7 @@ import sys from typing import Any, Dict, Optional, Tuple import aiohttp -from pydantic import BaseModel, Extra, Field, root_validator +from pydantic_v1 import BaseModel, Extra, Field, root_validator from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utilities/tensorflow_datasets.py b/libs/langchain/langchain/utilities/tensorflow_datasets.py index 1a7073d2f7..fb17112a7a 100644 --- a/libs/langchain/langchain/utilities/tensorflow_datasets.py +++ b/libs/langchain/langchain/utilities/tensorflow_datasets.py @@ -1,7 +1,7 @@ import logging from typing import Any, Callable, Dict, Iterator, List, Optional -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.schema import Document diff --git a/libs/langchain/langchain/utilities/twilio.py b/libs/langchain/langchain/utilities/twilio.py index 45e009bb2b..a0081f5b27 100644 --- a/libs/langchain/langchain/utilities/twilio.py +++ b/libs/langchain/langchain/utilities/twilio.py @@ -1,7 +1,7 @@ """Util that calls Twilio.""" from typing import Any, Dict, Optional -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utilities/wikipedia.py b/libs/langchain/langchain/utilities/wikipedia.py index 1202f8b24e..4476603eba 100644 --- a/libs/langchain/langchain/utilities/wikipedia.py +++ b/libs/langchain/langchain/utilities/wikipedia.py @@ -2,7 +2,7 @@ import logging from typing import Any, Dict, List, Optional -from pydantic import BaseModel, root_validator +from pydantic_v1 import BaseModel, root_validator from langchain.schema import Document diff --git a/libs/langchain/langchain/utilities/wolfram_alpha.py b/libs/langchain/langchain/utilities/wolfram_alpha.py index a27aec051f..aadadad3d3 100644 --- a/libs/langchain/langchain/utilities/wolfram_alpha.py +++ b/libs/langchain/langchain/utilities/wolfram_alpha.py @@ -1,7 +1,7 @@ """Util that calls WolframAlpha.""" from typing import Any, Dict, Optional -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utilities/zapier.py b/libs/langchain/langchain/utilities/zapier.py index 5884f5e4e3..613647d1eb 100644 --- a/libs/langchain/langchain/utilities/zapier.py +++ b/libs/langchain/langchain/utilities/zapier.py @@ -16,7 +16,7 @@ from typing import Any, Dict, List, Optional import aiohttp import requests -from pydantic import BaseModel, Extra, root_validator +from pydantic_v1 import BaseModel, Extra, root_validator from requests import Request, Session from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/utils/pydantic.py b/libs/langchain/langchain/utils/pydantic.py new file mode 100644 index 0000000000..80ddb81fcb --- /dev/null +++ b/libs/langchain/langchain/utils/pydantic.py @@ -0,0 +1,14 @@ +"""Utilities for tests.""" + + +def get_pydantic_major_version() -> int: + """Get the major version of Pydantic.""" + try: + import pydantic + + return int(pydantic.__version__.split(".")[0]) + except ImportError: + return 0 + + +PYDANTIC_MAJOR_VERSION = get_pydantic_major_version() diff --git a/libs/langchain/langchain/vectorstores/azuresearch.py b/libs/langchain/langchain/vectorstores/azuresearch.py index b20274b868..f15ef3aa2a 100644 --- a/libs/langchain/langchain/vectorstores/azuresearch.py +++ b/libs/langchain/langchain/vectorstores/azuresearch.py @@ -18,7 +18,7 @@ from typing import ( ) import numpy as np -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForRetrieverRun, diff --git a/libs/langchain/langchain/vectorstores/base.py b/libs/langchain/langchain/vectorstores/base.py index 8f27ce20b5..8544c98936 100644 --- a/libs/langchain/langchain/vectorstores/base.py +++ b/libs/langchain/langchain/vectorstores/base.py @@ -22,7 +22,7 @@ from typing import ( TypeVar, ) -from pydantic import Field, root_validator +from pydantic_v1 import Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForRetrieverRun, diff --git a/libs/langchain/langchain/vectorstores/clickhouse.py b/libs/langchain/langchain/vectorstores/clickhouse.py index 2544d45fd7..9e0955e136 100644 --- a/libs/langchain/langchain/vectorstores/clickhouse.py +++ b/libs/langchain/langchain/vectorstores/clickhouse.py @@ -8,7 +8,7 @@ from hashlib import sha1 from threading import Thread from typing import Any, Dict, Iterable, List, Optional, Tuple, Union -from pydantic import BaseSettings +from pydantic_v1 import BaseSettings from langchain.docstore.document import Document from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/vectorstores/docarray/base.py b/libs/langchain/langchain/vectorstores/docarray/base.py index fe58f49fcb..d82a7feac6 100644 --- a/libs/langchain/langchain/vectorstores/docarray/base.py +++ b/libs/langchain/langchain/vectorstores/docarray/base.py @@ -2,7 +2,7 @@ from abc import ABC from typing import TYPE_CHECKING, Any, Iterable, List, Optional, Tuple, Type import numpy as np -from pydantic import Field +from pydantic_v1 import Field from langchain.embeddings.base import Embeddings from langchain.schema import Document diff --git a/libs/langchain/langchain/vectorstores/myscale.py b/libs/langchain/langchain/vectorstores/myscale.py index 28e0824e13..c056c5e09d 100644 --- a/libs/langchain/langchain/vectorstores/myscale.py +++ b/libs/langchain/langchain/vectorstores/myscale.py @@ -7,7 +7,7 @@ from hashlib import sha1 from threading import Thread from typing import Any, Dict, Iterable, List, Optional, Tuple -from pydantic import BaseSettings +from pydantic_v1 import BaseSettings from langchain.docstore.document import Document from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/vectorstores/redis.py b/libs/langchain/langchain/vectorstores/redis.py index f6ed5c4011..2105b1c09f 100644 --- a/libs/langchain/langchain/vectorstores/redis.py +++ b/libs/langchain/langchain/vectorstores/redis.py @@ -20,7 +20,7 @@ from typing import ( ) import numpy as np -from pydantic import root_validator +from pydantic_v1 import root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForRetrieverRun, diff --git a/libs/langchain/langchain/vectorstores/starrocks.py b/libs/langchain/langchain/vectorstores/starrocks.py index 0076a4cf06..639b41ea4d 100644 --- a/libs/langchain/langchain/vectorstores/starrocks.py +++ b/libs/langchain/langchain/vectorstores/starrocks.py @@ -8,7 +8,7 @@ from hashlib import sha1 from threading import Thread from typing import Any, Dict, Iterable, List, Optional, Tuple -from pydantic import BaseSettings +from pydantic_v1 import BaseSettings from langchain.docstore.document import Document from langchain.embeddings.base import Embeddings diff --git a/libs/langchain/langchain/vectorstores/vectara.py b/libs/langchain/langchain/vectorstores/vectara.py index 16a6e8c500..681831b2bd 100644 --- a/libs/langchain/langchain/vectorstores/vectara.py +++ b/libs/langchain/langchain/vectorstores/vectara.py @@ -8,7 +8,7 @@ from hashlib import md5 from typing import Any, Iterable, List, Optional, Tuple, Type import requests -from pydantic import Field +from pydantic_v1 import Field from langchain.embeddings.base import Embeddings from langchain.schema import Document diff --git a/libs/langchain/tests/integration_tests/document_loaders/test_tensorflow_datasets.py b/libs/langchain/tests/integration_tests/document_loaders/test_tensorflow_datasets.py index e930d10fe3..e698499118 100644 --- a/libs/langchain/tests/integration_tests/document_loaders/test_tensorflow_datasets.py +++ b/libs/langchain/tests/integration_tests/document_loaders/test_tensorflow_datasets.py @@ -4,7 +4,7 @@ from __future__ import annotations from typing import TYPE_CHECKING import pytest -from pydantic.error_wrappers import ValidationError +from pydantic_v1.error_wrappers import ValidationError from langchain.document_loaders.tensorflow_datasets import TensorflowDatasetLoader from langchain.schema.document import Document diff --git a/libs/langchain/tests/integration_tests/retrievers/docarray/fixtures.py b/libs/langchain/tests/integration_tests/retrievers/docarray/fixtures.py index 520f3e54e5..22fec47a06 100644 --- a/libs/langchain/tests/integration_tests/retrievers/docarray/fixtures.py +++ b/libs/langchain/tests/integration_tests/retrievers/docarray/fixtures.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Any, Dict, Generator, Tuple import numpy as np import pytest -from pydantic import Field +from pydantic_v1 import Field if TYPE_CHECKING: from docarray.index import ( diff --git a/libs/langchain/tests/integration_tests/utilities/test_tensorflow_datasets.py b/libs/langchain/tests/integration_tests/utilities/test_tensorflow_datasets.py index 3066aa61e4..48eca0c74d 100644 --- a/libs/langchain/tests/integration_tests/utilities/test_tensorflow_datasets.py +++ b/libs/langchain/tests/integration_tests/utilities/test_tensorflow_datasets.py @@ -4,7 +4,7 @@ from __future__ import annotations from typing import TYPE_CHECKING import pytest -from pydantic.error_wrappers import ValidationError +from pydantic_v1.error_wrappers import ValidationError from langchain.schema.document import Document from langchain.utilities.tensorflow_datasets import TensorflowDatasets diff --git a/libs/langchain/tests/mock_servers/robot/server.py b/libs/langchain/tests/mock_servers/robot/server.py index 5af50d3f75..8e28ae583c 100644 --- a/libs/langchain/tests/mock_servers/robot/server.py +++ b/libs/langchain/tests/mock_servers/robot/server.py @@ -7,7 +7,7 @@ import uvicorn from fastapi import FastAPI, HTTPException, Query from fastapi.middleware.cors import CORSMiddleware from fastapi.openapi.utils import get_openapi -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field PORT = 7289 diff --git a/libs/langchain/tests/unit_tests/_api/test_deprecation.py b/libs/langchain/tests/unit_tests/_api/test_deprecation.py index 69605e2ea8..430eaaecd4 100644 --- a/libs/langchain/tests/unit_tests/_api/test_deprecation.py +++ b/libs/langchain/tests/unit_tests/_api/test_deprecation.py @@ -2,7 +2,7 @@ import warnings from typing import Any, Dict import pytest -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain._api.deprecation import _warn_deprecated, deprecated diff --git a/libs/langchain/tests/unit_tests/callbacks/fake_callback_handler.py b/libs/langchain/tests/unit_tests/callbacks/fake_callback_handler.py index f4819c6930..e7720fa06f 100644 --- a/libs/langchain/tests/unit_tests/callbacks/fake_callback_handler.py +++ b/libs/langchain/tests/unit_tests/callbacks/fake_callback_handler.py @@ -3,7 +3,7 @@ from itertools import chain from typing import Any, Dict, List, Optional, Union from uuid import UUID -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.callbacks.base import AsyncCallbackHandler, BaseCallbackHandler from langchain.schema.messages import BaseMessage diff --git a/libs/langchain/tests/unit_tests/evaluation/agents/test_eval_chain.py b/libs/langchain/tests/unit_tests/evaluation/agents/test_eval_chain.py index 5acb93baa5..b18c94875e 100644 --- a/libs/langchain/tests/unit_tests/evaluation/agents/test_eval_chain.py +++ b/libs/langchain/tests/unit_tests/evaluation/agents/test_eval_chain.py @@ -3,7 +3,7 @@ from typing import Any, Dict, List, Optional, Tuple import pytest -from pydantic import Field +from pydantic_v1 import Field from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.evaluation.agents.trajectory_eval_chain import ( diff --git a/libs/langchain/tests/unit_tests/llms/fake_llm.py b/libs/langchain/tests/unit_tests/llms/fake_llm.py index e7fc0d6dec..f04d428515 100644 --- a/libs/langchain/tests/unit_tests/llms/fake_llm.py +++ b/libs/langchain/tests/unit_tests/llms/fake_llm.py @@ -1,7 +1,7 @@ """Fake LLM wrapper for testing purposes.""" from typing import Any, Dict, List, Mapping, Optional, cast -from pydantic import validator +from pydantic_v1 import validator from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM diff --git a/libs/langchain/tests/unit_tests/output_parsers/test_pydantic_parser.py b/libs/langchain/tests/unit_tests/output_parsers/test_pydantic_parser.py index 8c12049960..070b9102df 100644 --- a/libs/langchain/tests/unit_tests/output_parsers/test_pydantic_parser.py +++ b/libs/langchain/tests/unit_tests/output_parsers/test_pydantic_parser.py @@ -2,7 +2,7 @@ from enum import Enum from typing import Optional -from pydantic import BaseModel, Field +from pydantic_v1 import BaseModel, Field from langchain.output_parsers.pydantic import PydanticOutputParser from langchain.schema import OutputParserException diff --git a/libs/langchain/tests/unit_tests/schema/test_runnable.py b/libs/langchain/tests/unit_tests/schema/test_runnable.py index aa0b7f4c1e..0177e6578c 100644 --- a/libs/langchain/tests/unit_tests/schema/test_runnable.py +++ b/libs/langchain/tests/unit_tests/schema/test_runnable.py @@ -1,3 +1,4 @@ +import warnings from typing import Any, Dict, List, Optional from uuid import UUID @@ -34,6 +35,7 @@ from langchain.schema.runnable import ( RunnableSequence, RunnableWithFallbacks, ) +from langchain.utils.pydantic import PYDANTIC_MAJOR_VERSION class FakeTracer(BaseTracer): @@ -250,7 +252,15 @@ async def test_prompt_with_chat_model( HumanMessage(content="What is your name?"), ] ) - assert tracer.runs == snapshot + + if PYDANTIC_MAJOR_VERSION == 1: + assert tracer.runs == snapshot + else: + warnings.warn( + f"testing snapshot for pydantic version {PYDANTIC_MAJOR_VERSION} is " + f"not supported yet" + ) + mocker.stop(prompt_spy) mocker.stop(chat_spy) @@ -351,7 +361,13 @@ async def test_prompt_with_llm( HumanMessage(content="What is your name?"), ] ) - assert tracer.runs == snapshot + if PYDANTIC_MAJOR_VERSION == 1: + assert tracer.runs == snapshot + else: + warnings.warn( + f"testing snapshot for pydantic version {PYDANTIC_MAJOR_VERSION} is " + f"not supported yet" + ) mocker.stop(prompt_spy) mocker.stop(llm_spy) @@ -384,7 +400,13 @@ async def test_prompt_with_llm( ] ), ] - assert tracer.runs == snapshot + if PYDANTIC_MAJOR_VERSION == 1: + assert tracer.runs == snapshot + else: + warnings.warn( + f"testing snapshot for pydantic version {PYDANTIC_MAJOR_VERSION} is " + f"not supported yet" + ) mocker.stop(prompt_spy) mocker.stop(llm_spy) @@ -442,7 +464,14 @@ def test_prompt_with_chat_model_and_parser( ] ) assert parser_spy.call_args.args[1] == AIMessage(content="foo, bar") - assert tracer.runs == snapshot + + if PYDANTIC_MAJOR_VERSION == 1: + assert tracer.runs == snapshot + else: + warnings.warn( + f"testing snapshot for pydantic version {PYDANTIC_MAJOR_VERSION} is " + f"not supported yet" + ) @freeze_time("2023-01-01") @@ -500,7 +529,13 @@ def test_combining_sequences( assert combined_chain.invoke( {"question": "What is your name?"}, dict(callbacks=[tracer]) ) == ["baz", "qux"] - assert tracer.runs == snapshot + if PYDANTIC_MAJOR_VERSION == 1: + assert tracer.runs == snapshot + else: + warnings.warn( + f"testing snapshot for pydantic version {PYDANTIC_MAJOR_VERSION} is " + f"not supported yet" + ) @freeze_time("2023-01-01") diff --git a/libs/langchain/tests/unit_tests/test_schema.py b/libs/langchain/tests/unit_tests/test_schema.py index facbf93507..3fa2be84e1 100644 --- a/libs/langchain/tests/unit_tests/test_schema.py +++ b/libs/langchain/tests/unit_tests/test_schema.py @@ -13,9 +13,10 @@ from langchain.schema.messages import ( class TestGetBufferString(unittest.TestCase): - human_msg: HumanMessage = HumanMessage(content="human") - ai_msg: AIMessage = AIMessage(content="ai") - sys_msg: SystemMessage = SystemMessage(content="sys") + def setUp(self) -> None: + self.human_msg = HumanMessage(content="human") + self.ai_msg = AIMessage(content="ai") + self.sys_msg = SystemMessage(content="sys") def test_empty_input(self) -> None: self.assertEqual(get_buffer_string([]), "") @@ -58,20 +59,14 @@ class TestGetBufferString(unittest.TestCase): ) -class TestMessageDictConversion(unittest.TestCase): - human_msg: HumanMessage = HumanMessage( - content="human", additional_kwargs={"key": "value"} - ) - ai_msg: AIMessage = AIMessage(content="ai") - sys_msg: SystemMessage = SystemMessage(content="sys") +def test_multiple_msg() -> None: + human_msg = HumanMessage(content="human", additional_kwargs={"key": "value"}) + ai_msg = AIMessage(content="ai") + sys_msg = SystemMessage(content="sys") - def test_multiple_msg(self) -> None: - msgs = [ - self.human_msg, - self.ai_msg, - self.sys_msg, - ] - self.assertEqual( - messages_from_dict(messages_to_dict(msgs)), - msgs, - ) + msgs = [ + human_msg, + ai_msg, + sys_msg, + ] + assert messages_from_dict(messages_to_dict(msgs)) == msgs diff --git a/libs/langchain/tests/unit_tests/tools/test_base.py b/libs/langchain/tests/unit_tests/tools/test_base.py index c42ae202d0..2ffaff0cbe 100644 --- a/libs/langchain/tests/unit_tests/tools/test_base.py +++ b/libs/langchain/tests/unit_tests/tools/test_base.py @@ -6,7 +6,7 @@ from functools import partial from typing import Any, List, Optional, Type, Union import pytest -from pydantic import BaseModel +from pydantic_v1 import BaseModel from langchain.agents.tools import Tool, tool from langchain.callbacks.manager import (