langchain-core 0.4.0.dev0__py3-none-any.whl → 1.0.0__py3-none-any.whl
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.
Potentially problematic release.
This version of langchain-core might be problematic. Click here for more details.
- langchain_core/__init__.py +1 -1
- langchain_core/_api/__init__.py +3 -4
- langchain_core/_api/beta_decorator.py +45 -70
- langchain_core/_api/deprecation.py +80 -80
- langchain_core/_api/path.py +22 -8
- langchain_core/_import_utils.py +10 -4
- langchain_core/agents.py +25 -21
- langchain_core/caches.py +53 -63
- langchain_core/callbacks/__init__.py +1 -8
- langchain_core/callbacks/base.py +341 -348
- langchain_core/callbacks/file.py +55 -44
- langchain_core/callbacks/manager.py +546 -683
- langchain_core/callbacks/stdout.py +29 -30
- langchain_core/callbacks/streaming_stdout.py +35 -36
- langchain_core/callbacks/usage.py +65 -70
- langchain_core/chat_history.py +48 -55
- langchain_core/document_loaders/base.py +46 -21
- langchain_core/document_loaders/langsmith.py +39 -36
- langchain_core/documents/__init__.py +0 -1
- langchain_core/documents/base.py +96 -74
- langchain_core/documents/compressor.py +12 -9
- langchain_core/documents/transformers.py +29 -28
- langchain_core/embeddings/fake.py +56 -57
- langchain_core/env.py +2 -3
- langchain_core/example_selectors/base.py +12 -0
- langchain_core/example_selectors/length_based.py +1 -1
- langchain_core/example_selectors/semantic_similarity.py +21 -25
- langchain_core/exceptions.py +15 -9
- langchain_core/globals.py +4 -163
- langchain_core/indexing/api.py +132 -125
- langchain_core/indexing/base.py +64 -67
- langchain_core/indexing/in_memory.py +26 -6
- langchain_core/language_models/__init__.py +15 -27
- langchain_core/language_models/_utils.py +267 -117
- langchain_core/language_models/base.py +92 -177
- langchain_core/language_models/chat_models.py +547 -407
- langchain_core/language_models/fake.py +11 -11
- langchain_core/language_models/fake_chat_models.py +72 -118
- langchain_core/language_models/llms.py +168 -242
- langchain_core/load/dump.py +8 -11
- langchain_core/load/load.py +32 -28
- langchain_core/load/mapping.py +2 -4
- langchain_core/load/serializable.py +50 -56
- langchain_core/messages/__init__.py +36 -51
- langchain_core/messages/ai.py +377 -150
- langchain_core/messages/base.py +239 -47
- langchain_core/messages/block_translators/__init__.py +111 -0
- langchain_core/messages/block_translators/anthropic.py +470 -0
- langchain_core/messages/block_translators/bedrock.py +94 -0
- langchain_core/messages/block_translators/bedrock_converse.py +297 -0
- langchain_core/messages/block_translators/google_genai.py +530 -0
- langchain_core/messages/block_translators/google_vertexai.py +21 -0
- langchain_core/messages/block_translators/groq.py +143 -0
- langchain_core/messages/block_translators/langchain_v0.py +301 -0
- langchain_core/messages/block_translators/openai.py +1010 -0
- langchain_core/messages/chat.py +2 -3
- langchain_core/messages/content.py +1423 -0
- langchain_core/messages/function.py +7 -7
- langchain_core/messages/human.py +44 -38
- langchain_core/messages/modifier.py +3 -2
- langchain_core/messages/system.py +40 -27
- langchain_core/messages/tool.py +160 -58
- langchain_core/messages/utils.py +527 -638
- langchain_core/output_parsers/__init__.py +1 -14
- langchain_core/output_parsers/base.py +68 -104
- langchain_core/output_parsers/json.py +13 -17
- langchain_core/output_parsers/list.py +11 -33
- langchain_core/output_parsers/openai_functions.py +56 -74
- langchain_core/output_parsers/openai_tools.py +68 -109
- langchain_core/output_parsers/pydantic.py +15 -13
- langchain_core/output_parsers/string.py +6 -2
- langchain_core/output_parsers/transform.py +17 -60
- langchain_core/output_parsers/xml.py +34 -44
- langchain_core/outputs/__init__.py +1 -1
- langchain_core/outputs/chat_generation.py +26 -11
- langchain_core/outputs/chat_result.py +1 -3
- langchain_core/outputs/generation.py +17 -6
- langchain_core/outputs/llm_result.py +15 -8
- langchain_core/prompt_values.py +29 -123
- langchain_core/prompts/__init__.py +3 -27
- langchain_core/prompts/base.py +48 -63
- langchain_core/prompts/chat.py +259 -288
- langchain_core/prompts/dict.py +19 -11
- langchain_core/prompts/few_shot.py +84 -90
- langchain_core/prompts/few_shot_with_templates.py +14 -12
- langchain_core/prompts/image.py +19 -14
- langchain_core/prompts/loading.py +6 -8
- langchain_core/prompts/message.py +7 -8
- langchain_core/prompts/prompt.py +42 -43
- langchain_core/prompts/string.py +37 -16
- langchain_core/prompts/structured.py +43 -46
- langchain_core/rate_limiters.py +51 -60
- langchain_core/retrievers.py +52 -192
- langchain_core/runnables/base.py +1727 -1683
- langchain_core/runnables/branch.py +52 -73
- langchain_core/runnables/config.py +89 -103
- langchain_core/runnables/configurable.py +128 -130
- langchain_core/runnables/fallbacks.py +93 -82
- langchain_core/runnables/graph.py +127 -127
- langchain_core/runnables/graph_ascii.py +63 -41
- langchain_core/runnables/graph_mermaid.py +87 -70
- langchain_core/runnables/graph_png.py +31 -36
- langchain_core/runnables/history.py +145 -161
- langchain_core/runnables/passthrough.py +141 -144
- langchain_core/runnables/retry.py +84 -68
- langchain_core/runnables/router.py +33 -37
- langchain_core/runnables/schema.py +79 -72
- langchain_core/runnables/utils.py +95 -139
- langchain_core/stores.py +85 -131
- langchain_core/structured_query.py +11 -15
- langchain_core/sys_info.py +31 -32
- langchain_core/tools/__init__.py +1 -14
- langchain_core/tools/base.py +221 -247
- langchain_core/tools/convert.py +144 -161
- langchain_core/tools/render.py +10 -10
- langchain_core/tools/retriever.py +12 -19
- langchain_core/tools/simple.py +52 -29
- langchain_core/tools/structured.py +56 -60
- langchain_core/tracers/__init__.py +1 -9
- langchain_core/tracers/_streaming.py +6 -7
- langchain_core/tracers/base.py +103 -112
- langchain_core/tracers/context.py +29 -48
- langchain_core/tracers/core.py +142 -105
- langchain_core/tracers/evaluation.py +30 -34
- langchain_core/tracers/event_stream.py +162 -117
- langchain_core/tracers/langchain.py +34 -36
- langchain_core/tracers/log_stream.py +87 -49
- langchain_core/tracers/memory_stream.py +3 -3
- langchain_core/tracers/root_listeners.py +18 -34
- langchain_core/tracers/run_collector.py +8 -20
- langchain_core/tracers/schemas.py +0 -125
- langchain_core/tracers/stdout.py +3 -3
- langchain_core/utils/__init__.py +1 -4
- langchain_core/utils/_merge.py +47 -9
- langchain_core/utils/aiter.py +70 -66
- langchain_core/utils/env.py +12 -9
- langchain_core/utils/function_calling.py +139 -206
- langchain_core/utils/html.py +7 -8
- langchain_core/utils/input.py +6 -6
- langchain_core/utils/interactive_env.py +6 -2
- langchain_core/utils/iter.py +48 -45
- langchain_core/utils/json.py +14 -4
- langchain_core/utils/json_schema.py +159 -43
- langchain_core/utils/mustache.py +32 -25
- langchain_core/utils/pydantic.py +67 -40
- langchain_core/utils/strings.py +5 -5
- langchain_core/utils/usage.py +1 -1
- langchain_core/utils/utils.py +104 -62
- langchain_core/vectorstores/base.py +131 -179
- langchain_core/vectorstores/in_memory.py +113 -182
- langchain_core/vectorstores/utils.py +23 -17
- langchain_core/version.py +1 -1
- langchain_core-1.0.0.dist-info/METADATA +68 -0
- langchain_core-1.0.0.dist-info/RECORD +172 -0
- {langchain_core-0.4.0.dev0.dist-info → langchain_core-1.0.0.dist-info}/WHEEL +1 -1
- langchain_core/beta/__init__.py +0 -1
- langchain_core/beta/runnables/__init__.py +0 -1
- langchain_core/beta/runnables/context.py +0 -448
- langchain_core/memory.py +0 -116
- langchain_core/messages/content_blocks.py +0 -1435
- langchain_core/prompts/pipeline.py +0 -133
- langchain_core/pydantic_v1/__init__.py +0 -30
- langchain_core/pydantic_v1/dataclasses.py +0 -23
- langchain_core/pydantic_v1/main.py +0 -23
- langchain_core/tracers/langchain_v1.py +0 -23
- langchain_core/utils/loading.py +0 -31
- langchain_core/v1/__init__.py +0 -1
- langchain_core/v1/chat_models.py +0 -1047
- langchain_core/v1/messages.py +0 -755
- langchain_core-0.4.0.dev0.dist-info/METADATA +0 -108
- langchain_core-0.4.0.dev0.dist-info/RECORD +0 -177
- langchain_core-0.4.0.dev0.dist-info/entry_points.txt +0 -4
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
langchain_core/__init__.py,sha256=5oThb0zpZmmoQFL0jqYB3GgBrXAJUSj5ZJ2GwVnR7IQ,711
|
|
2
|
+
langchain_core/_import_utils.py,sha256=PdYzgXd1wraCcECcMvJQpthmN3i__5h7mYVmFyLpq_s,1423
|
|
3
|
+
langchain_core/agents.py,sha256=JlE3h3Onyj5iRwh0m38HuzDreggjlRon7y6MXaxJeuY,8451
|
|
4
|
+
langchain_core/caches.py,sha256=S2B53WClWb7pINBNtttp35IUs8m8ltKOIIFxsXfPnLE,9591
|
|
5
|
+
langchain_core/chat_history.py,sha256=VIa4XUyd_G9EiIQZRNexJHp-ylouQYjMAuFmpETar8c,8468
|
|
6
|
+
langchain_core/chat_loaders.py,sha256=b57Gl3KGPxq9gYJjetsHfJm1I6kSqi7bDE91fJJOR84,601
|
|
7
|
+
langchain_core/chat_sessions.py,sha256=YEO3ck5_wRGd3a2EnGD7M_wTvNC_4T1IVjQWekagwaM,564
|
|
8
|
+
langchain_core/env.py,sha256=RHExSWJ2bW-6Wxb6UyBGxU5flLoNYOAeslZ9iTjomQE,598
|
|
9
|
+
langchain_core/exceptions.py,sha256=S5DwOEsjCRsb0JscycLwvgSrEABVcpH1rKIKhn27hUI,3226
|
|
10
|
+
langchain_core/globals.py,sha256=jO27FstGK1cyzNT096GD9lFq2YgNxY1DZ6NtA_yKdR8,1852
|
|
11
|
+
langchain_core/prompt_values.py,sha256=cTN71it1u22mg6QxN_R_SkLdgCLM5ruyVhvjmlP6hLM,4087
|
|
12
|
+
langchain_core/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
+
langchain_core/rate_limiters.py,sha256=_4yijdFLvg0Qw7gNvXcKsystymJrgS76vUwRIgVSnjY,9379
|
|
14
|
+
langchain_core/retrievers.py,sha256=2RQnv4-4q0hhhWePp87CTmUYB5ZGR5NJeusK8yP5WaI,10995
|
|
15
|
+
langchain_core/stores.py,sha256=AGZVNo_QATcTRiih24WZ76e1L8Sa861-7umGCbS95mw,9237
|
|
16
|
+
langchain_core/structured_query.py,sha256=mat7BKovKjckzMn3-I1El49yeGjg3cqk4ptpJHAPA-4,5123
|
|
17
|
+
langchain_core/sys_info.py,sha256=7BEle6I6WQIXNcNFGM6RxF9wNMVysjLpdlNACBC4CrA,3803
|
|
18
|
+
langchain_core/version.py,sha256=tjsyboL6g9dNiIkV4lGydJnD3hdkDY1UmDczAhPnOEY,75
|
|
19
|
+
langchain_core/_api/__init__.py,sha256=PYm_j7qRRKh5ca0TTra5UF-nko3ieZZZ5EeAFAinm3o,1973
|
|
20
|
+
langchain_core/_api/beta_decorator.py,sha256=IJgG2_kRb2eBmvHfarDjanJY4k1jwoPJWSOHZ5SLB4U,8664
|
|
21
|
+
langchain_core/_api/deprecation.py,sha256=nReAhxZ1dBwLhHdGAaqqRpf7aLQJ1dw4UtqmrRqeNLE,20296
|
|
22
|
+
langchain_core/_api/internal.py,sha256=aOZkYANu747LyWzyAk-0KE4RjdTYj18Wtlh7F9_qyPM,683
|
|
23
|
+
langchain_core/_api/path.py,sha256=y3dAvsG4JS0BuWErpJ5KhxCykJX2i03kYdeDU-Iup3Y,1349
|
|
24
|
+
langchain_core/callbacks/__init__.py,sha256=8FK0gmkWnbDYWrShBQowg0OK06Hprdim3sxiOla80xk,4225
|
|
25
|
+
langchain_core/callbacks/base.py,sha256=lMf_K7wtS7n3VaUpfHdK1KM4kEdyDE4-MmZHy3YJwak,34123
|
|
26
|
+
langchain_core/callbacks/file.py,sha256=eD1TBPnEzms0amUV_GnNbfLOPF7Et7Z-sCv6fl-7h38,8332
|
|
27
|
+
langchain_core/callbacks/manager.py,sha256=89wK92YUvw5FwvY30kF4UCFlxR2kYFgVAnPb5ZNj2nY,84719
|
|
28
|
+
langchain_core/callbacks/stdout.py,sha256=dy7jTcYFVKpaYesJoakEcAraBLwhjFR5Efjw91EZY8c,3695
|
|
29
|
+
langchain_core/callbacks/streaming_stdout.py,sha256=ylgpp4Bhs5Gv1aNeZWuuC2FU7C3IO7Q9CpEDxCgdFXY,4310
|
|
30
|
+
langchain_core/callbacks/usage.py,sha256=qQHyUeWL-NLwpb9jUTvjLhm0yRJ0Ay5j_hRAsQrCxkk,5051
|
|
31
|
+
langchain_core/document_loaders/__init__.py,sha256=DkZPp9cEVmsnz9SM1xtuefH_fGQFvA2WtpRG6iePPBs,975
|
|
32
|
+
langchain_core/document_loaders/base.py,sha256=niW_Zmkb9H62MqE7xMDj8fVtn1t5_NjeRAJhjwat8oE,4731
|
|
33
|
+
langchain_core/document_loaders/blob_loaders.py,sha256=4m1k8boiwXw3z4yMYT8bnYUA-eGTPtEZyUxZvI3GbTs,1077
|
|
34
|
+
langchain_core/document_loaders/langsmith.py,sha256=iPffW0z8q9sKseHhsjaneQx88E-hXVXJ5UbCAh_iNcU,5300
|
|
35
|
+
langchain_core/documents/__init__.py,sha256=w8LkIJ6Y25-cg1FQjve2ZCO7O_hg3ZidMPXp6ijIHTU,849
|
|
36
|
+
langchain_core/documents/base.py,sha256=pklTi9SwBP8SspA_n-9hr1nmxgH5RuuqMl_0hlmAAAY,10302
|
|
37
|
+
langchain_core/documents/compressor.py,sha256=umDoE70e7Cn32muNKRPXwC5cjML1gEg5XLmRd1DQQqg,1984
|
|
38
|
+
langchain_core/documents/transformers.py,sha256=qIq-zmC9WcW9Ec1Gb_X1tL2o98MqhlVb4V6nLU4siBs,2489
|
|
39
|
+
langchain_core/embeddings/__init__.py,sha256=0SfcdkVSSXmTFXznUyeZq_b1ajpwIGDueGAAfwyMpUY,774
|
|
40
|
+
langchain_core/embeddings/embeddings.py,sha256=u50T2VxLLyfGBCKcVtWfSiZrtKua8sOSHwSSHRKtcno,2405
|
|
41
|
+
langchain_core/embeddings/fake.py,sha256=2XG8CRFk5Kx9KKniWZm2vqBnhvl6J6sLv74AiYToU-0,3864
|
|
42
|
+
langchain_core/example_selectors/__init__.py,sha256=k8y0chtEhaHf8Y1_nZVDsb9CWDdRIWFb9U806mnbGvo,1394
|
|
43
|
+
langchain_core/example_selectors/base.py,sha256=4wRCERHak6Ci5JEKHeidQ_pbBgzQyc-vnQsz2sqBFzA,1716
|
|
44
|
+
langchain_core/example_selectors/length_based.py,sha256=THlN8aPzR59tfwNgGwrC6EtgR4bsOSqh1uK_oycIfpU,3384
|
|
45
|
+
langchain_core/example_selectors/semantic_similarity.py,sha256=gUI7UgiPvsmkcft2S9cWcnId8MOmErVBsGs_3pcGGA8,13549
|
|
46
|
+
langchain_core/indexing/__init__.py,sha256=VOvbbBJYY_UZdMKAeJCdQdszMiAOhAo3Cbht1HEkk8g,1274
|
|
47
|
+
langchain_core/indexing/api.py,sha256=1oWDAZ6NRWbyzM-qy02AAPw4yX4nqgPojElRUAYwqkg,38207
|
|
48
|
+
langchain_core/indexing/base.py,sha256=LWocpVq3Fzar1jec0keTNgPH860mvWOE1YIWra3irX8,22472
|
|
49
|
+
langchain_core/indexing/in_memory.py,sha256=2AbNLZPCIXfSsVwSxEMhqhVbEUcprUVgshnIoRoME5g,3332
|
|
50
|
+
langchain_core/language_models/__init__.py,sha256=nhf1jGPkfXzhE40-bw2aijQCeFvbemzna6bhJJYtX1w,3295
|
|
51
|
+
langchain_core/language_models/_utils.py,sha256=c75LzNP5OEimbTIYpqNYQFy1uyHaLwuKhCJzucl84bE,11028
|
|
52
|
+
langchain_core/language_models/base.py,sha256=VC9kMx2g31qN7Hk7RfKnP3BoiP6MYOVH3Vxdvb_NIo8,10905
|
|
53
|
+
langchain_core/language_models/chat_models.py,sha256=ddBeq_qcaGZSC43XCL4Ci-_aXPSvzE_RFVwWi4GhqMA,70778
|
|
54
|
+
langchain_core/language_models/fake.py,sha256=hb2yU3snYPTueZiJ-0KI0MKHYBNm6zdUw7xe8WqguEY,3732
|
|
55
|
+
langchain_core/language_models/fake_chat_models.py,sha256=C4z4ZCIBRJQ-9mxbhfddTOR9wNGpUi9ccjz1zR1XdvM,13508
|
|
56
|
+
langchain_core/language_models/llms.py,sha256=USnT9W-W7_XwQTq4kDcCzwUHtR_-mQpII4OGEy84AnI,53995
|
|
57
|
+
langchain_core/load/__init__.py,sha256=m3_6Fk2gpYZO0xqyTnZzdQigvsYHjMariLq_L2KwJFk,1150
|
|
58
|
+
langchain_core/load/dump.py,sha256=C7hFKs1OO1fXrZN7pAtIzUv9gS_n5CX5DXbUn0E99go,2631
|
|
59
|
+
langchain_core/load/load.py,sha256=LQJqeERSO5mlqImCDMLXDwmtpvEssVJJi3Iau7qpY4M,9283
|
|
60
|
+
langchain_core/load/mapping.py,sha256=SqBaAWAM2aV_Wgy80DAlS-39tJkHLcCyM45bVVnN12w,29513
|
|
61
|
+
langchain_core/load/serializable.py,sha256=2pU7Uw9Z1mxIxGdyC6nVqEgV2tAcPjjSwP7zDb2D56Q,11680
|
|
62
|
+
langchain_core/messages/__init__.py,sha256=4npkXfwypol9UrDbQXN8kdNKEcimj7NRL628XCVTad4,5483
|
|
63
|
+
langchain_core/messages/ai.py,sha256=VAJbeY6VJXRlos83SbFoMbrNTe4PJvhzeuG5vzeE0lU,27129
|
|
64
|
+
langchain_core/messages/base.py,sha256=zV498foyegSixJG3vc-IlNtYi2jb6-rngrbpKxFMUBk,16255
|
|
65
|
+
langchain_core/messages/chat.py,sha256=t9az-R1De2HdiEhhpGyIFonCqY03UAkqMdvttx11rhM,2204
|
|
66
|
+
langchain_core/messages/content.py,sha256=psf3BJm88O9MebH141Q1UGz_8YaPRdDNLRQXmAip3gs,41921
|
|
67
|
+
langchain_core/messages/function.py,sha256=RlkcFREWGgAlnD0psOOWc2kQa7wVZ-kJBl-mi-UIcdw,2094
|
|
68
|
+
langchain_core/messages/human.py,sha256=Sgx58Kwlb1y_YaeOXavz1D0V2ald_TAdqlC5zQI_Rz4,2130
|
|
69
|
+
langchain_core/messages/modifier.py,sha256=8d3mhHnKMDU9Xkw_M3-uf5WBtqA4dZj81tD7A6Zgo_o,875
|
|
70
|
+
langchain_core/messages/system.py,sha256=x8OBdba68Nt3SiO7aNTaDREq3iDjDV4XyRoqb-ZOmgo,2140
|
|
71
|
+
langchain_core/messages/tool.py,sha256=MMklOAPd2e0OAGxM3Iode_Bm3bC74_icN3HnL2FPCig,12584
|
|
72
|
+
langchain_core/messages/utils.py,sha256=qFFRj5S6VnA9htwabNo8umkfyfXGQTAoZ6-GwFyYxBQ,68697
|
|
73
|
+
langchain_core/messages/block_translators/__init__.py,sha256=_CxgFIR8hrxROFl1dzRNwkL4cgL-TxxpYQBn-26zP4A,4244
|
|
74
|
+
langchain_core/messages/block_translators/anthropic.py,sha256=eN304DgrEFTRl12f4PmU4P8ASTUngMkE7HC9-gpYUGk,19131
|
|
75
|
+
langchain_core/messages/block_translators/bedrock.py,sha256=yLjYwtCsYGHBEj9CSXHCZYLmwsA4F6D6NTT5kE11Bww,3511
|
|
76
|
+
langchain_core/messages/block_translators/bedrock_converse.py,sha256=YN7xfKPbxjVJujOzEuXbDx3QiDql1ldbLCYQ6bgH6FI,11994
|
|
77
|
+
langchain_core/messages/block_translators/google_genai.py,sha256=nW8TLs6wu1Hut6IEw7nK4qEa32lBbNnMDhY65qQTxIw,22155
|
|
78
|
+
langchain_core/messages/block_translators/google_vertexai.py,sha256=2RzpKFKi1991aWGK8osdkKq8bKadmy8q86kR3r0f6K4,632
|
|
79
|
+
langchain_core/messages/block_translators/groq.py,sha256=s7xCVITYV2W3CqZpc3OO7hXQRICLqNi8hyPofT2OvqM,5444
|
|
80
|
+
langchain_core/messages/block_translators/langchain_v0.py,sha256=WAoQGt1qZ5rVZD5n1A1z0dR-DpN6vgrn-gSII1CxhCA,11658
|
|
81
|
+
langchain_core/messages/block_translators/openai.py,sha256=YAb6lgCJvFYZg5tjhQbN-VmHyBJSnJgFTE5JO2k9ht4,39261
|
|
82
|
+
langchain_core/output_parsers/__init__.py,sha256=2S_EWMfq9WPSRQfelmsV6UifZEaQR6SPGr-sFP_MT9k,2629
|
|
83
|
+
langchain_core/output_parsers/base.py,sha256=neBb5nMHmpiS3GJUtVYMCSh2NXJvo_C8BEn1mQp_tMY,11108
|
|
84
|
+
langchain_core/output_parsers/format_instructions.py,sha256=8oUbeysnVGvXWyNd5gqXlEL850D31gMTy74GflsuvRU,553
|
|
85
|
+
langchain_core/output_parsers/json.py,sha256=KLPfGJdeddbiTv1ex2iA_q4N4VO5HeZCeELVKPh9sAM,4532
|
|
86
|
+
langchain_core/output_parsers/list.py,sha256=c6pnP1CF3tN1W6n8-JfP2NnMYmj9lAmPGIBK9H3sfJk,7259
|
|
87
|
+
langchain_core/output_parsers/openai_functions.py,sha256=4tyd1riGCOjEOftIsMT1jbrXNv1HWrcGhHEg-K1M4Tw,10597
|
|
88
|
+
langchain_core/output_parsers/openai_tools.py,sha256=_HmltJmaA9-RFllA-viLVUVGbXKavS6OOHEMM6hF1To,12372
|
|
89
|
+
langchain_core/output_parsers/pydantic.py,sha256=oi9qRawZbyW2U_Kg7QSE26TBSjfApz5UQeI6odEwNsI,4446
|
|
90
|
+
langchain_core/output_parsers/string.py,sha256=zwwSa8LjwxnmboUHXybmhb1dX5jpZ9zPNt96ggFIc8I,963
|
|
91
|
+
langchain_core/output_parsers/transform.py,sha256=FyYvkS1KnAHX9afF1qqdJbUBa_xUyDTvspPQBq8G5uM,5835
|
|
92
|
+
langchain_core/output_parsers/xml.py,sha256=65MwScRiyULkK3rfuqJespGHpl5XRIMNREUNofAzLnQ,10897
|
|
93
|
+
langchain_core/outputs/__init__.py,sha256=CLL4IYb-N18gSXLscJVNWDL2LapGieXJF5EhG8uQSvE,2115
|
|
94
|
+
langchain_core/outputs/chat_generation.py,sha256=sD-wCAFWuzADKM7swf9EEaNJmRsEAfZT6tLi00UfPDY,4733
|
|
95
|
+
langchain_core/outputs/chat_result.py,sha256=ZXLGUtb5xqJdoCtAX1XeiJf20ELx6gui7DUHH0rKnv8,1324
|
|
96
|
+
langchain_core/outputs/generation.py,sha256=Ysg7SD6s-vWKG1dWHnMoPlxipCGOv0IvYcN4CB8Le6Y,2621
|
|
97
|
+
langchain_core/outputs/llm_result.py,sha256=srdoHk-Vk2Xh40XMYAgfsFwGFmvyk2NOkUkvb6U_xZ8,3894
|
|
98
|
+
langchain_core/outputs/run_info.py,sha256=xCMWdsHfgnnodaf4OCMvZaWUfS836X7mV15JPkqvZjo,594
|
|
99
|
+
langchain_core/prompts/__init__.py,sha256=gXRJkxl6z7AYTGyyQAF0DQYpbwCUvfCFwXFfhSekzDw,3033
|
|
100
|
+
langchain_core/prompts/base.py,sha256=uavI9hF4fisZKTClOeD-02Nk2-K_p_pxBSCgQttuWoU,15747
|
|
101
|
+
langchain_core/prompts/chat.py,sha256=YQjECPvvipkdzTGPRPScYTc7V9HMlk6HNVRVScVgZYQ,50045
|
|
102
|
+
langchain_core/prompts/dict.py,sha256=eaY3v6D_Du8DMFsqwYnQThwJ-zsPnfbyk9Wxvvc4rt8,4698
|
|
103
|
+
langchain_core/prompts/few_shot.py,sha256=FaVMuen4eG0B-lnSr2-jGC_JMOhYoK1tfG-pJgYfcmg,15794
|
|
104
|
+
langchain_core/prompts/few_shot_with_templates.py,sha256=aKDMxKFmmK8mzAP6I35vpxQUApLs-9AGKCgNcYK9GlA,7804
|
|
105
|
+
langchain_core/prompts/image.py,sha256=L_5yGsI68Y0pwthA3AS0mQXFMXtvW_kBRItFS6Vpk14,4780
|
|
106
|
+
langchain_core/prompts/loading.py,sha256=hvNsDvqLz5wJA1EywW2wCwKUhJgUzNcIKfp5VEVOEGc,6889
|
|
107
|
+
langchain_core/prompts/message.py,sha256=gyiAKRfgXqgXqaeEXO0zFlt5Ote2T52npyaI1O5hhXE,2603
|
|
108
|
+
langchain_core/prompts/prompt.py,sha256=TcQZNc-Y6c7CMJwY1HwMvRYU4NcbMdCw6YS37Tc3pWk,10948
|
|
109
|
+
langchain_core/prompts/string.py,sha256=mgJ52ddTR5GiBIGy3ea4LBshhMLe3jnvejHuzecV6ZA,10854
|
|
110
|
+
langchain_core/prompts/structured.py,sha256=67-pReMLW8asyFpua8bHz5UsnK5KnM2yaqAxJGsR0uQ,5728
|
|
111
|
+
langchain_core/runnables/__init__.py,sha256=efTnFjwN_QSAv5ThLmKuWeu8P1BLARH-cWKZBuimfDM,3858
|
|
112
|
+
langchain_core/runnables/base.py,sha256=3XV_kXnEsmMr2nDHBQbjl-850CmcgeeboqT--T-8K2M,215861
|
|
113
|
+
langchain_core/runnables/branch.py,sha256=Q8KlP1cfUvU0JKoW1GwBpWZX12sseOxFdU9MMJfyjj4,15668
|
|
114
|
+
langchain_core/runnables/config.py,sha256=w2f2BeYbiXIuXxYJCrmSDIh7LgwSyF-7p92W-sxrbKU,19103
|
|
115
|
+
langchain_core/runnables/configurable.py,sha256=reO2SoYe-3QxLkRUPf3Iu8eFL9gmmf-E05uqc-i6G-Y,23972
|
|
116
|
+
langchain_core/runnables/fallbacks.py,sha256=RsVAZuXleO56cLCStmvPysXzqnG_MYzQPT-ZtCvWFnY,24432
|
|
117
|
+
langchain_core/runnables/graph.py,sha256=WG-VKPKYETY_xtTI2x_eM03eD80O6LmMOU_DDqRyLIY,22946
|
|
118
|
+
langchain_core/runnables/graph_ascii.py,sha256=le9njNqnDYtu1znTWGIyZYstEaiYuxBk9Qx8r7yfoXc,10328
|
|
119
|
+
langchain_core/runnables/graph_mermaid.py,sha256=Mw5r4QWjConm-I2OYACMUZIc7qiEBXesLjsuCH4HYpg,16650
|
|
120
|
+
langchain_core/runnables/graph_png.py,sha256=RM2sjhNWuBDxO7mSJvUOXiFHw06CmJ_s0puF7T6uKWk,5454
|
|
121
|
+
langchain_core/runnables/history.py,sha256=ru_0ni55HQ4Fl7aFGcCFt93vkeQHLRsbjt9eKnf8RdQ,24181
|
|
122
|
+
langchain_core/runnables/passthrough.py,sha256=ZXQJLQOQsl6uLSdOKAxBcvJjuDfzdHDrgLaiskL3jbw,25700
|
|
123
|
+
langchain_core/runnables/retry.py,sha256=eG2LUH0cgIzH7Xe7aVbdYww-04f_o74GRd1VxTocjjU,13682
|
|
124
|
+
langchain_core/runnables/router.py,sha256=Ec50ZKHxWlM3kNED6JXkbezEHxTgi3BzEsn6BIZTdho,7114
|
|
125
|
+
langchain_core/runnables/schema.py,sha256=ZrOSx7ErI0e2SgEMkL1k3Y8esFAd6AniBt8bhTMyR0o,5764
|
|
126
|
+
langchain_core/runnables/utils.py,sha256=p_QDnwJ7XcO7bl-QBdoSksNJixeMlYcr41ZAPmZTMiU,22176
|
|
127
|
+
langchain_core/tools/__init__.py,sha256=qe2E9VwZ7hpdkToz96oSJ080a0de9oQwSO9FP1XnmM0,2518
|
|
128
|
+
langchain_core/tools/base.py,sha256=axOOM3G3R3W_xuMV9tw6wrspRJVT25XP7z-tOkHeZcw,49595
|
|
129
|
+
langchain_core/tools/convert.py,sha256=RlEMCD6YEkp_ArO2uMbDryBJDJcERAL2uWfh8qprI3I,15725
|
|
130
|
+
langchain_core/tools/render.py,sha256=gD3pXYWjCaDKsYq_MZ-yCRXl1wUJbOh6dJobda9VjYM,1817
|
|
131
|
+
langchain_core/tools/retriever.py,sha256=6Ogox8pBMFEvXG6Kz-9fWQQXRuMX5NlJiFwKi2Ph97s,3790
|
|
132
|
+
langchain_core/tools/simple.py,sha256=U9R5jIUcZMXKMV5Ezu8G2MX_0ot2nrtvhjgaGHkA53o,6623
|
|
133
|
+
langchain_core/tools/structured.py,sha256=koCZXjPBn9w2wtaur1c3R3uGszxbuTLhUpTVC-rrZRo,9188
|
|
134
|
+
langchain_core/tracers/__init__.py,sha256=Yf0CQ-IcBa8f9lu0wMA_looT6Q8we3C0yd-xMP3c0Sc,1362
|
|
135
|
+
langchain_core/tracers/_streaming.py,sha256=U9pWQDJNUDH4oOYF3zvUMUtgkCecJzXQvfo-wYARmhQ,982
|
|
136
|
+
langchain_core/tracers/base.py,sha256=cywwNDlynmidmhOCQ8A1J0qhnvN_orWNB8z2UjvCEGs,25454
|
|
137
|
+
langchain_core/tracers/context.py,sha256=-7pbOA3QR0OIeehpD9eMpqugGgwLc_XxMjVQRg8GAJI,6194
|
|
138
|
+
langchain_core/tracers/core.py,sha256=doyEB6enQVeGYFbC5EmC_gVGq6tcZQpYXm4bXVaI11c,23306
|
|
139
|
+
langchain_core/tracers/evaluation.py,sha256=XmoPqBNFg6H-9K46fWanABAEVUgbob9S7qU-DPcL4RM,8367
|
|
140
|
+
langchain_core/tracers/event_stream.py,sha256=bzsu65tlXntEw2tfzSFDpbYVd638RkSBX59V4VoaZLQ,34966
|
|
141
|
+
langchain_core/tracers/langchain.py,sha256=juy0i7aryBuqWuML9EiNrAI6SAv2qllt5hAE6mC_0HQ,10477
|
|
142
|
+
langchain_core/tracers/log_stream.py,sha256=4nd6Lb6chPCdOFwPmHCv1S_jQOqlRivNqJikNKYPGis,25425
|
|
143
|
+
langchain_core/tracers/memory_stream.py,sha256=4bPh6Fhoq84Ul03wIasEju34GHKXj_c9xTIm6nAFG-8,4995
|
|
144
|
+
langchain_core/tracers/root_listeners.py,sha256=6ZE56m7zyVzMXtUPztifkX409rdaXTXZcJIYlS69xls,4097
|
|
145
|
+
langchain_core/tracers/run_collector.py,sha256=Uy8lwFLDgMtLmzIi9RlBY-xXs9NRQoNSNekluuZzqxI,1265
|
|
146
|
+
langchain_core/tracers/schemas.py,sha256=-B159J_A1pLdmN6GLR3yM2S_KozJWawKaFc7vI2xXaU,191
|
|
147
|
+
langchain_core/tracers/stdout.py,sha256=E8TXpAiKJeLf8hnnBLUie0dINY8V2d7iPyGu5O0OwYg,6715
|
|
148
|
+
langchain_core/utils/__init__.py,sha256=yn6ZGHMxi7MjqojSBkT2sCxYRpo76zAIBcKnTRaJ2Pc,3041
|
|
149
|
+
langchain_core/utils/_merge.py,sha256=9wTZdkuG45azGBze7OZFFIoCiidHi3roe6TQiQ5bcV0,7536
|
|
150
|
+
langchain_core/utils/aiter.py,sha256=gfFyGWro42FB4R66_tWSyW8XrLLzV7EI9EmLvI8dFGI,10574
|
|
151
|
+
langchain_core/utils/env.py,sha256=pQTqZLCjcueoxTd8epc3cr0lRn8njJf_A-bOQfHWPXw,2458
|
|
152
|
+
langchain_core/utils/formatting.py,sha256=fkieArzKXxSsLcEa3B-MX60O4ZLeeLjiPtVtxCJPcOU,1480
|
|
153
|
+
langchain_core/utils/function_calling.py,sha256=ZwjzsIZ2HLq0MiIQp6IhQr_RkWSZx9e-VGJjE3Ukof4,26999
|
|
154
|
+
langchain_core/utils/html.py,sha256=ReIdqTTC8r-AfsqynFjCIaFC9t9sI_vYnmz3DanpVqQ,3714
|
|
155
|
+
langchain_core/utils/image.py,sha256=1MH8Lbg0f2HfhTC4zobKMvpVoHRfpsyvWHq9ae4xENo,532
|
|
156
|
+
langchain_core/utils/input.py,sha256=Ruhzw4kjldit5aTsvsm_tgrcrpVaTnwq976lUn0G2_U,1887
|
|
157
|
+
langchain_core/utils/interactive_env.py,sha256=LBgNICNAwgwDMOdlVD12TtZfSboPOKXaBS2Jn-bsXQ8,289
|
|
158
|
+
langchain_core/utils/iter.py,sha256=jqtyfA2129a5ftfuRovpUBEslCGaeuiiGr8bkT-iozI,7300
|
|
159
|
+
langchain_core/utils/json.py,sha256=Jsa-EuPLj5sSYDOAIzM7g1-7gsgfXgCs8KLNQ3x1-O4,6533
|
|
160
|
+
langchain_core/utils/json_schema.py,sha256=_hgV2Gzs1FkkFqLwqIPZcmN4DFyqm6PICYIM8Bjkqm4,9068
|
|
161
|
+
langchain_core/utils/mustache.py,sha256=2LgatBIOa1bGU4EaL5xrS076NWqfQkB4Mtencmc3mtQ,21262
|
|
162
|
+
langchain_core/utils/pydantic.py,sha256=Lu5Hu7tbMJpAEn4JHqPX2DstI3QMvnH4jRbjq3K283s,18510
|
|
163
|
+
langchain_core/utils/strings.py,sha256=eD9G_u92ZlVTDBp8MmV7guCSShevJcValgH-_8ozQ9I,1758
|
|
164
|
+
langchain_core/utils/usage.py,sha256=vB674Eu69xDGx6JBJlySp6cnePkxCD0Wz26mi502NAM,1211
|
|
165
|
+
langchain_core/utils/utils.py,sha256=Kfpl83xT1j64RUODMZ0FtG68OzRm6lvNqAs9_TNkoTk,15756
|
|
166
|
+
langchain_core/vectorstores/__init__.py,sha256=5P0eoeoH5LHab64JjmEeWa6SxX4eMy-etAP1MEHsETY,804
|
|
167
|
+
langchain_core/vectorstores/base.py,sha256=Nce-RPbBZvqt8Aqcy5rDcXCk4Wa0u798jv7FNq4L2W8,40614
|
|
168
|
+
langchain_core/vectorstores/in_memory.py,sha256=tYjAn4bARPvdlNv5jxnZwOEA7iySHmZcxatHnoz1x44,15715
|
|
169
|
+
langchain_core/vectorstores/utils.py,sha256=XXpQ2mxado6vrLmZWVTstcxrurBtoHcBZEORITAHWw0,4931
|
|
170
|
+
langchain_core-1.0.0.dist-info/METADATA,sha256=9b-TdQe6daMlOujBjaLHAldy4i7nj3umELcEM7RcepE,3399
|
|
171
|
+
langchain_core-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
172
|
+
langchain_core-1.0.0.dist-info/RECORD,,
|
langchain_core/beta/__init__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"""Some **beta** features that are not yet ready for production."""
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"""Runnables."""
|
|
@@ -1,448 +0,0 @@
|
|
|
1
|
-
"""Context management for runnables."""
|
|
2
|
-
|
|
3
|
-
import asyncio
|
|
4
|
-
import threading
|
|
5
|
-
from collections import defaultdict
|
|
6
|
-
from collections.abc import Awaitable, Mapping, Sequence
|
|
7
|
-
from functools import partial
|
|
8
|
-
from itertools import groupby
|
|
9
|
-
from typing import (
|
|
10
|
-
Any,
|
|
11
|
-
Callable,
|
|
12
|
-
Optional,
|
|
13
|
-
TypeVar,
|
|
14
|
-
Union,
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
from pydantic import ConfigDict
|
|
18
|
-
from typing_extensions import override
|
|
19
|
-
|
|
20
|
-
from langchain_core._api.beta_decorator import beta
|
|
21
|
-
from langchain_core.runnables.base import (
|
|
22
|
-
Runnable,
|
|
23
|
-
RunnableSerializable,
|
|
24
|
-
coerce_to_runnable,
|
|
25
|
-
)
|
|
26
|
-
from langchain_core.runnables.config import RunnableConfig, ensure_config, patch_config
|
|
27
|
-
from langchain_core.runnables.utils import ConfigurableFieldSpec, Input, Output
|
|
28
|
-
|
|
29
|
-
T = TypeVar("T")
|
|
30
|
-
Values = dict[Union[asyncio.Event, threading.Event], Any]
|
|
31
|
-
CONTEXT_CONFIG_PREFIX = "__context__/"
|
|
32
|
-
CONTEXT_CONFIG_SUFFIX_GET = "/get"
|
|
33
|
-
CONTEXT_CONFIG_SUFFIX_SET = "/set"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
async def _asetter(done: asyncio.Event, values: Values, value: T) -> T:
|
|
37
|
-
values[done] = value
|
|
38
|
-
done.set()
|
|
39
|
-
return value
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
async def _agetter(done: asyncio.Event, values: Values) -> Any:
|
|
43
|
-
await done.wait()
|
|
44
|
-
return values[done]
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
def _setter(done: threading.Event, values: Values, value: T) -> T:
|
|
48
|
-
values[done] = value
|
|
49
|
-
done.set()
|
|
50
|
-
return value
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def _getter(done: threading.Event, values: Values) -> Any:
|
|
54
|
-
done.wait()
|
|
55
|
-
return values[done]
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def _key_from_id(id_: str) -> str:
|
|
59
|
-
wout_prefix = id_.split(CONTEXT_CONFIG_PREFIX, maxsplit=1)[1]
|
|
60
|
-
if wout_prefix.endswith(CONTEXT_CONFIG_SUFFIX_GET):
|
|
61
|
-
return wout_prefix[: -len(CONTEXT_CONFIG_SUFFIX_GET)]
|
|
62
|
-
if wout_prefix.endswith(CONTEXT_CONFIG_SUFFIX_SET):
|
|
63
|
-
return wout_prefix[: -len(CONTEXT_CONFIG_SUFFIX_SET)]
|
|
64
|
-
msg = f"Invalid context config id {id_}"
|
|
65
|
-
raise ValueError(msg)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def _config_with_context(
|
|
69
|
-
config: RunnableConfig,
|
|
70
|
-
steps: list[Runnable],
|
|
71
|
-
setter: Callable,
|
|
72
|
-
getter: Callable,
|
|
73
|
-
event_cls: Union[type[threading.Event], type[asyncio.Event]],
|
|
74
|
-
) -> RunnableConfig:
|
|
75
|
-
if any(k.startswith(CONTEXT_CONFIG_PREFIX) for k in config.get("configurable", {})):
|
|
76
|
-
return config
|
|
77
|
-
|
|
78
|
-
context_specs = [
|
|
79
|
-
(spec, i)
|
|
80
|
-
for i, step in enumerate(steps)
|
|
81
|
-
for spec in step.config_specs
|
|
82
|
-
if spec.id.startswith(CONTEXT_CONFIG_PREFIX)
|
|
83
|
-
]
|
|
84
|
-
grouped_by_key = {
|
|
85
|
-
key: list(group)
|
|
86
|
-
for key, group in groupby(
|
|
87
|
-
sorted(context_specs, key=lambda s: s[0].id),
|
|
88
|
-
key=lambda s: _key_from_id(s[0].id),
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
deps_by_key = {
|
|
92
|
-
key: {
|
|
93
|
-
_key_from_id(dep) for spec in group for dep in (spec[0].dependencies or [])
|
|
94
|
-
}
|
|
95
|
-
for key, group in grouped_by_key.items()
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
values: Values = {}
|
|
99
|
-
events: defaultdict[str, Union[asyncio.Event, threading.Event]] = defaultdict(
|
|
100
|
-
event_cls
|
|
101
|
-
)
|
|
102
|
-
context_funcs: dict[str, Callable[[], Any]] = {}
|
|
103
|
-
for key, group in grouped_by_key.items():
|
|
104
|
-
getters = [s for s in group if s[0].id.endswith(CONTEXT_CONFIG_SUFFIX_GET)]
|
|
105
|
-
setters = [s for s in group if s[0].id.endswith(CONTEXT_CONFIG_SUFFIX_SET)]
|
|
106
|
-
|
|
107
|
-
for dep in deps_by_key[key]:
|
|
108
|
-
if key in deps_by_key[dep]:
|
|
109
|
-
msg = f"Deadlock detected between context keys {key} and {dep}"
|
|
110
|
-
raise ValueError(msg)
|
|
111
|
-
if len(setters) != 1:
|
|
112
|
-
msg = f"Expected exactly one setter for context key {key}"
|
|
113
|
-
raise ValueError(msg)
|
|
114
|
-
setter_idx = setters[0][1]
|
|
115
|
-
if any(getter_idx < setter_idx for _, getter_idx in getters):
|
|
116
|
-
msg = f"Context setter for key {key} must be defined after all getters."
|
|
117
|
-
raise ValueError(msg)
|
|
118
|
-
|
|
119
|
-
if getters:
|
|
120
|
-
context_funcs[getters[0][0].id] = partial(getter, events[key], values)
|
|
121
|
-
context_funcs[setters[0][0].id] = partial(setter, events[key], values)
|
|
122
|
-
|
|
123
|
-
return patch_config(config, configurable=context_funcs)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
def aconfig_with_context(
|
|
127
|
-
config: RunnableConfig,
|
|
128
|
-
steps: list[Runnable],
|
|
129
|
-
) -> RunnableConfig:
|
|
130
|
-
"""Asynchronously patch a runnable config with context getters and setters.
|
|
131
|
-
|
|
132
|
-
Args:
|
|
133
|
-
config: The runnable config.
|
|
134
|
-
steps: The runnable steps.
|
|
135
|
-
|
|
136
|
-
Returns:
|
|
137
|
-
The patched runnable config.
|
|
138
|
-
"""
|
|
139
|
-
return _config_with_context(config, steps, _asetter, _agetter, asyncio.Event)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
def config_with_context(
|
|
143
|
-
config: RunnableConfig,
|
|
144
|
-
steps: list[Runnable],
|
|
145
|
-
) -> RunnableConfig:
|
|
146
|
-
"""Patch a runnable config with context getters and setters.
|
|
147
|
-
|
|
148
|
-
Args:
|
|
149
|
-
config: The runnable config.
|
|
150
|
-
steps: The runnable steps.
|
|
151
|
-
|
|
152
|
-
Returns:
|
|
153
|
-
The patched runnable config.
|
|
154
|
-
"""
|
|
155
|
-
return _config_with_context(config, steps, _setter, _getter, threading.Event)
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
@beta()
|
|
159
|
-
class ContextGet(RunnableSerializable):
|
|
160
|
-
"""Get a context value."""
|
|
161
|
-
|
|
162
|
-
prefix: str = ""
|
|
163
|
-
|
|
164
|
-
key: Union[str, list[str]]
|
|
165
|
-
|
|
166
|
-
@override
|
|
167
|
-
def __str__(self) -> str:
|
|
168
|
-
return f"ContextGet({_print_keys(self.key)})"
|
|
169
|
-
|
|
170
|
-
@property
|
|
171
|
-
def ids(self) -> list[str]:
|
|
172
|
-
"""The context getter ids."""
|
|
173
|
-
prefix = self.prefix + "/" if self.prefix else ""
|
|
174
|
-
keys = self.key if isinstance(self.key, list) else [self.key]
|
|
175
|
-
return [
|
|
176
|
-
f"{CONTEXT_CONFIG_PREFIX}{prefix}{k}{CONTEXT_CONFIG_SUFFIX_GET}"
|
|
177
|
-
for k in keys
|
|
178
|
-
]
|
|
179
|
-
|
|
180
|
-
@property
|
|
181
|
-
@override
|
|
182
|
-
def config_specs(self) -> list[ConfigurableFieldSpec]:
|
|
183
|
-
return super().config_specs + [
|
|
184
|
-
ConfigurableFieldSpec(
|
|
185
|
-
id=id_,
|
|
186
|
-
annotation=Callable[[], Any],
|
|
187
|
-
)
|
|
188
|
-
for id_ in self.ids
|
|
189
|
-
]
|
|
190
|
-
|
|
191
|
-
@override
|
|
192
|
-
def invoke(
|
|
193
|
-
self, input: Any, config: Optional[RunnableConfig] = None, **kwargs: Any
|
|
194
|
-
) -> Any:
|
|
195
|
-
config = ensure_config(config)
|
|
196
|
-
configurable = config.get("configurable", {})
|
|
197
|
-
if isinstance(self.key, list):
|
|
198
|
-
return {key: configurable[id_]() for key, id_ in zip(self.key, self.ids)}
|
|
199
|
-
return configurable[self.ids[0]]()
|
|
200
|
-
|
|
201
|
-
@override
|
|
202
|
-
async def ainvoke(
|
|
203
|
-
self, input: Any, config: Optional[RunnableConfig] = None, **kwargs: Any
|
|
204
|
-
) -> Any:
|
|
205
|
-
config = ensure_config(config)
|
|
206
|
-
configurable = config.get("configurable", {})
|
|
207
|
-
if isinstance(self.key, list):
|
|
208
|
-
values = await asyncio.gather(*(configurable[id_]() for id_ in self.ids))
|
|
209
|
-
return dict(zip(self.key, values))
|
|
210
|
-
return await configurable[self.ids[0]]()
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
SetValue = Union[
|
|
214
|
-
Runnable[Input, Output],
|
|
215
|
-
Callable[[Input], Output],
|
|
216
|
-
Callable[[Input], Awaitable[Output]],
|
|
217
|
-
Any,
|
|
218
|
-
]
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
def _coerce_set_value(value: SetValue) -> Runnable[Input, Output]:
|
|
222
|
-
if not isinstance(value, Runnable) and not callable(value):
|
|
223
|
-
return coerce_to_runnable(lambda _: value)
|
|
224
|
-
return coerce_to_runnable(value)
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
@beta()
|
|
228
|
-
class ContextSet(RunnableSerializable):
|
|
229
|
-
"""Set a context value."""
|
|
230
|
-
|
|
231
|
-
prefix: str = ""
|
|
232
|
-
|
|
233
|
-
keys: Mapping[str, Optional[Runnable]]
|
|
234
|
-
|
|
235
|
-
model_config = ConfigDict(
|
|
236
|
-
arbitrary_types_allowed=True,
|
|
237
|
-
)
|
|
238
|
-
|
|
239
|
-
def __init__(
|
|
240
|
-
self,
|
|
241
|
-
key: Optional[str] = None,
|
|
242
|
-
value: Optional[SetValue] = None,
|
|
243
|
-
prefix: str = "",
|
|
244
|
-
**kwargs: SetValue,
|
|
245
|
-
):
|
|
246
|
-
"""Create a context setter.
|
|
247
|
-
|
|
248
|
-
Args:
|
|
249
|
-
key: The context setter key.
|
|
250
|
-
value: The context setter value.
|
|
251
|
-
prefix: The context setter prefix.
|
|
252
|
-
**kwargs: Additional context setter key-value pairs.
|
|
253
|
-
"""
|
|
254
|
-
if key is not None:
|
|
255
|
-
kwargs[key] = value
|
|
256
|
-
super().__init__( # type: ignore[call-arg]
|
|
257
|
-
keys={
|
|
258
|
-
k: _coerce_set_value(v) if v is not None else None
|
|
259
|
-
for k, v in kwargs.items()
|
|
260
|
-
},
|
|
261
|
-
prefix=prefix,
|
|
262
|
-
)
|
|
263
|
-
|
|
264
|
-
@override
|
|
265
|
-
def __str__(self) -> str:
|
|
266
|
-
return f"ContextSet({_print_keys(list(self.keys.keys()))})"
|
|
267
|
-
|
|
268
|
-
@property
|
|
269
|
-
def ids(self) -> list[str]:
|
|
270
|
-
"""The context setter ids."""
|
|
271
|
-
prefix = self.prefix + "/" if self.prefix else ""
|
|
272
|
-
return [
|
|
273
|
-
f"{CONTEXT_CONFIG_PREFIX}{prefix}{key}{CONTEXT_CONFIG_SUFFIX_SET}"
|
|
274
|
-
for key in self.keys
|
|
275
|
-
]
|
|
276
|
-
|
|
277
|
-
@property
|
|
278
|
-
@override
|
|
279
|
-
def config_specs(self) -> list[ConfigurableFieldSpec]:
|
|
280
|
-
mapper_config_specs = [
|
|
281
|
-
s
|
|
282
|
-
for mapper in self.keys.values()
|
|
283
|
-
if mapper is not None
|
|
284
|
-
for s in mapper.config_specs
|
|
285
|
-
]
|
|
286
|
-
for spec in mapper_config_specs:
|
|
287
|
-
if spec.id.endswith(CONTEXT_CONFIG_SUFFIX_GET):
|
|
288
|
-
getter_key = spec.id.split("/")[1]
|
|
289
|
-
if getter_key in self.keys:
|
|
290
|
-
msg = f"Circular reference in context setter for key {getter_key}"
|
|
291
|
-
raise ValueError(msg)
|
|
292
|
-
return super().config_specs + [
|
|
293
|
-
ConfigurableFieldSpec(
|
|
294
|
-
id=id_,
|
|
295
|
-
annotation=Callable[[], Any],
|
|
296
|
-
)
|
|
297
|
-
for id_ in self.ids
|
|
298
|
-
]
|
|
299
|
-
|
|
300
|
-
@override
|
|
301
|
-
def invoke(
|
|
302
|
-
self, input: Any, config: Optional[RunnableConfig] = None, **kwargs: Any
|
|
303
|
-
) -> Any:
|
|
304
|
-
config = ensure_config(config)
|
|
305
|
-
configurable = config.get("configurable", {})
|
|
306
|
-
for id_, mapper in zip(self.ids, self.keys.values()):
|
|
307
|
-
if mapper is not None:
|
|
308
|
-
configurable[id_](mapper.invoke(input, config))
|
|
309
|
-
else:
|
|
310
|
-
configurable[id_](input)
|
|
311
|
-
return input
|
|
312
|
-
|
|
313
|
-
@override
|
|
314
|
-
async def ainvoke(
|
|
315
|
-
self, input: Any, config: Optional[RunnableConfig] = None, **kwargs: Any
|
|
316
|
-
) -> Any:
|
|
317
|
-
config = ensure_config(config)
|
|
318
|
-
configurable = config.get("configurable", {})
|
|
319
|
-
for id_, mapper in zip(self.ids, self.keys.values()):
|
|
320
|
-
if mapper is not None:
|
|
321
|
-
await configurable[id_](await mapper.ainvoke(input, config))
|
|
322
|
-
else:
|
|
323
|
-
await configurable[id_](input)
|
|
324
|
-
return input
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
class Context:
|
|
328
|
-
"""Context for a runnable.
|
|
329
|
-
|
|
330
|
-
The `Context` class provides methods for creating context scopes,
|
|
331
|
-
getters, and setters within a runnable. It allows for managing
|
|
332
|
-
and accessing contextual information throughout the execution
|
|
333
|
-
of a program.
|
|
334
|
-
|
|
335
|
-
Example:
|
|
336
|
-
.. code-block:: python
|
|
337
|
-
|
|
338
|
-
from langchain_core.beta.runnables.context import Context
|
|
339
|
-
from langchain_core.runnables.passthrough import RunnablePassthrough
|
|
340
|
-
from langchain_core.prompts.prompt import PromptTemplate
|
|
341
|
-
from langchain_core.output_parsers.string import StrOutputParser
|
|
342
|
-
from tests.unit_tests.fake.llm import FakeListLLM
|
|
343
|
-
|
|
344
|
-
chain = (
|
|
345
|
-
Context.setter("input")
|
|
346
|
-
| {
|
|
347
|
-
"context": RunnablePassthrough()
|
|
348
|
-
| Context.setter("context"),
|
|
349
|
-
"question": RunnablePassthrough(),
|
|
350
|
-
}
|
|
351
|
-
| PromptTemplate.from_template("{context} {question}")
|
|
352
|
-
| FakeListLLM(responses=["hello"])
|
|
353
|
-
| StrOutputParser()
|
|
354
|
-
| {
|
|
355
|
-
"result": RunnablePassthrough(),
|
|
356
|
-
"context": Context.getter("context"),
|
|
357
|
-
"input": Context.getter("input"),
|
|
358
|
-
}
|
|
359
|
-
)
|
|
360
|
-
|
|
361
|
-
# Use the chain
|
|
362
|
-
output = chain.invoke("What's your name?")
|
|
363
|
-
print(output["result"]) # Output: "hello"
|
|
364
|
-
print(output["context"]) # Output: "What's your name?"
|
|
365
|
-
print(output["input"]) # Output: "What's your name?
|
|
366
|
-
|
|
367
|
-
"""
|
|
368
|
-
|
|
369
|
-
@staticmethod
|
|
370
|
-
def create_scope(scope: str, /) -> "PrefixContext":
|
|
371
|
-
"""Create a context scope.
|
|
372
|
-
|
|
373
|
-
Args:
|
|
374
|
-
scope: The scope.
|
|
375
|
-
|
|
376
|
-
Returns:
|
|
377
|
-
The context scope.
|
|
378
|
-
"""
|
|
379
|
-
return PrefixContext(prefix=scope)
|
|
380
|
-
|
|
381
|
-
@staticmethod
|
|
382
|
-
def getter(key: Union[str, list[str]], /) -> ContextGet:
|
|
383
|
-
"""Return a context getter.
|
|
384
|
-
|
|
385
|
-
Args:
|
|
386
|
-
key: The context getter key.
|
|
387
|
-
"""
|
|
388
|
-
return ContextGet(key=key)
|
|
389
|
-
|
|
390
|
-
@staticmethod
|
|
391
|
-
def setter(
|
|
392
|
-
_key: Optional[str] = None,
|
|
393
|
-
_value: Optional[SetValue] = None,
|
|
394
|
-
/,
|
|
395
|
-
**kwargs: SetValue,
|
|
396
|
-
) -> ContextSet:
|
|
397
|
-
"""Return a context setter.
|
|
398
|
-
|
|
399
|
-
Args:
|
|
400
|
-
_key: The context setter key.
|
|
401
|
-
_value: The context setter value.
|
|
402
|
-
**kwargs: Additional context setter key-value pairs.
|
|
403
|
-
"""
|
|
404
|
-
return ContextSet(_key, _value, prefix="", **kwargs)
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
class PrefixContext:
|
|
408
|
-
"""Context for a runnable with a prefix."""
|
|
409
|
-
|
|
410
|
-
prefix: str = ""
|
|
411
|
-
|
|
412
|
-
def __init__(self, prefix: str = ""):
|
|
413
|
-
"""Create a prefix context.
|
|
414
|
-
|
|
415
|
-
Args:
|
|
416
|
-
prefix: The prefix.
|
|
417
|
-
"""
|
|
418
|
-
self.prefix = prefix
|
|
419
|
-
|
|
420
|
-
def getter(self, key: Union[str, list[str]], /) -> ContextGet:
|
|
421
|
-
"""Return a prefixed context getter.
|
|
422
|
-
|
|
423
|
-
Args:
|
|
424
|
-
key: The context getter key.
|
|
425
|
-
"""
|
|
426
|
-
return ContextGet(key=key, prefix=self.prefix)
|
|
427
|
-
|
|
428
|
-
def setter(
|
|
429
|
-
self,
|
|
430
|
-
_key: Optional[str] = None,
|
|
431
|
-
_value: Optional[SetValue] = None,
|
|
432
|
-
/,
|
|
433
|
-
**kwargs: SetValue,
|
|
434
|
-
) -> ContextSet:
|
|
435
|
-
"""Return a prefixed context setter.
|
|
436
|
-
|
|
437
|
-
Args:
|
|
438
|
-
_key: The context setter key.
|
|
439
|
-
_value: The context setter value.
|
|
440
|
-
**kwargs: Additional context setter key-value pairs.
|
|
441
|
-
"""
|
|
442
|
-
return ContextSet(_key, _value, prefix=self.prefix, **kwargs)
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
def _print_keys(keys: Union[str, Sequence[str]]) -> str:
|
|
446
|
-
if isinstance(keys, str):
|
|
447
|
-
return f"'{keys}'"
|
|
448
|
-
return ", ".join(f"'{k}'" for k in keys)
|