langchain-core 0.3.0.dev0__tar.gz → 0.3.0.dev1__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-0.3.0.dev0 → langchain_core-0.3.0.dev1}/PKG-INFO +2 -2
- langchain_core-0.3.0.dev1/langchain_core/__init__.py +25 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/_api/beta_decorator.py +1 -1
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/_api/deprecation.py +96 -13
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/callbacks/base.py +61 -6
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/callbacks/manager.py +130 -12
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/document_loaders/__init__.py +2 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/document_loaders/base.py +1 -1
- langchain_core-0.3.0.dev1/langchain_core/document_loaders/langsmith.py +128 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/documents/base.py +1 -1
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/embeddings/fake.py +52 -8
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/example_selectors/semantic_similarity.py +2 -2
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/exceptions.py +1 -1
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/graph_vectorstores/base.py +34 -19
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/graph_vectorstores/links.py +7 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/indexing/api.py +3 -3
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/language_models/__init__.py +2 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/language_models/base.py +26 -8
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/language_models/chat_models.py +114 -65
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/language_models/fake.py +6 -2
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/language_models/fake_chat_models.py +6 -2
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/language_models/llms.py +89 -10
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/load/load.py +1 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/load/mapping.py +10 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/load/serializable.py +23 -3
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/messages/ai.py +3 -4
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/messages/base.py +2 -2
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/messages/utils.py +57 -22
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/output_parsers/json.py +5 -4
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/output_parsers/openai_functions.py +9 -5
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/output_parsers/openai_tools.py +6 -9
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/output_parsers/pydantic.py +15 -10
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/output_parsers/xml.py +4 -4
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/outputs/chat_generation.py +2 -1
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/prompts/base.py +10 -3
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/prompts/chat.py +7 -7
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/prompts/few_shot.py +6 -6
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/prompts/few_shot_with_templates.py +4 -3
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/prompts/loading.py +1 -1
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/prompts/prompt.py +4 -2
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/prompts/string.py +5 -5
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/prompts/structured.py +39 -45
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/rate_limiters.py +1 -1
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/retrievers.py +41 -4
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/base.py +27 -20
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/config.py +2 -31
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/fallbacks.py +1 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/graph.py +2 -2
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/graph_mermaid.py +71 -40
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/history.py +21 -12
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/passthrough.py +1 -1
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/retry.py +7 -7
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/utils.py +6 -4
- langchain_core-0.3.0.dev1/langchain_core/tools/__init__.py +60 -0
- langchain_core-0.3.0.dev0/langchain_core/tools.py → langchain_core-0.3.0.dev1/langchain_core/tools/base.py +35 -826
- langchain_core-0.3.0.dev1/langchain_core/tools/convert.py +313 -0
- langchain_core-0.3.0.dev1/langchain_core/tools/render.py +65 -0
- langchain_core-0.3.0.dev1/langchain_core/tools/retriever.py +92 -0
- langchain_core-0.3.0.dev1/langchain_core/tools/simple.py +170 -0
- langchain_core-0.3.0.dev1/langchain_core/tools/structured.py +217 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/tracers/core.py +17 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/tracers/evaluation.py +4 -10
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/tracers/schemas.py +11 -10
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/__init__.py +4 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/_merge.py +17 -4
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/aiter.py +2 -2
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/function_calling.py +65 -19
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/json.py +1 -1
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/loading.py +4 -2
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/mustache.py +26 -20
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/pydantic.py +78 -30
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/utils.py +158 -4
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/vectorstores/base.py +69 -273
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/vectorstores/in_memory.py +230 -34
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/vectorstores/utils.py +6 -6
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/pyproject.toml +15 -28
- langchain_core-0.3.0.dev0/langchain_core/__init__.py +0 -15
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/README.md +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/_api/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/_api/internal.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/_api/path.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/agents.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/beta/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/beta/runnables/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/beta/runnables/context.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/caches.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/callbacks/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/callbacks/file.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/callbacks/stdout.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/callbacks/streaming_stdout.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/chat_history.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/chat_loaders.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/chat_sessions.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/document_loaders/blob_loaders.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/documents/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/documents/compressor.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/documents/transformers.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/embeddings/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/embeddings/embeddings.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/env.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/example_selectors/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/example_selectors/base.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/example_selectors/length_based.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/globals.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/graph_vectorstores/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/indexing/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/indexing/base.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/indexing/in_memory.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/load/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/load/dump.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/memory.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/messages/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/messages/chat.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/messages/function.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/messages/human.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/messages/modifier.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/messages/system.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/messages/tool.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/output_parsers/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/output_parsers/base.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/output_parsers/format_instructions.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/output_parsers/list.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/output_parsers/string.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/output_parsers/transform.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/outputs/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/outputs/chat_result.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/outputs/generation.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/outputs/llm_result.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/outputs/run_info.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/prompt_values.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/prompts/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/prompts/image.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/prompts/pipeline.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/py.typed +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/pydantic_v1/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/pydantic_v1/dataclasses.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/pydantic_v1/main.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/branch.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/configurable.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/graph_ascii.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/graph_png.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/learnable.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/router.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/runnables/schema.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/stores.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/structured_query.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/sys_info.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/tracers/__init__.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/tracers/_streaming.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/tracers/base.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/tracers/context.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/tracers/event_stream.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/tracers/langchain.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/tracers/langchain_v1.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/tracers/log_stream.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/tracers/memory_stream.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/tracers/root_listeners.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/tracers/run_collector.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/tracers/stdout.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/env.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/formatting.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/html.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/image.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/input.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/interactive_env.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/iter.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/json_schema.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/utils/strings.py +0 -0
- {langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/vectorstores/__init__.py +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: langchain-core
|
|
3
|
-
Version: 0.3.0.
|
|
3
|
+
Version: 0.3.0.dev1
|
|
4
4
|
Summary: Building applications with LLMs through composability
|
|
5
5
|
Home-page: https://github.com/langchain-ai/langchain
|
|
6
6
|
License: MIT
|
|
7
|
-
Requires-Python: >=3.
|
|
7
|
+
Requires-Python: >=3.9,<4.0
|
|
8
8
|
Classifier: License :: OSI Approved :: MIT License
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.9
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""``langchain-core`` defines the base abstractions for the LangChain ecosystem.
|
|
2
|
+
|
|
3
|
+
The interfaces for core components like chat models, LLMs, vector stores, retrievers,
|
|
4
|
+
and more are defined here. The universal invocation protocol (Runnables) along with
|
|
5
|
+
a syntax for combining components (LangChain Expression Language) are also defined here.
|
|
6
|
+
|
|
7
|
+
No third-party integrations are defined here. The dependencies are kept purposefully
|
|
8
|
+
very lightweight.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from importlib import metadata
|
|
12
|
+
|
|
13
|
+
from langchain_core._api import (
|
|
14
|
+
surface_langchain_beta_warnings,
|
|
15
|
+
surface_langchain_deprecation_warnings,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
__version__ = metadata.version(__package__)
|
|
20
|
+
except metadata.PackageNotFoundError:
|
|
21
|
+
# Case where package metadata is not available.
|
|
22
|
+
__version__ = ""
|
|
23
|
+
|
|
24
|
+
surface_langchain_deprecation_warnings()
|
|
25
|
+
surface_langchain_beta_warnings()
|
{langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/_api/beta_decorator.py
RENAMED
|
@@ -270,7 +270,7 @@ def warn_beta(
|
|
|
270
270
|
message += f" {addendum}"
|
|
271
271
|
|
|
272
272
|
warning = LangChainBetaWarning(message)
|
|
273
|
-
warnings.warn(warning, category=LangChainBetaWarning, stacklevel=
|
|
273
|
+
warnings.warn(warning, category=LangChainBetaWarning, stacklevel=4)
|
|
274
274
|
|
|
275
275
|
|
|
276
276
|
def surface_langchain_beta_warnings() -> None:
|
|
@@ -14,7 +14,17 @@ import contextlib
|
|
|
14
14
|
import functools
|
|
15
15
|
import inspect
|
|
16
16
|
import warnings
|
|
17
|
-
from typing import
|
|
17
|
+
from typing import (
|
|
18
|
+
Any,
|
|
19
|
+
Callable,
|
|
20
|
+
Generator,
|
|
21
|
+
Type,
|
|
22
|
+
TypeVar,
|
|
23
|
+
Union,
|
|
24
|
+
cast,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
from typing_extensions import ParamSpec
|
|
18
28
|
|
|
19
29
|
from langchain_core._api.internal import is_caller_internal
|
|
20
30
|
|
|
@@ -30,7 +40,8 @@ class LangChainPendingDeprecationWarning(PendingDeprecationWarning):
|
|
|
30
40
|
# PUBLIC API
|
|
31
41
|
|
|
32
42
|
|
|
33
|
-
|
|
43
|
+
# Last Any should be FieldInfoV1 but this leads to circular imports
|
|
44
|
+
T = TypeVar("T", bound=Union[Type, Callable[..., Any], Any])
|
|
34
45
|
|
|
35
46
|
|
|
36
47
|
def _validate_deprecation_params(
|
|
@@ -133,6 +144,7 @@ def deprecated(
|
|
|
133
144
|
_package: str = package,
|
|
134
145
|
) -> T:
|
|
135
146
|
"""Implementation of the decorator returned by `deprecated`."""
|
|
147
|
+
from langchain_core.utils.pydantic import FieldInfoV1
|
|
136
148
|
|
|
137
149
|
def emit_warning() -> None:
|
|
138
150
|
"""Emit the warning."""
|
|
@@ -207,50 +219,73 @@ def deprecated(
|
|
|
207
219
|
)
|
|
208
220
|
return cast(T, obj)
|
|
209
221
|
|
|
222
|
+
elif isinstance(obj, FieldInfoV1):
|
|
223
|
+
wrapped = None
|
|
224
|
+
if not _obj_type:
|
|
225
|
+
_obj_type = "attribute"
|
|
226
|
+
if not _name:
|
|
227
|
+
raise ValueError(f"Field {obj} must have a name to be deprecated.")
|
|
228
|
+
old_doc = obj.description
|
|
229
|
+
|
|
230
|
+
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T:
|
|
231
|
+
return cast(
|
|
232
|
+
T,
|
|
233
|
+
FieldInfoV1(
|
|
234
|
+
default=obj.default,
|
|
235
|
+
default_factory=obj.default_factory,
|
|
236
|
+
description=new_doc,
|
|
237
|
+
alias=obj.alias,
|
|
238
|
+
exclude=obj.exclude,
|
|
239
|
+
),
|
|
240
|
+
)
|
|
241
|
+
|
|
210
242
|
elif isinstance(obj, property):
|
|
211
243
|
if not _obj_type:
|
|
212
244
|
_obj_type = "attribute"
|
|
213
245
|
wrapped = None
|
|
214
|
-
_name = _name or obj.fget.__qualname__
|
|
246
|
+
_name = _name or cast(Union[Type, Callable], obj.fget).__qualname__
|
|
215
247
|
old_doc = obj.__doc__
|
|
216
248
|
|
|
217
249
|
class _deprecated_property(property):
|
|
218
250
|
"""A deprecated property."""
|
|
219
251
|
|
|
220
|
-
def __init__(self, fget=None, fset=None, fdel=None, doc=None):
|
|
252
|
+
def __init__(self, fget=None, fset=None, fdel=None, doc=None): # type: ignore[no-untyped-def]
|
|
221
253
|
super().__init__(fget, fset, fdel, doc)
|
|
222
254
|
self.__orig_fget = fget
|
|
223
255
|
self.__orig_fset = fset
|
|
224
256
|
self.__orig_fdel = fdel
|
|
225
257
|
|
|
226
|
-
def __get__(self, instance, owner=None):
|
|
258
|
+
def __get__(self, instance, owner=None): # type: ignore[no-untyped-def]
|
|
227
259
|
if instance is not None or owner is not None:
|
|
228
260
|
emit_warning()
|
|
229
261
|
return self.fget(instance)
|
|
230
262
|
|
|
231
|
-
def __set__(self, instance, value):
|
|
263
|
+
def __set__(self, instance, value): # type: ignore[no-untyped-def]
|
|
232
264
|
if instance is not None:
|
|
233
265
|
emit_warning()
|
|
234
266
|
return self.fset(instance, value)
|
|
235
267
|
|
|
236
|
-
def __delete__(self, instance):
|
|
268
|
+
def __delete__(self, instance): # type: ignore[no-untyped-def]
|
|
237
269
|
if instance is not None:
|
|
238
270
|
emit_warning()
|
|
239
271
|
return self.fdel(instance)
|
|
240
272
|
|
|
241
|
-
def __set_name__(self, owner, set_name):
|
|
273
|
+
def __set_name__(self, owner, set_name): # type: ignore[no-untyped-def]
|
|
242
274
|
nonlocal _name
|
|
243
275
|
if _name == "<lambda>":
|
|
244
276
|
_name = set_name
|
|
245
277
|
|
|
246
|
-
def finalize(wrapper: Callable[..., Any], new_doc: str) ->
|
|
278
|
+
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T:
|
|
247
279
|
"""Finalize the property."""
|
|
248
|
-
return
|
|
249
|
-
|
|
280
|
+
return cast(
|
|
281
|
+
T,
|
|
282
|
+
_deprecated_property(
|
|
283
|
+
fget=obj.fget, fset=obj.fset, fdel=obj.fdel, doc=new_doc
|
|
284
|
+
),
|
|
250
285
|
)
|
|
251
286
|
|
|
252
287
|
else:
|
|
253
|
-
_name = _name or obj.__qualname__
|
|
288
|
+
_name = _name or cast(Union[Type, Callable], obj).__qualname__
|
|
254
289
|
if not _obj_type:
|
|
255
290
|
# edge case: when a function is within another function
|
|
256
291
|
# within a test, this will call it a "method" not a "function"
|
|
@@ -409,7 +444,7 @@ def warn_deprecated(
|
|
|
409
444
|
LangChainPendingDeprecationWarning if pending else LangChainDeprecationWarning
|
|
410
445
|
)
|
|
411
446
|
warning = warning_cls(message)
|
|
412
|
-
warnings.warn(warning, category=LangChainDeprecationWarning, stacklevel=
|
|
447
|
+
warnings.warn(warning, category=LangChainDeprecationWarning, stacklevel=4)
|
|
413
448
|
|
|
414
449
|
|
|
415
450
|
def surface_langchain_deprecation_warnings() -> None:
|
|
@@ -423,3 +458,51 @@ def surface_langchain_deprecation_warnings() -> None:
|
|
|
423
458
|
"default",
|
|
424
459
|
category=LangChainDeprecationWarning,
|
|
425
460
|
)
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
_P = ParamSpec("_P")
|
|
464
|
+
_R = TypeVar("_R")
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
def rename_parameter(
|
|
468
|
+
*,
|
|
469
|
+
since: str,
|
|
470
|
+
removal: str,
|
|
471
|
+
old: str,
|
|
472
|
+
new: str,
|
|
473
|
+
) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]:
|
|
474
|
+
"""Decorator indicating that parameter *old* of *func* is renamed to *new*.
|
|
475
|
+
|
|
476
|
+
The actual implementation of *func* should use *new*, not *old*. If *old*
|
|
477
|
+
is passed to *func*, a DeprecationWarning is emitted, and its value is
|
|
478
|
+
used, even if *new* is also passed by keyword.
|
|
479
|
+
|
|
480
|
+
Example:
|
|
481
|
+
|
|
482
|
+
.. code-block:: python
|
|
483
|
+
|
|
484
|
+
@_api.rename_parameter("3.1", "bad_name", "good_name")
|
|
485
|
+
def func(good_name): ...
|
|
486
|
+
"""
|
|
487
|
+
|
|
488
|
+
def decorator(f: Callable[_P, _R]) -> Callable[_P, _R]:
|
|
489
|
+
@functools.wraps(f)
|
|
490
|
+
def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _R:
|
|
491
|
+
if new in kwargs and old in kwargs:
|
|
492
|
+
raise TypeError(
|
|
493
|
+
f"{f.__name__}() got multiple values for argument {new!r}"
|
|
494
|
+
)
|
|
495
|
+
if old in kwargs:
|
|
496
|
+
warn_deprecated(
|
|
497
|
+
since,
|
|
498
|
+
removal=removal,
|
|
499
|
+
message=f"The parameter `{old}` of `{f.__name__}` was "
|
|
500
|
+
f"deprecated in {since} and will be removed "
|
|
501
|
+
f"in {removal} Use `{new}` instead.",
|
|
502
|
+
)
|
|
503
|
+
kwargs[new] = kwargs.pop(old)
|
|
504
|
+
return f(*args, **kwargs)
|
|
505
|
+
|
|
506
|
+
return wrapper
|
|
507
|
+
|
|
508
|
+
return decorator
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import logging
|
|
5
6
|
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, TypeVar, Union
|
|
6
7
|
from uuid import UUID
|
|
7
8
|
|
|
@@ -13,6 +14,8 @@ if TYPE_CHECKING:
|
|
|
13
14
|
from langchain_core.messages import BaseMessage
|
|
14
15
|
from langchain_core.outputs import ChatGenerationChunk, GenerationChunk, LLMResult
|
|
15
16
|
|
|
17
|
+
_LOGGER = logging.getLogger(__name__)
|
|
18
|
+
|
|
16
19
|
|
|
17
20
|
class RetrieverManagerMixin:
|
|
18
21
|
"""Mixin for Retriever callbacks."""
|
|
@@ -911,15 +914,67 @@ class BaseCallbackManager(CallbackManagerMixin):
|
|
|
911
914
|
def copy(self: T) -> T:
|
|
912
915
|
"""Copy the callback manager."""
|
|
913
916
|
return self.__class__(
|
|
914
|
-
handlers=self.handlers,
|
|
915
|
-
inheritable_handlers=self.inheritable_handlers,
|
|
917
|
+
handlers=self.handlers.copy(),
|
|
918
|
+
inheritable_handlers=self.inheritable_handlers.copy(),
|
|
916
919
|
parent_run_id=self.parent_run_id,
|
|
917
|
-
tags=self.tags,
|
|
918
|
-
inheritable_tags=self.inheritable_tags,
|
|
919
|
-
metadata=self.metadata,
|
|
920
|
-
inheritable_metadata=self.inheritable_metadata,
|
|
920
|
+
tags=self.tags.copy(),
|
|
921
|
+
inheritable_tags=self.inheritable_tags.copy(),
|
|
922
|
+
metadata=self.metadata.copy(),
|
|
923
|
+
inheritable_metadata=self.inheritable_metadata.copy(),
|
|
924
|
+
)
|
|
925
|
+
|
|
926
|
+
def merge(self: T, other: BaseCallbackManager) -> T:
|
|
927
|
+
"""Merge the callback manager with another callback manager.
|
|
928
|
+
|
|
929
|
+
May be overwritten in subclasses. Primarily used internally
|
|
930
|
+
within merge_configs.
|
|
931
|
+
|
|
932
|
+
Returns:
|
|
933
|
+
BaseCallbackManager: The merged callback manager of the same type
|
|
934
|
+
as the current object.
|
|
935
|
+
|
|
936
|
+
Example: Merging two callback managers.
|
|
937
|
+
|
|
938
|
+
.. code-block:: python
|
|
939
|
+
|
|
940
|
+
from langchain_core.callbacks.manager import CallbackManager, trace_as_chain_group
|
|
941
|
+
from langchain_core.callbacks.stdout import StdOutCallbackHandler
|
|
942
|
+
|
|
943
|
+
manager = CallbackManager(handlers=[StdOutCallbackHandler()], tags=["tag2"])
|
|
944
|
+
with trace_as_chain_group("My Group Name", tags=["tag1"]) as group_manager:
|
|
945
|
+
merged_manager = group_manager.merge(manager)
|
|
946
|
+
print(merged_manager.handlers)
|
|
947
|
+
# [
|
|
948
|
+
# <langchain_core.callbacks.stdout.StdOutCallbackHandler object at ...>,
|
|
949
|
+
# <langchain_core.callbacks.streaming_stdout.StreamingStdOutCallbackHandler object at ...>,
|
|
950
|
+
# ]
|
|
951
|
+
|
|
952
|
+
print(merged_manager.tags)
|
|
953
|
+
# ['tag2', 'tag1']
|
|
954
|
+
|
|
955
|
+
""" # noqa: E501
|
|
956
|
+
manager = self.__class__(
|
|
957
|
+
parent_run_id=self.parent_run_id or other.parent_run_id,
|
|
958
|
+
handlers=[],
|
|
959
|
+
inheritable_handlers=[],
|
|
960
|
+
tags=list(set(self.tags + other.tags)),
|
|
961
|
+
inheritable_tags=list(set(self.inheritable_tags + other.inheritable_tags)),
|
|
962
|
+
metadata={
|
|
963
|
+
**self.metadata,
|
|
964
|
+
**other.metadata,
|
|
965
|
+
},
|
|
921
966
|
)
|
|
922
967
|
|
|
968
|
+
handlers = self.handlers + other.handlers
|
|
969
|
+
inheritable_handlers = self.inheritable_handlers + other.inheritable_handlers
|
|
970
|
+
|
|
971
|
+
for handler in handlers:
|
|
972
|
+
manager.add_handler(handler)
|
|
973
|
+
|
|
974
|
+
for handler in inheritable_handlers:
|
|
975
|
+
manager.add_handler(handler, inherit=True)
|
|
976
|
+
return manager
|
|
977
|
+
|
|
923
978
|
@property
|
|
924
979
|
def is_async(self) -> bool:
|
|
925
980
|
"""Whether the callback manager is async."""
|
|
@@ -1612,16 +1612,75 @@ class CallbackManagerForChainGroup(CallbackManager):
|
|
|
1612
1612
|
def copy(self) -> CallbackManagerForChainGroup:
|
|
1613
1613
|
"""Copy the callback manager."""
|
|
1614
1614
|
return self.__class__(
|
|
1615
|
-
handlers=self.handlers,
|
|
1616
|
-
inheritable_handlers=self.inheritable_handlers,
|
|
1615
|
+
handlers=self.handlers.copy(),
|
|
1616
|
+
inheritable_handlers=self.inheritable_handlers.copy(),
|
|
1617
1617
|
parent_run_id=self.parent_run_id,
|
|
1618
|
-
tags=self.tags,
|
|
1619
|
-
inheritable_tags=self.inheritable_tags,
|
|
1620
|
-
metadata=self.metadata,
|
|
1621
|
-
inheritable_metadata=self.inheritable_metadata,
|
|
1618
|
+
tags=self.tags.copy(),
|
|
1619
|
+
inheritable_tags=self.inheritable_tags.copy(),
|
|
1620
|
+
metadata=self.metadata.copy(),
|
|
1621
|
+
inheritable_metadata=self.inheritable_metadata.copy(),
|
|
1622
|
+
parent_run_manager=self.parent_run_manager,
|
|
1623
|
+
)
|
|
1624
|
+
|
|
1625
|
+
def merge(
|
|
1626
|
+
self: CallbackManagerForChainGroup, other: BaseCallbackManager
|
|
1627
|
+
) -> CallbackManagerForChainGroup:
|
|
1628
|
+
"""Merge the group callback manager with another callback manager.
|
|
1629
|
+
|
|
1630
|
+
Overwrites the merge method in the base class to ensure that the
|
|
1631
|
+
parent run manager is preserved. Keeps the parent_run_manager
|
|
1632
|
+
from the current object.
|
|
1633
|
+
|
|
1634
|
+
Returns:
|
|
1635
|
+
CallbackManagerForChainGroup: A copy of the current object with the
|
|
1636
|
+
handlers, tags, and other attributes merged from the other object.
|
|
1637
|
+
|
|
1638
|
+
Example: Merging two callback managers.
|
|
1639
|
+
|
|
1640
|
+
.. code-block:: python
|
|
1641
|
+
|
|
1642
|
+
from langchain_core.callbacks.manager import CallbackManager, trace_as_chain_group
|
|
1643
|
+
from langchain_core.callbacks.stdout import StdOutCallbackHandler
|
|
1644
|
+
|
|
1645
|
+
manager = CallbackManager(handlers=[StdOutCallbackHandler()], tags=["tag2"])
|
|
1646
|
+
with trace_as_chain_group("My Group Name", tags=["tag1"]) as group_manager:
|
|
1647
|
+
merged_manager = group_manager.merge(manager)
|
|
1648
|
+
print(type(merged_manager))
|
|
1649
|
+
# <class 'langchain_core.callbacks.manager.CallbackManagerForChainGroup'>
|
|
1650
|
+
|
|
1651
|
+
print(merged_manager.handlers)
|
|
1652
|
+
# [
|
|
1653
|
+
# <langchain_core.callbacks.stdout.LangChainTracer object at ...>,
|
|
1654
|
+
# <langchain_core.callbacks.streaming_stdout.StdOutCallbackHandler object at ...>,
|
|
1655
|
+
# ]
|
|
1656
|
+
|
|
1657
|
+
print(merged_manager.tags)
|
|
1658
|
+
# ['tag2', 'tag1']
|
|
1659
|
+
|
|
1660
|
+
""" # noqa: E501
|
|
1661
|
+
manager = self.__class__(
|
|
1662
|
+
parent_run_id=self.parent_run_id or other.parent_run_id,
|
|
1663
|
+
handlers=[],
|
|
1664
|
+
inheritable_handlers=[],
|
|
1665
|
+
tags=list(set(self.tags + other.tags)),
|
|
1666
|
+
inheritable_tags=list(set(self.inheritable_tags + other.inheritable_tags)),
|
|
1667
|
+
metadata={
|
|
1668
|
+
**self.metadata,
|
|
1669
|
+
**other.metadata,
|
|
1670
|
+
},
|
|
1622
1671
|
parent_run_manager=self.parent_run_manager,
|
|
1623
1672
|
)
|
|
1624
1673
|
|
|
1674
|
+
handlers = self.handlers + other.handlers
|
|
1675
|
+
inheritable_handlers = self.inheritable_handlers + other.inheritable_handlers
|
|
1676
|
+
|
|
1677
|
+
for handler in handlers:
|
|
1678
|
+
manager.add_handler(handler)
|
|
1679
|
+
|
|
1680
|
+
for handler in inheritable_handlers:
|
|
1681
|
+
manager.add_handler(handler, inherit=True)
|
|
1682
|
+
return manager
|
|
1683
|
+
|
|
1625
1684
|
def on_chain_end(self, outputs: Union[Dict[str, Any], Any], **kwargs: Any) -> None:
|
|
1626
1685
|
"""Run when traced chain group ends.
|
|
1627
1686
|
|
|
@@ -2040,16 +2099,75 @@ class AsyncCallbackManagerForChainGroup(AsyncCallbackManager):
|
|
|
2040
2099
|
def copy(self) -> AsyncCallbackManagerForChainGroup:
|
|
2041
2100
|
"""Copy the async callback manager."""
|
|
2042
2101
|
return self.__class__(
|
|
2043
|
-
handlers=self.handlers,
|
|
2044
|
-
inheritable_handlers=self.inheritable_handlers,
|
|
2102
|
+
handlers=self.handlers.copy(),
|
|
2103
|
+
inheritable_handlers=self.inheritable_handlers.copy(),
|
|
2045
2104
|
parent_run_id=self.parent_run_id,
|
|
2046
|
-
tags=self.tags,
|
|
2047
|
-
inheritable_tags=self.inheritable_tags,
|
|
2048
|
-
metadata=self.metadata,
|
|
2049
|
-
inheritable_metadata=self.inheritable_metadata,
|
|
2105
|
+
tags=self.tags.copy(),
|
|
2106
|
+
inheritable_tags=self.inheritable_tags.copy(),
|
|
2107
|
+
metadata=self.metadata.copy(),
|
|
2108
|
+
inheritable_metadata=self.inheritable_metadata.copy(),
|
|
2109
|
+
parent_run_manager=self.parent_run_manager,
|
|
2110
|
+
)
|
|
2111
|
+
|
|
2112
|
+
def merge(
|
|
2113
|
+
self: AsyncCallbackManagerForChainGroup, other: BaseCallbackManager
|
|
2114
|
+
) -> AsyncCallbackManagerForChainGroup:
|
|
2115
|
+
"""Merge the group callback manager with another callback manager.
|
|
2116
|
+
|
|
2117
|
+
Overwrites the merge method in the base class to ensure that the
|
|
2118
|
+
parent run manager is preserved. Keeps the parent_run_manager
|
|
2119
|
+
from the current object.
|
|
2120
|
+
|
|
2121
|
+
Returns:
|
|
2122
|
+
AsyncCallbackManagerForChainGroup: A copy of the current AsyncCallbackManagerForChainGroup
|
|
2123
|
+
with the handlers, tags, etc. of the other callback manager merged in.
|
|
2124
|
+
|
|
2125
|
+
Example: Merging two callback managers.
|
|
2126
|
+
|
|
2127
|
+
.. code-block:: python
|
|
2128
|
+
|
|
2129
|
+
from langchain_core.callbacks.manager import CallbackManager, atrace_as_chain_group
|
|
2130
|
+
from langchain_core.callbacks.stdout import StdOutCallbackHandler
|
|
2131
|
+
|
|
2132
|
+
manager = CallbackManager(handlers=[StdOutCallbackHandler()], tags=["tag2"])
|
|
2133
|
+
async with atrace_as_chain_group("My Group Name", tags=["tag1"]) as group_manager:
|
|
2134
|
+
merged_manager = group_manager.merge(manager)
|
|
2135
|
+
print(type(merged_manager))
|
|
2136
|
+
# <class 'langchain_core.callbacks.manager.AsyncCallbackManagerForChainGroup'>
|
|
2137
|
+
|
|
2138
|
+
print(merged_manager.handlers)
|
|
2139
|
+
# [
|
|
2140
|
+
# <langchain_core.callbacks.stdout.LangChainTracer object at ...>,
|
|
2141
|
+
# <langchain_core.callbacks.streaming_stdout.StdOutCallbackHandler object at ...>,
|
|
2142
|
+
# ]
|
|
2143
|
+
|
|
2144
|
+
print(merged_manager.tags)
|
|
2145
|
+
# ['tag2', 'tag1']
|
|
2146
|
+
|
|
2147
|
+
""" # noqa: E501
|
|
2148
|
+
manager = self.__class__(
|
|
2149
|
+
parent_run_id=self.parent_run_id or other.parent_run_id,
|
|
2150
|
+
handlers=[],
|
|
2151
|
+
inheritable_handlers=[],
|
|
2152
|
+
tags=list(set(self.tags + other.tags)),
|
|
2153
|
+
inheritable_tags=list(set(self.inheritable_tags + other.inheritable_tags)),
|
|
2154
|
+
metadata={
|
|
2155
|
+
**self.metadata,
|
|
2156
|
+
**other.metadata,
|
|
2157
|
+
},
|
|
2050
2158
|
parent_run_manager=self.parent_run_manager,
|
|
2051
2159
|
)
|
|
2052
2160
|
|
|
2161
|
+
handlers = self.handlers + other.handlers
|
|
2162
|
+
inheritable_handlers = self.inheritable_handlers + other.inheritable_handlers
|
|
2163
|
+
|
|
2164
|
+
for handler in handlers:
|
|
2165
|
+
manager.add_handler(handler)
|
|
2166
|
+
|
|
2167
|
+
for handler in inheritable_handlers:
|
|
2168
|
+
manager.add_handler(handler, inherit=True)
|
|
2169
|
+
return manager
|
|
2170
|
+
|
|
2053
2171
|
async def on_chain_end(
|
|
2054
2172
|
self, outputs: Union[Dict[str, Any], Any], **kwargs: Any
|
|
2055
2173
|
) -> None:
|
{langchain_core-0.3.0.dev0 → langchain_core-0.3.0.dev1}/langchain_core/document_loaders/__init__.py
RENAMED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from langchain_core.document_loaders.base import BaseBlobParser, BaseLoader
|
|
2
2
|
from langchain_core.document_loaders.blob_loaders import Blob, BlobLoader, PathLike
|
|
3
|
+
from langchain_core.document_loaders.langsmith import LangSmithLoader
|
|
3
4
|
|
|
4
5
|
__all__ = [
|
|
5
6
|
"BaseBlobParser",
|
|
@@ -7,4 +8,5 @@ __all__ = [
|
|
|
7
8
|
"Blob",
|
|
8
9
|
"BlobLoader",
|
|
9
10
|
"PathLike",
|
|
11
|
+
"LangSmithLoader",
|
|
10
12
|
]
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
import json
|
|
3
|
+
import uuid
|
|
4
|
+
from typing import Any, Callable, Iterator, Optional, Sequence, Union
|
|
5
|
+
|
|
6
|
+
from langsmith import Client as LangSmithClient
|
|
7
|
+
|
|
8
|
+
from langchain_core.document_loaders.base import BaseLoader
|
|
9
|
+
from langchain_core.documents import Document
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class LangSmithLoader(BaseLoader):
|
|
13
|
+
"""Load LangSmith Dataset examples as Documents.
|
|
14
|
+
|
|
15
|
+
Loads the example inputs as the Document page content and places the entire example
|
|
16
|
+
into the Document metadata. This allows you to easily create few-shot example
|
|
17
|
+
retrievers from the loaded documents.
|
|
18
|
+
|
|
19
|
+
.. dropdown:: Lazy load
|
|
20
|
+
|
|
21
|
+
.. code-block:: python
|
|
22
|
+
|
|
23
|
+
from langchain_core.document_loaders import LangSmithLoader
|
|
24
|
+
|
|
25
|
+
loader = LangSmithLoader(dataset_id="...", limit=100)
|
|
26
|
+
docs = []
|
|
27
|
+
for doc in loader.lazy_load():
|
|
28
|
+
docs.append(doc)
|
|
29
|
+
|
|
30
|
+
.. code-block:: pycon
|
|
31
|
+
|
|
32
|
+
# -> [Document("...", metadata={"inputs": {...}, "outputs": {...}, ...}), ...]
|
|
33
|
+
|
|
34
|
+
.. versionadded:: 0.2.34
|
|
35
|
+
""" # noqa: E501
|
|
36
|
+
|
|
37
|
+
def __init__(
|
|
38
|
+
self,
|
|
39
|
+
*,
|
|
40
|
+
dataset_id: Optional[Union[uuid.UUID, str]] = None,
|
|
41
|
+
dataset_name: Optional[str] = None,
|
|
42
|
+
example_ids: Optional[Sequence[Union[uuid.UUID, str]]] = None,
|
|
43
|
+
as_of: Optional[Union[datetime.datetime, str]] = None,
|
|
44
|
+
splits: Optional[Sequence[str]] = None,
|
|
45
|
+
inline_s3_urls: bool = True,
|
|
46
|
+
offset: int = 0,
|
|
47
|
+
limit: Optional[int] = None,
|
|
48
|
+
metadata: Optional[dict] = None,
|
|
49
|
+
filter: Optional[str] = None,
|
|
50
|
+
content_key: str = "",
|
|
51
|
+
format_content: Optional[Callable[..., str]] = None,
|
|
52
|
+
client: Optional[LangSmithClient] = None,
|
|
53
|
+
**client_kwargs: Any,
|
|
54
|
+
) -> None:
|
|
55
|
+
"""
|
|
56
|
+
Args:
|
|
57
|
+
dataset_id: The ID of the dataset to filter by. Defaults to None.
|
|
58
|
+
dataset_name: The name of the dataset to filter by. Defaults to None.
|
|
59
|
+
content_key: The inputs key to set as Document page content. ``"."`` characters
|
|
60
|
+
are interpreted as nested keys. E.g. ``content_key="first.second"`` will
|
|
61
|
+
result in
|
|
62
|
+
``Document(page_content=format_content(example.inputs["first"]["second"]))``
|
|
63
|
+
format_content: Function for converting the content extracted from the example
|
|
64
|
+
inputs into a string. Defaults to JSON-encoding the contents.
|
|
65
|
+
example_ids: The IDs of the examples to filter by. Defaults to None.
|
|
66
|
+
as_of: The dataset version tag OR
|
|
67
|
+
timestamp to retrieve the examples as of.
|
|
68
|
+
Response examples will only be those that were present at the time
|
|
69
|
+
of the tagged (or timestamped) version.
|
|
70
|
+
splits: A list of dataset splits, which are
|
|
71
|
+
divisions of your dataset such as 'train', 'test', or 'validation'.
|
|
72
|
+
Returns examples only from the specified splits.
|
|
73
|
+
inline_s3_urls: Whether to inline S3 URLs. Defaults to True.
|
|
74
|
+
offset: The offset to start from. Defaults to 0.
|
|
75
|
+
limit: The maximum number of examples to return.
|
|
76
|
+
filter: A structured filter string to apply to the examples.
|
|
77
|
+
client: LangSmith Client. If not provided will be initialized from below args.
|
|
78
|
+
client_kwargs: Keyword args to pass to LangSmith client init. Should only be
|
|
79
|
+
specified if ``client`` isn't.
|
|
80
|
+
""" # noqa: E501
|
|
81
|
+
if client and client_kwargs:
|
|
82
|
+
raise ValueError
|
|
83
|
+
self._client = client or LangSmithClient(**client_kwargs)
|
|
84
|
+
self.content_key = list(content_key.split(".")) if content_key else []
|
|
85
|
+
self.format_content = format_content or _stringify
|
|
86
|
+
self.dataset_id = dataset_id
|
|
87
|
+
self.dataset_name = dataset_name
|
|
88
|
+
self.example_ids = example_ids
|
|
89
|
+
self.as_of = as_of
|
|
90
|
+
self.splits = splits
|
|
91
|
+
self.inline_s3_urls = inline_s3_urls
|
|
92
|
+
self.offset = offset
|
|
93
|
+
self.limit = limit
|
|
94
|
+
self.metadata = metadata
|
|
95
|
+
self.filter = filter
|
|
96
|
+
|
|
97
|
+
def lazy_load(self) -> Iterator[Document]:
|
|
98
|
+
for example in self._client.list_examples(
|
|
99
|
+
dataset_id=self.dataset_id,
|
|
100
|
+
dataset_name=self.dataset_name,
|
|
101
|
+
example_ids=self.example_ids,
|
|
102
|
+
as_of=self.as_of,
|
|
103
|
+
splits=self.splits,
|
|
104
|
+
inline_s3_urls=self.inline_s3_urls,
|
|
105
|
+
offset=self.offset,
|
|
106
|
+
limit=self.limit,
|
|
107
|
+
metadata=self.metadata,
|
|
108
|
+
filter=self.filter,
|
|
109
|
+
):
|
|
110
|
+
content: Any = example.inputs
|
|
111
|
+
for key in self.content_key:
|
|
112
|
+
content = content[key]
|
|
113
|
+
content_str = self.format_content(content)
|
|
114
|
+
metadata = example.dict()
|
|
115
|
+
# Stringify datetime and UUID types.
|
|
116
|
+
for k in ("dataset_id", "created_at", "modified_at", "source_run_id", "id"):
|
|
117
|
+
metadata[k] = str(metadata[k]) if metadata[k] else metadata[k]
|
|
118
|
+
yield Document(content_str, metadata=metadata)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _stringify(x: Union[str, dict]) -> str:
|
|
122
|
+
if isinstance(x, str):
|
|
123
|
+
return x
|
|
124
|
+
else:
|
|
125
|
+
try:
|
|
126
|
+
return json.dumps(x, indent=2)
|
|
127
|
+
except Exception:
|
|
128
|
+
return str(x)
|
|
@@ -141,7 +141,7 @@ class Blob(BaseMedia):
|
|
|
141
141
|
def as_string(self) -> str:
|
|
142
142
|
"""Read data as a string."""
|
|
143
143
|
if self.data is None and self.path:
|
|
144
|
-
with open(str(self.path),
|
|
144
|
+
with open(str(self.path), encoding=self.encoding) as f:
|
|
145
145
|
return f.read()
|
|
146
146
|
elif isinstance(self.data, bytes):
|
|
147
147
|
return self.data.decode(self.encoding)
|