langchain-core 1.2.0__tar.gz → 1.2.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {langchain_core-1.2.0 → langchain_core-1.2.5}/PKG-INFO +1 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/_api/deprecation.py +110 -81
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/example_selectors/length_based.py +1 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/language_models/chat_models.py +5 -5
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/load/__init__.py +10 -2
- langchain_core-1.2.5/langchain_core/load/_validation.py +176 -0
- langchain_core-1.2.5/langchain_core/load/dump.py +120 -0
- langchain_core-1.2.5/langchain_core/load/load.py +657 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/load/mapping.py +12 -19
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/ai.py +3 -3
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/block_translators/anthropic.py +38 -20
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/block_translators/bedrock.py +16 -2
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/block_translators/bedrock_converse.py +34 -12
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/block_translators/google_genai.py +20 -3
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/block_translators/groq.py +16 -2
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/block_translators/openai.py +44 -15
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/utils.py +165 -49
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/output_parsers/openai_functions.py +2 -2
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/output_parsers/openai_tools.py +9 -7
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/output_parsers/pydantic.py +1 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/prompts/structured.py +3 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/runnables/base.py +10 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/runnables/graph_ascii.py +3 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/runnables/graph_mermaid.py +1 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/runnables/graph_png.py +2 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/runnables/history.py +4 -4
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/runnables/passthrough.py +10 -16
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tools/base.py +35 -4
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tracers/core.py +10 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tracers/evaluation.py +1 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tracers/event_stream.py +5 -5
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tracers/langchain.py +54 -4
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tracers/log_stream.py +2 -2
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/_merge.py +1 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/aiter.py +1 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/function_calling.py +11 -2
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/input.py +3 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/mustache.py +2 -2
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/uuid.py +3 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/vectorstores/in_memory.py +1 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/version.py +1 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/pyproject.toml +1 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/_api/test_deprecation.py +85 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/language_models/chat_models/test_base.py +2 -2
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/load/test_imports.py +8 -1
- langchain_core-1.2.5/tests/unit_tests/load/test_secret_injection.py +431 -0
- langchain_core-1.2.5/tests/unit_tests/load/test_serializable.py +893 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/messages/block_translators/test_openai.py +15 -14
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/messages/test_ai.py +2 -2
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/messages/test_utils.py +183 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/output_parsers/test_openai_tools.py +74 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/output_parsers/test_pydantic_parser.py +4 -4
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/test_chat.py +1 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/test_dict.py +1 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/test_image.py +2 -2
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/test_structured.py +0 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/runnables/test_runnable.py +7 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/runnables/test_runnable_events_v1.py +2 -2
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/runnables/test_runnable_events_v2.py +2 -2
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/test_messages.py +22 -6
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/test_tools.py +162 -4
- langchain_core-1.2.5/tests/unit_tests/tracers/test_automatic_metadata.py +155 -0
- langchain_core-1.2.5/tests/unit_tests/tracers/test_langchain.py +568 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/vectorstores/test_in_memory.py +1 -1
- {langchain_core-1.2.0 → langchain_core-1.2.5}/uv.lock +4 -4
- langchain_core-1.2.0/langchain_core/load/dump.py +0 -82
- langchain_core-1.2.0/langchain_core/load/load.py +0 -289
- langchain_core-1.2.0/tests/unit_tests/load/test_serializable.py +0 -367
- langchain_core-1.2.0/tests/unit_tests/tracers/test_langchain.py +0 -147
- {langchain_core-1.2.0 → langchain_core-1.2.5}/.gitignore +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/Makefile +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/README.md +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/extended_testing_deps.txt +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/_api/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/_api/beta_decorator.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/_api/internal.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/_api/path.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/_import_utils.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/agents.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/caches.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/callbacks/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/callbacks/base.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/callbacks/file.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/callbacks/manager.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/callbacks/stdout.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/callbacks/streaming_stdout.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/callbacks/usage.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/chat_history.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/chat_loaders.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/chat_sessions.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/document_loaders/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/document_loaders/base.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/document_loaders/blob_loaders.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/document_loaders/langsmith.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/documents/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/documents/base.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/documents/compressor.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/documents/transformers.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/embeddings/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/embeddings/embeddings.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/embeddings/fake.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/env.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/example_selectors/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/example_selectors/base.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/example_selectors/semantic_similarity.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/exceptions.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/globals.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/indexing/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/indexing/api.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/indexing/base.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/indexing/in_memory.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/language_models/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/language_models/_utils.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/language_models/base.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/language_models/fake.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/language_models/fake_chat_models.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/language_models/llms.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/language_models/model_profile.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/load/serializable.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/base.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/block_translators/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/block_translators/google_vertexai.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/block_translators/langchain_v0.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/chat.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/content.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/function.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/human.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/modifier.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/system.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/messages/tool.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/output_parsers/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/output_parsers/base.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/output_parsers/format_instructions.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/output_parsers/json.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/output_parsers/list.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/output_parsers/string.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/output_parsers/transform.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/output_parsers/xml.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/outputs/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/outputs/chat_generation.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/outputs/chat_result.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/outputs/generation.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/outputs/llm_result.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/outputs/run_info.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/prompt_values.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/prompts/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/prompts/base.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/prompts/chat.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/prompts/dict.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/prompts/few_shot.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/prompts/few_shot_with_templates.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/prompts/image.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/prompts/loading.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/prompts/message.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/prompts/prompt.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/prompts/string.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/py.typed +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/rate_limiters.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/retrievers.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/runnables/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/runnables/branch.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/runnables/config.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/runnables/configurable.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/runnables/fallbacks.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/runnables/graph.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/runnables/retry.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/runnables/router.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/runnables/schema.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/runnables/utils.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/stores.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/structured_query.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/sys_info.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tools/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tools/convert.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tools/render.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tools/retriever.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tools/simple.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tools/structured.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tracers/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tracers/_streaming.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tracers/base.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tracers/context.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tracers/memory_stream.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tracers/root_listeners.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tracers/run_collector.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tracers/schemas.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/tracers/stdout.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/env.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/formatting.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/html.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/image.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/interactive_env.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/iter.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/json.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/json_schema.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/pydantic.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/strings.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/usage.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/utils/utils.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/vectorstores/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/vectorstores/base.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/langchain_core/vectorstores/utils.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/scripts/check_imports.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/scripts/lint_imports.sh +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/benchmarks/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/benchmarks/test_async_callbacks.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/benchmarks/test_imports.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/integration_tests/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/integration_tests/test_compile.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/_api/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/_api/test_beta_decorator.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/_api/test_imports.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/_api/test_path.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/caches/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/caches/test_in_memory_cache.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/callbacks/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/callbacks/test_async_callback_manager.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/callbacks/test_dispatch_custom_event.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/callbacks/test_imports.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/callbacks/test_sync_callback_manager.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/callbacks/test_usage_callback.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/chat_history/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/chat_history/test_chat_history.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/conftest.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/data/prompt_file.txt +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/data/prompts/prompt_extra_args.json +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/data/prompts/prompt_missing_args.json +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/data/prompts/simple_prompt.json +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/dependencies/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/dependencies/test_dependencies.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/document_loaders/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/document_loaders/test_base.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/document_loaders/test_langsmith.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/documents/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/documents/test_document.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/documents/test_imports.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/documents/test_str.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/embeddings/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/embeddings/test_deterministic_embedding.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/example_selectors/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/example_selectors/test_base.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/example_selectors/test_imports.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/example_selectors/test_length_based_example_selector.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/example_selectors/test_similarity.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/example-non-utf8.csv +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/example-non-utf8.txt +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/example-utf8.csv +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/example-utf8.txt +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/example_prompt.json +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/examples.json +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/examples.yaml +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/few_shot_prompt.json +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/few_shot_prompt.yaml +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/few_shot_prompt_example_prompt.json +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/few_shot_prompt_examples_in.json +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/few_shot_prompt_yaml_examples.yaml +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/jinja_injection_prompt.json +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/jinja_injection_prompt.yaml +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/prompt_with_output_parser.json +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/simple_prompt.json +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/simple_prompt.yaml +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/simple_prompt_with_template_file.json +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/examples/simple_template.txt +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/fake/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/fake/callbacks.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/fake/test_fake_chat_model.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/indexing/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/indexing/test_hashed_document.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/indexing/test_in_memory_indexer.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/indexing/test_in_memory_record_manager.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/indexing/test_indexing.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/indexing/test_public_api.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/language_models/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/language_models/chat_models/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/language_models/chat_models/test_benchmark.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/language_models/chat_models/test_cache.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/language_models/chat_models/test_rate_limiting.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/language_models/llms/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/language_models/llms/test_base.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/language_models/llms/test_cache.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/language_models/test_imports.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/load/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/messages/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/messages/block_translators/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/messages/block_translators/test_anthropic.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/messages/block_translators/test_bedrock.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/messages/block_translators/test_bedrock_converse.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/messages/block_translators/test_google_genai.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/messages/block_translators/test_groq.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/messages/block_translators/test_langchain_v0.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/messages/block_translators/test_registration.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/messages/test_imports.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/output_parsers/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/output_parsers/test_base_parsers.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/output_parsers/test_imports.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/output_parsers/test_json.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/output_parsers/test_list_parser.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/output_parsers/test_openai_functions.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/output_parsers/test_xml_parser.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/outputs/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/outputs/test_chat_generation.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/outputs/test_imports.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompt_file.txt +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/__snapshots__/test_chat.ambr +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/__snapshots__/test_prompt.ambr +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/prompt_extra_args.json +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/prompt_missing_args.json +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/simple_prompt.json +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/test_few_shot.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/test_few_shot_with_templates.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/test_imports.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/test_loading.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/test_prompt.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/test_string.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/prompts/test_utils.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/pydantic_utils.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/rate_limiters/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/rate_limiters/test_in_memory_rate_limiter.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/runnables/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/runnables/__snapshots__/test_fallbacks.ambr +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/runnables/__snapshots__/test_graph.ambr +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/runnables/__snapshots__/test_runnable.ambr +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/runnables/test_concurrency.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/runnables/test_config.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/runnables/test_configurable.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/runnables/test_fallbacks.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/runnables/test_graph.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/runnables/test_history.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/runnables/test_imports.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/runnables/test_tracing_interops.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/runnables/test_utils.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/stores/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/stores/test_in_memory.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/stubs.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/test_globals.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/test_imports.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/test_outputs.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/test_prompt_values.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/test_pydantic_imports.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/test_pydantic_serde.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/test_retrievers.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/test_setup.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/test_sys_info.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/tracers/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/tracers/test_async_base_tracer.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/tracers/test_base_tracer.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/tracers/test_imports.py +2 -2
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/tracers/test_memory_stream.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/tracers/test_run_collector.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/tracers/test_schemas.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/utils/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/utils/test_aiter.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/utils/test_env.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/utils/test_function_calling.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/utils/test_html.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/utils/test_imports.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/utils/test_iter.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/utils/test_json_schema.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/utils/test_pydantic.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/utils/test_rm_titles.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/utils/test_strings.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/utils/test_usage.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/utils/test_utils.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/utils/test_uuid_utils.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/vectorstores/__init__.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/vectorstores/test_utils.py +0 -0
- {langchain_core-1.2.0 → langchain_core-1.2.5}/tests/unit_tests/vectorstores/test_vectorstore.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: langchain-core
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.5
|
|
4
4
|
Summary: Building applications with LLMs through composability
|
|
5
5
|
Project-URL: Homepage, https://docs.langchain.com/
|
|
6
6
|
Project-URL: Documentation, https://reference.langchain.com/python/langchain_core/
|
|
@@ -28,6 +28,27 @@ from pydantic.v1.fields import FieldInfo as FieldInfoV1
|
|
|
28
28
|
from langchain_core._api.internal import is_caller_internal
|
|
29
29
|
|
|
30
30
|
|
|
31
|
+
def _build_deprecation_message(
|
|
32
|
+
*,
|
|
33
|
+
alternative: str = "",
|
|
34
|
+
alternative_import: str = "",
|
|
35
|
+
) -> str:
|
|
36
|
+
"""Build a simple deprecation message for `__deprecated__` attribute.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
alternative: An alternative API name.
|
|
40
|
+
alternative_import: A fully qualified import path for the alternative.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
A deprecation message string for IDE/type checker display.
|
|
44
|
+
"""
|
|
45
|
+
if alternative_import:
|
|
46
|
+
return f"Use {alternative_import} instead."
|
|
47
|
+
if alternative:
|
|
48
|
+
return f"Use {alternative} instead."
|
|
49
|
+
return "Deprecated."
|
|
50
|
+
|
|
51
|
+
|
|
31
52
|
class LangChainDeprecationWarning(DeprecationWarning):
|
|
32
53
|
"""A class for issuing deprecation warnings for LangChain users."""
|
|
33
54
|
|
|
@@ -81,60 +102,57 @@ def deprecated(
|
|
|
81
102
|
) -> Callable[[T], T]:
|
|
82
103
|
"""Decorator to mark a function, a class, or a property as deprecated.
|
|
83
104
|
|
|
84
|
-
When deprecating a classmethod, a staticmethod, or a property, the
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
underlying callable), but *over* `@property`.
|
|
105
|
+
When deprecating a classmethod, a staticmethod, or a property, the `@deprecated`
|
|
106
|
+
decorator should go *under* `@classmethod` and `@staticmethod` (i.e., `deprecated`
|
|
107
|
+
should directly decorate the underlying callable), but *over* `@property`.
|
|
88
108
|
|
|
89
|
-
When deprecating a class `C` intended to be used as a base class in a
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
own (deprecation-emitting) `C.__init__`).
|
|
109
|
+
When deprecating a class `C` intended to be used as a base class in a multiple
|
|
110
|
+
inheritance hierarchy, `C` *must* define an `__init__` method (if `C` instead
|
|
111
|
+
inherited its `__init__` from its own base class, then `@deprecated` would mess up
|
|
112
|
+
`__init__` inheritance when installing its own (deprecation-emitting) `C.__init__`).
|
|
94
113
|
|
|
95
|
-
Parameters are the same as for `warn_deprecated`, except that *obj_type*
|
|
96
|
-
|
|
97
|
-
|
|
114
|
+
Parameters are the same as for `warn_deprecated`, except that *obj_type* defaults to
|
|
115
|
+
'class' if decorating a class, 'attribute' if decorating a property, and 'function'
|
|
116
|
+
otherwise.
|
|
98
117
|
|
|
99
118
|
Args:
|
|
100
|
-
since:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
and %(removal)s format specifiers will be replaced by the
|
|
119
|
+
since: The release at which this API became deprecated.
|
|
120
|
+
message: Override the default deprecation message.
|
|
121
|
+
|
|
122
|
+
The `%(since)s`, `%(name)s`, `%(alternative)s`, `%(obj_type)s`,
|
|
123
|
+
`%(addendum)s`, and `%(removal)s` format specifiers will be replaced by the
|
|
106
124
|
values of the respective arguments passed to this function.
|
|
107
|
-
name:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
alternative_import:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
obj_type:
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
package:
|
|
128
|
-
The package of the deprecated object.
|
|
125
|
+
name: The name of the deprecated object.
|
|
126
|
+
alternative: An alternative API that the user may use in place of the deprecated
|
|
127
|
+
API.
|
|
128
|
+
|
|
129
|
+
The deprecation warning will tell the user about this alternative if
|
|
130
|
+
provided.
|
|
131
|
+
alternative_import: An alternative import that the user may use instead.
|
|
132
|
+
pending: If `True`, uses a `PendingDeprecationWarning` instead of a
|
|
133
|
+
`DeprecationWarning`.
|
|
134
|
+
|
|
135
|
+
Cannot be used together with removal.
|
|
136
|
+
obj_type: The object type being deprecated.
|
|
137
|
+
addendum: Additional text appended directly to the final message.
|
|
138
|
+
removal: The expected removal version.
|
|
139
|
+
|
|
140
|
+
With the default (an empty string), a removal version is automatically
|
|
141
|
+
computed from since. Set to other Falsy values to not schedule a removal
|
|
142
|
+
date.
|
|
143
|
+
|
|
144
|
+
Cannot be used together with pending.
|
|
145
|
+
package: The package of the deprecated object.
|
|
129
146
|
|
|
130
147
|
Returns:
|
|
131
148
|
A decorator to mark a function or class as deprecated.
|
|
132
149
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
150
|
+
Example:
|
|
151
|
+
```python
|
|
152
|
+
@deprecated("1.4.0")
|
|
153
|
+
def the_function_to_deprecate():
|
|
154
|
+
pass
|
|
155
|
+
```
|
|
138
156
|
"""
|
|
139
157
|
_validate_deprecation_params(
|
|
140
158
|
removal, alternative, alternative_import, pending=pending
|
|
@@ -223,6 +241,11 @@ def deprecated(
|
|
|
223
241
|
obj.__init__ = functools.wraps(obj.__init__)( # type: ignore[misc]
|
|
224
242
|
warn_if_direct_instance
|
|
225
243
|
)
|
|
244
|
+
# Set __deprecated__ for PEP 702 (IDE/type checker support)
|
|
245
|
+
obj.__deprecated__ = _build_deprecation_message( # type: ignore[attr-defined]
|
|
246
|
+
alternative=alternative,
|
|
247
|
+
alternative_import=alternative_import,
|
|
248
|
+
)
|
|
226
249
|
return obj
|
|
227
250
|
|
|
228
251
|
elif isinstance(obj, FieldInfoV1):
|
|
@@ -315,12 +338,15 @@ def deprecated(
|
|
|
315
338
|
|
|
316
339
|
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T: # noqa: ARG001
|
|
317
340
|
"""Finalize the property."""
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
_DeprecatedProperty(
|
|
321
|
-
fget=obj.fget, fset=obj.fset, fdel=obj.fdel, doc=new_doc
|
|
322
|
-
),
|
|
341
|
+
prop = _DeprecatedProperty(
|
|
342
|
+
fget=obj.fget, fset=obj.fset, fdel=obj.fdel, doc=new_doc
|
|
323
343
|
)
|
|
344
|
+
# Set __deprecated__ for PEP 702 (IDE/type checker support)
|
|
345
|
+
prop.__deprecated__ = _build_deprecation_message( # type: ignore[attr-defined]
|
|
346
|
+
alternative=alternative,
|
|
347
|
+
alternative_import=alternative_import,
|
|
348
|
+
)
|
|
349
|
+
return cast("T", prop)
|
|
324
350
|
|
|
325
351
|
else:
|
|
326
352
|
_name = _name or cast("type | Callable", obj).__qualname__
|
|
@@ -343,6 +369,11 @@ def deprecated(
|
|
|
343
369
|
"""
|
|
344
370
|
wrapper = functools.wraps(wrapped)(wrapper)
|
|
345
371
|
wrapper.__doc__ = new_doc
|
|
372
|
+
# Set __deprecated__ for PEP 702 (IDE/type checker support)
|
|
373
|
+
wrapper.__deprecated__ = _build_deprecation_message( # type: ignore[attr-defined]
|
|
374
|
+
alternative=alternative,
|
|
375
|
+
alternative_import=alternative_import,
|
|
376
|
+
)
|
|
346
377
|
return cast("T", wrapper)
|
|
347
378
|
|
|
348
379
|
old_doc = inspect.cleandoc(old_doc or "").strip("\n")
|
|
@@ -398,7 +429,7 @@ def deprecated(
|
|
|
398
429
|
|
|
399
430
|
@contextlib.contextmanager
|
|
400
431
|
def suppress_langchain_deprecation_warning() -> Generator[None, None, None]:
|
|
401
|
-
"""Context manager to suppress LangChainDeprecationWarning
|
|
432
|
+
"""Context manager to suppress `LangChainDeprecationWarning`."""
|
|
402
433
|
with warnings.catch_warnings():
|
|
403
434
|
warnings.simplefilter("ignore", LangChainDeprecationWarning)
|
|
404
435
|
warnings.simplefilter("ignore", LangChainPendingDeprecationWarning)
|
|
@@ -421,35 +452,33 @@ def warn_deprecated(
|
|
|
421
452
|
"""Display a standardized deprecation.
|
|
422
453
|
|
|
423
454
|
Args:
|
|
424
|
-
since:
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
and %(removal)s format specifiers will be replaced by the
|
|
455
|
+
since: The release at which this API became deprecated.
|
|
456
|
+
message: Override the default deprecation message.
|
|
457
|
+
|
|
458
|
+
The `%(since)s`, `%(name)s`, `%(alternative)s`, `%(obj_type)s`,
|
|
459
|
+
`%(addendum)s`, and `%(removal)s` format specifiers will be replaced by the
|
|
430
460
|
values of the respective arguments passed to this function.
|
|
431
|
-
name:
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
alternative_import:
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
obj_type:
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
package:
|
|
452
|
-
The package of the deprecated object.
|
|
461
|
+
name: The name of the deprecated object.
|
|
462
|
+
alternative: An alternative API that the user may use in place of the
|
|
463
|
+
deprecated API.
|
|
464
|
+
|
|
465
|
+
The deprecation warning will tell the user about this alternative if
|
|
466
|
+
provided.
|
|
467
|
+
alternative_import: An alternative import that the user may use instead.
|
|
468
|
+
pending: If `True`, uses a `PendingDeprecationWarning` instead of a
|
|
469
|
+
`DeprecationWarning`.
|
|
470
|
+
|
|
471
|
+
Cannot be used together with removal.
|
|
472
|
+
obj_type: The object type being deprecated.
|
|
473
|
+
addendum: Additional text appended directly to the final message.
|
|
474
|
+
removal: The expected removal version.
|
|
475
|
+
|
|
476
|
+
With the default (an empty string), a removal version is automatically
|
|
477
|
+
computed from since. Set to other Falsy values to not schedule a removal
|
|
478
|
+
date.
|
|
479
|
+
|
|
480
|
+
Cannot be used together with pending.
|
|
481
|
+
package: The package of the deprecated object.
|
|
453
482
|
"""
|
|
454
483
|
if not pending:
|
|
455
484
|
if not removal:
|
|
@@ -534,8 +563,8 @@ def rename_parameter(
|
|
|
534
563
|
"""Decorator indicating that parameter *old* of *func* is renamed to *new*.
|
|
535
564
|
|
|
536
565
|
The actual implementation of *func* should use *new*, not *old*. If *old* is passed
|
|
537
|
-
to *func*, a DeprecationWarning is emitted, and its value is used, even if *new*
|
|
538
|
-
also passed by keyword.
|
|
566
|
+
to *func*, a `DeprecationWarning` is emitted, and its value is used, even if *new*
|
|
567
|
+
is also passed by keyword.
|
|
539
568
|
|
|
540
569
|
Args:
|
|
541
570
|
since: The version in which the parameter was renamed.
|
|
@@ -547,7 +547,7 @@ class BaseChatModel(BaseLanguageModel[AIMessage], ABC):
|
|
|
547
547
|
):
|
|
548
548
|
if block["type"] != index_type:
|
|
549
549
|
index_type = block["type"]
|
|
550
|
-
index
|
|
550
|
+
index += 1
|
|
551
551
|
if "index" not in block:
|
|
552
552
|
block["index"] = index
|
|
553
553
|
run_manager.on_llm_new_token(
|
|
@@ -679,7 +679,7 @@ class BaseChatModel(BaseLanguageModel[AIMessage], ABC):
|
|
|
679
679
|
):
|
|
680
680
|
if block["type"] != index_type:
|
|
681
681
|
index_type = block["type"]
|
|
682
|
-
index
|
|
682
|
+
index += 1
|
|
683
683
|
if "index" not in block:
|
|
684
684
|
block["index"] = index
|
|
685
685
|
await run_manager.on_llm_new_token(
|
|
@@ -730,7 +730,7 @@ class BaseChatModel(BaseLanguageModel[AIMessage], ABC):
|
|
|
730
730
|
|
|
731
731
|
# --- Custom methods ---
|
|
732
732
|
|
|
733
|
-
def _combine_llm_outputs(self,
|
|
733
|
+
def _combine_llm_outputs(self, _llm_outputs: list[dict | None], /) -> dict:
|
|
734
734
|
return {}
|
|
735
735
|
|
|
736
736
|
def _convert_cached_generations(self, cache_val: list) -> list[ChatGeneration]:
|
|
@@ -1187,7 +1187,7 @@ class BaseChatModel(BaseLanguageModel[AIMessage], ABC):
|
|
|
1187
1187
|
):
|
|
1188
1188
|
if block["type"] != index_type:
|
|
1189
1189
|
index_type = block["type"]
|
|
1190
|
-
index
|
|
1190
|
+
index += 1
|
|
1191
1191
|
if "index" not in block:
|
|
1192
1192
|
block["index"] = index
|
|
1193
1193
|
if run_manager:
|
|
@@ -1305,7 +1305,7 @@ class BaseChatModel(BaseLanguageModel[AIMessage], ABC):
|
|
|
1305
1305
|
):
|
|
1306
1306
|
if block["type"] != index_type:
|
|
1307
1307
|
index_type = block["type"]
|
|
1308
|
-
index
|
|
1308
|
+
index += 1
|
|
1309
1309
|
if "index" not in block:
|
|
1310
1310
|
block["index"] = index
|
|
1311
1311
|
if run_manager:
|
|
@@ -6,7 +6,7 @@ from langchain_core._import_utils import import_attr
|
|
|
6
6
|
|
|
7
7
|
if TYPE_CHECKING:
|
|
8
8
|
from langchain_core.load.dump import dumpd, dumps
|
|
9
|
-
from langchain_core.load.load import loads
|
|
9
|
+
from langchain_core.load.load import InitValidator, loads
|
|
10
10
|
from langchain_core.load.serializable import Serializable
|
|
11
11
|
|
|
12
12
|
# Unfortunately, we have to eagerly import load from langchain_core/load/load.py
|
|
@@ -15,11 +15,19 @@ if TYPE_CHECKING:
|
|
|
15
15
|
# the `from langchain_core.load.load import load` absolute import should also work.
|
|
16
16
|
from langchain_core.load.load import load
|
|
17
17
|
|
|
18
|
-
__all__ = (
|
|
18
|
+
__all__ = (
|
|
19
|
+
"InitValidator",
|
|
20
|
+
"Serializable",
|
|
21
|
+
"dumpd",
|
|
22
|
+
"dumps",
|
|
23
|
+
"load",
|
|
24
|
+
"loads",
|
|
25
|
+
)
|
|
19
26
|
|
|
20
27
|
_dynamic_imports = {
|
|
21
28
|
"dumpd": "dump",
|
|
22
29
|
"dumps": "dump",
|
|
30
|
+
"InitValidator": "load",
|
|
23
31
|
"loads": "load",
|
|
24
32
|
"Serializable": "serializable",
|
|
25
33
|
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""Validation utilities for LangChain serialization.
|
|
2
|
+
|
|
3
|
+
Provides escape-based protection against injection attacks in serialized objects. The
|
|
4
|
+
approach uses an allowlist design: only dicts explicitly produced by
|
|
5
|
+
`Serializable.to_json()` are treated as LC objects during deserialization.
|
|
6
|
+
|
|
7
|
+
## How escaping works
|
|
8
|
+
|
|
9
|
+
During serialization, plain dicts (user data) that contain an `'lc'` key are wrapped:
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
{"lc": 1, ...} # user data that looks like LC object
|
|
13
|
+
# becomes:
|
|
14
|
+
{"__lc_escaped__": {"lc": 1, ...}}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
During deserialization, escaped dicts are unwrapped and returned as plain dicts,
|
|
18
|
+
NOT instantiated as LC objects.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from typing import Any
|
|
22
|
+
|
|
23
|
+
_LC_ESCAPED_KEY = "__lc_escaped__"
|
|
24
|
+
"""Sentinel key used to mark escaped user dicts during serialization.
|
|
25
|
+
|
|
26
|
+
When a plain dict contains 'lc' key (which could be confused with LC objects),
|
|
27
|
+
we wrap it as {"__lc_escaped__": {...original...}}.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _needs_escaping(obj: dict[str, Any]) -> bool:
|
|
32
|
+
"""Check if a dict needs escaping to prevent confusion with LC objects.
|
|
33
|
+
|
|
34
|
+
A dict needs escaping if:
|
|
35
|
+
|
|
36
|
+
1. It has an `'lc'` key (could be confused with LC serialization format)
|
|
37
|
+
2. It has only the escape key (would be mistaken for an escaped dict)
|
|
38
|
+
"""
|
|
39
|
+
return "lc" in obj or (len(obj) == 1 and _LC_ESCAPED_KEY in obj)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _escape_dict(obj: dict[str, Any]) -> dict[str, Any]:
|
|
43
|
+
"""Wrap a dict in the escape marker.
|
|
44
|
+
|
|
45
|
+
Example:
|
|
46
|
+
```python
|
|
47
|
+
{"key": "value"} # becomes {"__lc_escaped__": {"key": "value"}}
|
|
48
|
+
```
|
|
49
|
+
"""
|
|
50
|
+
return {_LC_ESCAPED_KEY: obj}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _is_escaped_dict(obj: dict[str, Any]) -> bool:
|
|
54
|
+
"""Check if a dict is an escaped user dict.
|
|
55
|
+
|
|
56
|
+
Example:
|
|
57
|
+
```python
|
|
58
|
+
{"__lc_escaped__": {...}} # is an escaped dict
|
|
59
|
+
```
|
|
60
|
+
"""
|
|
61
|
+
return len(obj) == 1 and _LC_ESCAPED_KEY in obj
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _serialize_value(obj: Any) -> Any:
|
|
65
|
+
"""Serialize a value with escaping of user dicts.
|
|
66
|
+
|
|
67
|
+
Called recursively on kwarg values to escape any plain dicts that could be confused
|
|
68
|
+
with LC objects.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
obj: The value to serialize.
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
The serialized value with user dicts escaped as needed.
|
|
75
|
+
"""
|
|
76
|
+
from langchain_core.load.serializable import ( # noqa: PLC0415
|
|
77
|
+
Serializable,
|
|
78
|
+
to_json_not_implemented,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
if isinstance(obj, Serializable):
|
|
82
|
+
# This is an LC object - serialize it properly (not escaped)
|
|
83
|
+
return _serialize_lc_object(obj)
|
|
84
|
+
if isinstance(obj, dict):
|
|
85
|
+
if not all(isinstance(k, (str, int, float, bool, type(None))) for k in obj):
|
|
86
|
+
# if keys are not json serializable
|
|
87
|
+
return to_json_not_implemented(obj)
|
|
88
|
+
# Check if dict needs escaping BEFORE recursing into values.
|
|
89
|
+
# If it needs escaping, wrap it as-is - the contents are user data that
|
|
90
|
+
# will be returned as-is during deserialization (no instantiation).
|
|
91
|
+
# This prevents re-escaping of already-escaped nested content.
|
|
92
|
+
if _needs_escaping(obj):
|
|
93
|
+
return _escape_dict(obj)
|
|
94
|
+
# Safe dict (no 'lc' key) - recurse into values
|
|
95
|
+
return {k: _serialize_value(v) for k, v in obj.items()}
|
|
96
|
+
if isinstance(obj, (list, tuple)):
|
|
97
|
+
return [_serialize_value(item) for item in obj]
|
|
98
|
+
if isinstance(obj, (str, int, float, bool, type(None))):
|
|
99
|
+
return obj
|
|
100
|
+
|
|
101
|
+
# Non-JSON-serializable object (datetime, custom objects, etc.)
|
|
102
|
+
return to_json_not_implemented(obj)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _is_lc_secret(obj: Any) -> bool:
|
|
106
|
+
"""Check if an object is a LangChain secret marker."""
|
|
107
|
+
expected_num_keys = 3
|
|
108
|
+
return (
|
|
109
|
+
isinstance(obj, dict)
|
|
110
|
+
and obj.get("lc") == 1
|
|
111
|
+
and obj.get("type") == "secret"
|
|
112
|
+
and "id" in obj
|
|
113
|
+
and len(obj) == expected_num_keys
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _serialize_lc_object(obj: Any) -> dict[str, Any]:
|
|
118
|
+
"""Serialize a `Serializable` object with escaping of user data in kwargs.
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
obj: The `Serializable` object to serialize.
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
The serialized dict with user data in kwargs escaped as needed.
|
|
125
|
+
|
|
126
|
+
Note:
|
|
127
|
+
Kwargs values are processed with `_serialize_value` to escape user data (like
|
|
128
|
+
metadata) that contains `'lc'` keys. Secret fields (from `lc_secrets`) are
|
|
129
|
+
skipped because `to_json()` replaces their values with secret markers.
|
|
130
|
+
"""
|
|
131
|
+
from langchain_core.load.serializable import Serializable # noqa: PLC0415
|
|
132
|
+
|
|
133
|
+
if not isinstance(obj, Serializable):
|
|
134
|
+
msg = f"Expected Serializable, got {type(obj)}"
|
|
135
|
+
raise TypeError(msg)
|
|
136
|
+
|
|
137
|
+
serialized: dict[str, Any] = dict(obj.to_json())
|
|
138
|
+
|
|
139
|
+
# Process kwargs to escape user data that could be confused with LC objects
|
|
140
|
+
# Skip secret fields - to_json() already converted them to secret markers
|
|
141
|
+
if serialized.get("type") == "constructor" and "kwargs" in serialized:
|
|
142
|
+
serialized["kwargs"] = {
|
|
143
|
+
k: v if _is_lc_secret(v) else _serialize_value(v)
|
|
144
|
+
for k, v in serialized["kwargs"].items()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return serialized
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _unescape_value(obj: Any) -> Any:
|
|
151
|
+
"""Unescape a value, processing escape markers in dict values and lists.
|
|
152
|
+
|
|
153
|
+
When an escaped dict is encountered (`{"__lc_escaped__": ...}`), it's
|
|
154
|
+
unwrapped and the contents are returned AS-IS (no further processing).
|
|
155
|
+
The contents represent user data that should not be modified.
|
|
156
|
+
|
|
157
|
+
For regular dicts and lists, we recurse to find any nested escape markers.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
obj: The value to unescape.
|
|
161
|
+
|
|
162
|
+
Returns:
|
|
163
|
+
The unescaped value.
|
|
164
|
+
"""
|
|
165
|
+
if isinstance(obj, dict):
|
|
166
|
+
if _is_escaped_dict(obj):
|
|
167
|
+
# Unwrap and return the user data as-is (no further unescaping).
|
|
168
|
+
# The contents are user data that may contain more escape keys,
|
|
169
|
+
# but those are part of the user's actual data.
|
|
170
|
+
return obj[_LC_ESCAPED_KEY]
|
|
171
|
+
|
|
172
|
+
# Regular dict - recurse into values to find nested escape markers
|
|
173
|
+
return {k: _unescape_value(v) for k, v in obj.items()}
|
|
174
|
+
if isinstance(obj, list):
|
|
175
|
+
return [_unescape_value(item) for item in obj]
|
|
176
|
+
return obj
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""Serialize LangChain objects to JSON.
|
|
2
|
+
|
|
3
|
+
Provides `dumps` (to JSON string) and `dumpd` (to dict) for serializing
|
|
4
|
+
`Serializable` objects.
|
|
5
|
+
|
|
6
|
+
## Escaping
|
|
7
|
+
|
|
8
|
+
During serialization, plain dicts (user data) that contain an `'lc'` key are escaped
|
|
9
|
+
by wrapping them: `{"__lc_escaped__": {...original...}}`. This prevents injection
|
|
10
|
+
attacks where malicious data could trick the deserializer into instantiating
|
|
11
|
+
arbitrary classes. The escape marker is removed during deserialization.
|
|
12
|
+
|
|
13
|
+
This is an allowlist approach: only dicts explicitly produced by
|
|
14
|
+
`Serializable.to_json()` are treated as LC objects; everything else is escaped if it
|
|
15
|
+
could be confused with the LC format.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import json
|
|
19
|
+
from typing import Any
|
|
20
|
+
|
|
21
|
+
from pydantic import BaseModel
|
|
22
|
+
|
|
23
|
+
from langchain_core.load._validation import _serialize_value
|
|
24
|
+
from langchain_core.load.serializable import Serializable, to_json_not_implemented
|
|
25
|
+
from langchain_core.messages import AIMessage
|
|
26
|
+
from langchain_core.outputs import ChatGeneration
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def default(obj: Any) -> Any:
|
|
30
|
+
"""Return a default value for an object.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
obj: The object to serialize to json if it is a Serializable object.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
A JSON serializable object or a SerializedNotImplemented object.
|
|
37
|
+
"""
|
|
38
|
+
if isinstance(obj, Serializable):
|
|
39
|
+
return obj.to_json()
|
|
40
|
+
return to_json_not_implemented(obj)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _dump_pydantic_models(obj: Any) -> Any:
|
|
44
|
+
"""Convert nested Pydantic models to dicts for JSON serialization.
|
|
45
|
+
|
|
46
|
+
Handles the special case where a `ChatGeneration` contains an `AIMessage`
|
|
47
|
+
with a parsed Pydantic model in `additional_kwargs["parsed"]`. Since
|
|
48
|
+
Pydantic models aren't directly JSON serializable, this converts them to
|
|
49
|
+
dicts.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
obj: The object to process.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
A copy of the object with nested Pydantic models converted to dicts, or
|
|
56
|
+
the original object unchanged if no conversion was needed.
|
|
57
|
+
"""
|
|
58
|
+
if (
|
|
59
|
+
isinstance(obj, ChatGeneration)
|
|
60
|
+
and isinstance(obj.message, AIMessage)
|
|
61
|
+
and (parsed := obj.message.additional_kwargs.get("parsed"))
|
|
62
|
+
and isinstance(parsed, BaseModel)
|
|
63
|
+
):
|
|
64
|
+
obj_copy = obj.model_copy(deep=True)
|
|
65
|
+
obj_copy.message.additional_kwargs["parsed"] = parsed.model_dump()
|
|
66
|
+
return obj_copy
|
|
67
|
+
return obj
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def dumps(obj: Any, *, pretty: bool = False, **kwargs: Any) -> str:
|
|
71
|
+
"""Return a JSON string representation of an object.
|
|
72
|
+
|
|
73
|
+
Note:
|
|
74
|
+
Plain dicts containing an `'lc'` key are automatically escaped to prevent
|
|
75
|
+
confusion with LC serialization format. The escape marker is removed during
|
|
76
|
+
deserialization.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
obj: The object to dump.
|
|
80
|
+
pretty: Whether to pretty print the json.
|
|
81
|
+
|
|
82
|
+
If `True`, the json will be indented by either 2 spaces or the amount
|
|
83
|
+
provided in the `indent` kwarg.
|
|
84
|
+
**kwargs: Additional arguments to pass to `json.dumps`
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
A JSON string representation of the object.
|
|
88
|
+
|
|
89
|
+
Raises:
|
|
90
|
+
ValueError: If `default` is passed as a kwarg.
|
|
91
|
+
"""
|
|
92
|
+
if "default" in kwargs:
|
|
93
|
+
msg = "`default` should not be passed to dumps"
|
|
94
|
+
raise ValueError(msg)
|
|
95
|
+
|
|
96
|
+
obj = _dump_pydantic_models(obj)
|
|
97
|
+
serialized = _serialize_value(obj)
|
|
98
|
+
|
|
99
|
+
if pretty:
|
|
100
|
+
indent = kwargs.pop("indent", 2)
|
|
101
|
+
return json.dumps(serialized, indent=indent, **kwargs)
|
|
102
|
+
return json.dumps(serialized, **kwargs)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def dumpd(obj: Any) -> Any:
|
|
106
|
+
"""Return a dict representation of an object.
|
|
107
|
+
|
|
108
|
+
Note:
|
|
109
|
+
Plain dicts containing an `'lc'` key are automatically escaped to prevent
|
|
110
|
+
confusion with LC serialization format. The escape marker is removed during
|
|
111
|
+
deserialization.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
obj: The object to dump.
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
Dictionary that can be serialized to json using `json.dumps`.
|
|
118
|
+
"""
|
|
119
|
+
obj = _dump_pydantic_models(obj)
|
|
120
|
+
return _serialize_value(obj)
|