langchain-core 1.0.0a2__py3-none-any.whl → 1.0.0a3__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/_api/beta_decorator.py +17 -40
- langchain_core/_api/deprecation.py +20 -7
- langchain_core/_api/path.py +19 -2
- langchain_core/_import_utils.py +7 -0
- langchain_core/agents.py +10 -6
- langchain_core/callbacks/base.py +28 -15
- langchain_core/callbacks/manager.py +81 -69
- langchain_core/callbacks/usage.py +4 -2
- langchain_core/chat_history.py +29 -21
- langchain_core/document_loaders/base.py +34 -9
- langchain_core/document_loaders/langsmith.py +3 -0
- langchain_core/documents/base.py +35 -10
- langchain_core/documents/transformers.py +4 -2
- langchain_core/embeddings/fake.py +8 -5
- langchain_core/env.py +2 -3
- langchain_core/example_selectors/base.py +12 -0
- langchain_core/exceptions.py +7 -0
- langchain_core/globals.py +17 -28
- langchain_core/indexing/api.py +57 -45
- langchain_core/indexing/base.py +5 -8
- langchain_core/indexing/in_memory.py +23 -3
- langchain_core/language_models/__init__.py +6 -2
- langchain_core/language_models/_utils.py +27 -5
- langchain_core/language_models/base.py +33 -21
- langchain_core/language_models/chat_models.py +99 -27
- langchain_core/language_models/fake_chat_models.py +5 -7
- langchain_core/language_models/llms.py +54 -20
- langchain_core/load/dump.py +2 -3
- langchain_core/load/load.py +15 -1
- langchain_core/load/serializable.py +38 -43
- langchain_core/memory.py +7 -3
- langchain_core/messages/__init__.py +1 -1
- langchain_core/messages/ai.py +41 -34
- langchain_core/messages/base.py +16 -7
- langchain_core/messages/block_translators/__init__.py +10 -8
- langchain_core/messages/block_translators/anthropic.py +3 -1
- langchain_core/messages/block_translators/bedrock.py +3 -1
- langchain_core/messages/block_translators/bedrock_converse.py +3 -1
- langchain_core/messages/block_translators/google_genai.py +3 -1
- langchain_core/messages/block_translators/google_vertexai.py +3 -1
- langchain_core/messages/block_translators/groq.py +3 -1
- langchain_core/messages/block_translators/ollama.py +3 -1
- langchain_core/messages/block_translators/openai.py +50 -20
- langchain_core/messages/content.py +23 -13
- langchain_core/messages/human.py +2 -13
- langchain_core/messages/system.py +2 -6
- langchain_core/messages/tool.py +34 -14
- langchain_core/messages/utils.py +186 -73
- langchain_core/output_parsers/base.py +5 -2
- langchain_core/output_parsers/json.py +4 -4
- langchain_core/output_parsers/list.py +7 -22
- langchain_core/output_parsers/openai_functions.py +3 -0
- langchain_core/output_parsers/openai_tools.py +6 -1
- langchain_core/output_parsers/pydantic.py +4 -0
- langchain_core/output_parsers/string.py +5 -1
- langchain_core/output_parsers/xml.py +19 -19
- langchain_core/outputs/chat_generation.py +18 -7
- langchain_core/outputs/generation.py +14 -3
- langchain_core/outputs/llm_result.py +8 -1
- langchain_core/prompt_values.py +10 -4
- langchain_core/prompts/base.py +6 -11
- langchain_core/prompts/chat.py +88 -60
- langchain_core/prompts/dict.py +16 -8
- langchain_core/prompts/few_shot.py +9 -11
- langchain_core/prompts/few_shot_with_templates.py +5 -1
- langchain_core/prompts/image.py +12 -5
- langchain_core/prompts/loading.py +2 -2
- langchain_core/prompts/message.py +5 -6
- langchain_core/prompts/pipeline.py +13 -8
- langchain_core/prompts/prompt.py +22 -8
- langchain_core/prompts/string.py +18 -10
- langchain_core/prompts/structured.py +7 -2
- langchain_core/rate_limiters.py +2 -2
- langchain_core/retrievers.py +7 -6
- langchain_core/runnables/base.py +387 -246
- langchain_core/runnables/branch.py +11 -28
- langchain_core/runnables/config.py +20 -17
- langchain_core/runnables/configurable.py +34 -19
- langchain_core/runnables/fallbacks.py +20 -13
- langchain_core/runnables/graph.py +48 -38
- langchain_core/runnables/graph_ascii.py +40 -17
- langchain_core/runnables/graph_mermaid.py +54 -25
- langchain_core/runnables/graph_png.py +27 -31
- langchain_core/runnables/history.py +55 -58
- langchain_core/runnables/passthrough.py +44 -21
- langchain_core/runnables/retry.py +44 -23
- langchain_core/runnables/router.py +9 -8
- langchain_core/runnables/schema.py +9 -0
- langchain_core/runnables/utils.py +53 -90
- langchain_core/stores.py +19 -31
- langchain_core/sys_info.py +9 -8
- langchain_core/tools/base.py +36 -27
- langchain_core/tools/convert.py +25 -14
- langchain_core/tools/simple.py +36 -8
- langchain_core/tools/structured.py +25 -12
- langchain_core/tracers/base.py +2 -2
- langchain_core/tracers/context.py +5 -1
- langchain_core/tracers/core.py +110 -46
- langchain_core/tracers/evaluation.py +22 -26
- langchain_core/tracers/event_stream.py +97 -42
- langchain_core/tracers/langchain.py +12 -3
- langchain_core/tracers/langchain_v1.py +10 -2
- langchain_core/tracers/log_stream.py +56 -17
- langchain_core/tracers/root_listeners.py +4 -20
- langchain_core/tracers/run_collector.py +6 -16
- langchain_core/tracers/schemas.py +5 -1
- langchain_core/utils/aiter.py +14 -6
- langchain_core/utils/env.py +3 -0
- langchain_core/utils/function_calling.py +46 -20
- langchain_core/utils/interactive_env.py +6 -2
- langchain_core/utils/iter.py +12 -5
- langchain_core/utils/json.py +12 -3
- langchain_core/utils/json_schema.py +156 -40
- langchain_core/utils/loading.py +5 -1
- langchain_core/utils/mustache.py +25 -16
- langchain_core/utils/pydantic.py +38 -9
- langchain_core/utils/utils.py +25 -9
- langchain_core/vectorstores/base.py +7 -20
- langchain_core/vectorstores/in_memory.py +20 -14
- langchain_core/vectorstores/utils.py +18 -12
- langchain_core/version.py +1 -1
- langchain_core-1.0.0a3.dist-info/METADATA +77 -0
- langchain_core-1.0.0a3.dist-info/RECORD +181 -0
- 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-1.0.0a2.dist-info/METADATA +0 -106
- langchain_core-1.0.0a2.dist-info/RECORD +0 -184
- {langchain_core-1.0.0a2.dist-info → langchain_core-1.0.0a3.dist-info}/WHEEL +0 -0
- {langchain_core-1.0.0a2.dist-info → langchain_core-1.0.0a3.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
langchain_core-1.0.0a3.dist-info/METADATA,sha256=k94vpJybgVViNdkf_q3-vsyfxcOzOoZ5iN4zgzC1-cQ,3726
|
|
2
|
+
langchain_core-1.0.0a3.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
|
|
3
|
+
langchain_core-1.0.0a3.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
|
4
|
+
langchain_core/__init__.py,sha256=TgvhxbrjCRVJwr2HddiyHvtH8W94K-uLM6-6ifNIBXo,713
|
|
5
|
+
langchain_core/_api/__init__.py,sha256=WDOMw4faVuscjDCL5ttnRQNienJP_M9vGMmJUXS6L5w,1976
|
|
6
|
+
langchain_core/_api/beta_decorator.py,sha256=LM5C32LB7_KNLfePssM2hgFRt7aPvqddf9J_TiOWIsw,8877
|
|
7
|
+
langchain_core/_api/deprecation.py,sha256=zvN3foFxxJe62iS1LAdpBTKQ2yZEwNxLiB0bom6hPZ8,20927
|
|
8
|
+
langchain_core/_api/internal.py,sha256=aOZkYANu747LyWzyAk-0KE4RjdTYj18Wtlh7F9_qyPM,683
|
|
9
|
+
langchain_core/_api/path.py,sha256=raXCzfgMf6AoPo8UP6I1qHRKlIBcBuR18qMHaFyIvhU,1405
|
|
10
|
+
langchain_core/_import_utils.py,sha256=NvAiw5PLvsKCux8LcRndpbZL9m_rHkL1-iWZcNLzQMc,1458
|
|
11
|
+
langchain_core/agents.py,sha256=Z9AFByLkZp__LM_icC699Ge-8dCxPiYQNOdEqrZUiDw,8468
|
|
12
|
+
langchain_core/caches.py,sha256=d_6h0Bb0h7sLK0mrQ1BwSljJKnLBvKvoXQMVSnpcqlI,9665
|
|
13
|
+
langchain_core/callbacks/__init__.py,sha256=jXp7StVQk5GeWudGtnnkFV_L-WHCl44ESznc6-0pOVg,4347
|
|
14
|
+
langchain_core/callbacks/base.py,sha256=TRYx7JexS4V-DWr2mlV4K0GiicblC548t1nbjPrjtb0,37325
|
|
15
|
+
langchain_core/callbacks/file.py,sha256=dLBuDRqeLxOBTB9k6c9KEh8dx5UgGfQ9uUF-dhiykZM,8532
|
|
16
|
+
langchain_core/callbacks/manager.py,sha256=hLyjHpS07NwlAwsgHcoM-nv7U12tyS5PTk-o7rJFJ84,90999
|
|
17
|
+
langchain_core/callbacks/stdout.py,sha256=hQ1gjpshNHGdbCS8cH6_oTc4nM8tCWzGNXrbm9dJeaY,4113
|
|
18
|
+
langchain_core/callbacks/streaming_stdout.py,sha256=92UQWxL9HBzdCpn47AF-ZE_jGkkebMn2Z_l24ndMBMI,4646
|
|
19
|
+
langchain_core/callbacks/usage.py,sha256=S2sBShC_0br6HtRB5Cow6ILOl_gX7TaDcEAge2MyjYo,5107
|
|
20
|
+
langchain_core/chat_history.py,sha256=8dMeYTMwWl1wH64qjW8gq9Cx143eqLV0Qa9xEQ37m5I,8872
|
|
21
|
+
langchain_core/chat_loaders.py,sha256=b57Gl3KGPxq9gYJjetsHfJm1I6kSqi7bDE91fJJOR84,601
|
|
22
|
+
langchain_core/chat_sessions.py,sha256=YEO3ck5_wRGd3a2EnGD7M_wTvNC_4T1IVjQWekagwaM,564
|
|
23
|
+
langchain_core/document_loaders/__init__.py,sha256=DkZPp9cEVmsnz9SM1xtuefH_fGQFvA2WtpRG6iePPBs,975
|
|
24
|
+
langchain_core/document_loaders/base.py,sha256=nBv07847NrsB9EZpC0YU7Zv_Y08T7pisLREMrJwE7Bg,4666
|
|
25
|
+
langchain_core/document_loaders/blob_loaders.py,sha256=4m1k8boiwXw3z4yMYT8bnYUA-eGTPtEZyUxZvI3GbTs,1077
|
|
26
|
+
langchain_core/document_loaders/langsmith.py,sha256=QGgBhyr0uq3_84nTzuBB8Bk-DiubjuTVsfvSj-Y8RvU,5513
|
|
27
|
+
langchain_core/documents/__init__.py,sha256=KT_l-TSINKrTXldw5n57wx1yGBtJmGAGxAQL0ceQefc,850
|
|
28
|
+
langchain_core/documents/base.py,sha256=qxf8E06ga9kblxvTECyNXViHoLx1_MWPTM92ATSWlX8,10598
|
|
29
|
+
langchain_core/documents/compressor.py,sha256=91aCQC3W4XMoFXtAmlOCSPb8pSdrirY6Lg8ZLBxTX4s,2001
|
|
30
|
+
langchain_core/documents/transformers.py,sha256=lL0BdmL8xkNO_NqY3vqaLPhPdzte0BUKVoG2IMJqe2s,2584
|
|
31
|
+
langchain_core/embeddings/__init__.py,sha256=0SfcdkVSSXmTFXznUyeZq_b1ajpwIGDueGAAfwyMpUY,774
|
|
32
|
+
langchain_core/embeddings/embeddings.py,sha256=u50T2VxLLyfGBCKcVtWfSiZrtKua8sOSHwSSHRKtcno,2405
|
|
33
|
+
langchain_core/embeddings/fake.py,sha256=iEFwd3j7zGG6EUoCPK-Y9On9C3-q-Lu0Syld27UhsnQ,3954
|
|
34
|
+
langchain_core/env.py,sha256=RHExSWJ2bW-6Wxb6UyBGxU5flLoNYOAeslZ9iTjomQE,598
|
|
35
|
+
langchain_core/example_selectors/__init__.py,sha256=k8y0chtEhaHf8Y1_nZVDsb9CWDdRIWFb9U806mnbGvo,1394
|
|
36
|
+
langchain_core/example_selectors/base.py,sha256=4wRCERHak6Ci5JEKHeidQ_pbBgzQyc-vnQsz2sqBFzA,1716
|
|
37
|
+
langchain_core/example_selectors/length_based.py,sha256=VlWoGhppKrKYKRyi0qBdhq4TbD-6pDHobx3fMGWoqfY,3375
|
|
38
|
+
langchain_core/example_selectors/semantic_similarity.py,sha256=flhao1yNBnaDkM2MlwFd2m4m2dBc_IlEMnmSWV61IVE,13739
|
|
39
|
+
langchain_core/exceptions.py,sha256=JurkMF4p-DOmv7SQJqif7A-5kfKOHCcl8R_wXmMUfSE,3327
|
|
40
|
+
langchain_core/globals.py,sha256=yl9GRxC3INm6AqRplHmKjxr0bn1YWXSU34iul5dnBl8,8823
|
|
41
|
+
langchain_core/indexing/__init__.py,sha256=VOvbbBJYY_UZdMKAeJCdQdszMiAOhAo3Cbht1HEkk8g,1274
|
|
42
|
+
langchain_core/indexing/api.py,sha256=aHOBAEhLFxmutjT9U8fKIuejwujpKO5EmJfZzcu1JIE,38469
|
|
43
|
+
langchain_core/indexing/base.py,sha256=PWxwX4bH1xq8gKaVnGiNnThPRmwhoDKrJRlEotjtERo,23015
|
|
44
|
+
langchain_core/indexing/in_memory.py,sha256=YPVOGKE3d5-APCy7T0sJvSPjJJUcshSfPeCpq7BA4j0,3326
|
|
45
|
+
langchain_core/language_models/__init__.py,sha256=UATdO6Ap7_UdEHv_sCNxXj_b20-LPDDZJnFkA7zazk8,3901
|
|
46
|
+
langchain_core/language_models/_utils.py,sha256=L5isJ4pHLLPuPjsEjhAC5f2Lxgn_XuYyr-kmqFdzTpU,11164
|
|
47
|
+
langchain_core/language_models/base.py,sha256=35rt7Io4_nMztFaQ3c2iukSdVsDDL2q6u4ETvgdWV_c,14583
|
|
48
|
+
langchain_core/language_models/chat_models.py,sha256=timWQlovkW4P7u0O8EXy7XWlwUL4zZhA8qiuw4vyTJo,79654
|
|
49
|
+
langchain_core/language_models/fake.py,sha256=h9LhVTkmYLXkJ1_VvsKhqYVpkQsM7eAr9geXF_IVkPs,3772
|
|
50
|
+
langchain_core/language_models/fake_chat_models.py,sha256=nbPFjZ4JSL2-OxKJjJFo39LTehciFZR6Usj5cstDME0,13496
|
|
51
|
+
langchain_core/language_models/llms.py,sha256=wWmMcAJbQYyFBFrXxy2wkNDS4eEv63HwiJLfsOzKFzU,58049
|
|
52
|
+
langchain_core/load/__init__.py,sha256=m3_6Fk2gpYZO0xqyTnZzdQigvsYHjMariLq_L2KwJFk,1150
|
|
53
|
+
langchain_core/load/dump.py,sha256=N34h-I3VeLFzuwrYlVSY_gFx0iaZhEi72D04yxkx3cc,2654
|
|
54
|
+
langchain_core/load/load.py,sha256=eDyYNBGbfVDLGOA3p2cAOWY0rLqbf9E9qNfstw0PKDY,9729
|
|
55
|
+
langchain_core/load/mapping.py,sha256=nnFXiTdQkfdv41_wP38aWGtpp9svxW6fwVyC3LmRkok,29633
|
|
56
|
+
langchain_core/load/serializable.py,sha256=P29Coe7ZE8-13goAmAtSt0rl85fKaUd96znRQuIHG9k,11722
|
|
57
|
+
langchain_core/memory.py,sha256=bYgZGSldIa79GqpEd2m9Ve78euCq6SJatzTsHAHKosk,3693
|
|
58
|
+
langchain_core/messages/__init__.py,sha256=y4HmwOTSPex6Py9fo7NPPBf82O_MkdgTUw5uj1f_gmg,6048
|
|
59
|
+
langchain_core/messages/ai.py,sha256=kHFdWpswJ_H9XLY2YkmJ5jCQc11_15Op4YjjvGrGmMI,24629
|
|
60
|
+
langchain_core/messages/base.py,sha256=3e4RNutCZfo3KJfoVrdmKt0hPxt79yM-M_aZuytMwlg,14909
|
|
61
|
+
langchain_core/messages/block_translators/__init__.py,sha256=bBWL_RoZWfy7MZzRmKGZihbZpJ61LO-GMtQiGizRjqc,3255
|
|
62
|
+
langchain_core/messages/block_translators/anthropic.py,sha256=5O-OkOUAX0iReOSRIxCiTOs6xAnITyFgPyKmHwzSyIo,19221
|
|
63
|
+
langchain_core/messages/block_translators/bedrock.py,sha256=I71rdoi6D0V4TPTMV4kU_wIEp6WybgBfXrLZkYnzo0Y,1527
|
|
64
|
+
langchain_core/messages/block_translators/bedrock_converse.py,sha256=M2EhLQHmNGGHRJHCIzYWWktTQDIZhvlFDIl-6LrhpgA,1638
|
|
65
|
+
langchain_core/messages/block_translators/google_genai.py,sha256=C_ug4rlO93alzoH14FCsk6temXJZrTXoEx2_AfGfZhk,1571
|
|
66
|
+
langchain_core/messages/block_translators/google_vertexai.py,sha256=spEuRU1tFsmQvIlHdrQgDswDP5XSQr0-5qgW8x47vXQ,1628
|
|
67
|
+
langchain_core/messages/block_translators/groq.py,sha256=8Iw_HSZM00MZQTrvlZucxSJ2bbx9gvkxR-SU_mjuJk8,1499
|
|
68
|
+
langchain_core/messages/block_translators/langchain_v0.py,sha256=NQjsIeP5lrCqKMK-NcAsI66dvVwIvjUegbtkzv9cj3Y,6708
|
|
69
|
+
langchain_core/messages/block_translators/ollama.py,sha256=0xQE5YmRPy0fuXtyGpxEsHfLZzwzQofEc-EnSwUT1vc,1517
|
|
70
|
+
langchain_core/messages/block_translators/openai.py,sha256=nD6D_Nd-dw5da-09LetUu5nLVxZ6bIBO98KX5Q5mlzg,32003
|
|
71
|
+
langchain_core/messages/chat.py,sha256=Vgk3y03F9NP-wKkXAjBDLOtrH43NpEMN2xaWRp6qhRA,2260
|
|
72
|
+
langchain_core/messages/content.py,sha256=4th006UJRBhDHnr9jvVZ3kHU79tIvm6Bkss_z396els,43565
|
|
73
|
+
langchain_core/messages/function.py,sha256=QO2WgKmJ5nm7QL-xXG11Fmz3qFkHm1lL0k41WjDeEZE,2157
|
|
74
|
+
langchain_core/messages/human.py,sha256=tA_zRoA-UuTFEs81g9mcQM8mSUoXaLJSpThqWb8-fJ4,2303
|
|
75
|
+
langchain_core/messages/modifier.py,sha256=ch0RedUM_uA7wOEJHk8mkoJSNR0Rli_32BmOfdbS1dU,894
|
|
76
|
+
langchain_core/messages/system.py,sha256=LnEMMEhB16rLSHibJz6sh2Cs84gCz_eOxG3NKxP8I74,2313
|
|
77
|
+
langchain_core/messages/tool.py,sha256=gu4FTfTfsZQg0IF9GquF4GVUEb6Ej7Lnn3g-zMMP5yY,12762
|
|
78
|
+
langchain_core/messages/utils.py,sha256=gyIOxWVHBVHgJkSOitZnaESRsSEoEzQIh401UUa04xc,70187
|
|
79
|
+
langchain_core/output_parsers/__init__.py,sha256=R8L0GwY-vD9qvqze3EVELXF6i45IYUJ_FbSfno_IREg,2873
|
|
80
|
+
langchain_core/output_parsers/base.py,sha256=53Yt9dOlR686ku0dP2LK9hHKGprxw_YEsAsY04dejmE,11225
|
|
81
|
+
langchain_core/output_parsers/format_instructions.py,sha256=8oUbeysnVGvXWyNd5gqXlEL850D31gMTy74GflsuvRU,553
|
|
82
|
+
langchain_core/output_parsers/json.py,sha256=Z_mcfO9jdAH96dZXrSi4rEx3o7Z9Oqn_IBkOjLBDpaQ,4589
|
|
83
|
+
langchain_core/output_parsers/list.py,sha256=WJ1fgGH2vnh_TRgGd83WZKVKGGpcqu-Q8zjDseqIA0Y,7294
|
|
84
|
+
langchain_core/output_parsers/openai_functions.py,sha256=FFy2Wh39wPFM1mO222gMzQU_wrpIFiCo5unZM8PM3jQ,10793
|
|
85
|
+
langchain_core/output_parsers/openai_tools.py,sha256=2zBuswllEu_gwN7iAd3Yvifr6XIJcvyMIVa1ER68-_k,12606
|
|
86
|
+
langchain_core/output_parsers/pydantic.py,sha256=mwB5HNa4KHLt_kD7gbwWyXSX-GnM1gX0nsM00b0OVAE,4490
|
|
87
|
+
langchain_core/output_parsers/string.py,sha256=jlUsciPkCmZ3MOfhz-KUJDjSaR0VswnzH8z0KlIfAoQ,965
|
|
88
|
+
langchain_core/output_parsers/transform.py,sha256=ntWW0SKk6GUHXQNXHZvT1PhyedQrvF61oIo_fP63fRQ,5923
|
|
89
|
+
langchain_core/output_parsers/xml.py,sha256=MDjZHJY2KeYREPLlEQJ1M2r0ALa0nb1Wec7MJ4Nk6LA,10974
|
|
90
|
+
langchain_core/outputs/__init__.py,sha256=uy2aeRTvvIfyWeLtPs0KaCw0VpG6QTkC0esmj268BIM,2119
|
|
91
|
+
langchain_core/outputs/chat_generation.py,sha256=XLJCeok5mliejMlzJka8v8aqLDs6HORd813PcxeeBRk,4681
|
|
92
|
+
langchain_core/outputs/chat_result.py,sha256=us15wVh00AYkIVNmf0VETEI9aoEQy-cT-SIXMX-98Zc,1356
|
|
93
|
+
langchain_core/outputs/generation.py,sha256=zroWD-bJxmdKJWbt1Rv-jVImyOng5s8rEn8bHMtjaLo,2644
|
|
94
|
+
langchain_core/outputs/llm_result.py,sha256=aX81609Z5JrLQGx9u2l6UDdzMLRoLgvdr5k1xDmB4UI,3935
|
|
95
|
+
langchain_core/outputs/run_info.py,sha256=xCMWdsHfgnnodaf4OCMvZaWUfS836X7mV15JPkqvZjo,594
|
|
96
|
+
langchain_core/prompt_values.py,sha256=35H9-5o9KP0gLPEcNURtqQOOuc8lDPi6th-Fqu3H-Ew,4031
|
|
97
|
+
langchain_core/prompts/__init__.py,sha256=sp3NU858CEf4YUuDYiY_-iF1x1Gb5msSyoyrk2FUI94,4123
|
|
98
|
+
langchain_core/prompts/base.py,sha256=VJt3Mv_NegXDbe4AQxPPNq4ZuImV5lIKIB2THzGatrw,16007
|
|
99
|
+
langchain_core/prompts/chat.py,sha256=Q-ZiWXG_8eup9-iESgaDz8R1HcN26exYhlVi6lSeUtI,52597
|
|
100
|
+
langchain_core/prompts/dict.py,sha256=e4rxVs2IkMjxN_NqYtRpb9NYLyE9mimMMSzawbubrfA,4732
|
|
101
|
+
langchain_core/prompts/few_shot.py,sha256=nd1KtIw_pv8MdM49Q1V_szu4u6Wil0VAVqmiHLKzr64,16141
|
|
102
|
+
langchain_core/prompts/few_shot_with_templates.py,sha256=z1fSlcHunfdVQc7BuM9tudCWMquUn2Zztw7ROXOEOgE,7839
|
|
103
|
+
langchain_core/prompts/image.py,sha256=rrwpPo3nb2k_8I1DYF3cZv3go0T_CmSUrJsIktrQtgA,4786
|
|
104
|
+
langchain_core/prompts/loading.py,sha256=wFfHxvh8107PoH8h1DwnNtRDZoEMF9EZBTT8ZWSVbC8,6939
|
|
105
|
+
langchain_core/prompts/message.py,sha256=9I5IZXFn2Bwv8CIZ0zMp7k8C48xQyiAOqyv6uAYJdY0,2624
|
|
106
|
+
langchain_core/prompts/pipeline.py,sha256=Zj6aqIcU874mnYG__0I4nHmz4p7uaNAdYsJpMDb1LyQ,4612
|
|
107
|
+
langchain_core/prompts/prompt.py,sha256=RfD-w7GKolgptGB72UVIb1q3iIOm4pv2hby6EmJf9kk,11667
|
|
108
|
+
langchain_core/prompts/string.py,sha256=biN76hgwqZx-SjtXgy3qe9QmM2I2STSg8DylD0Mf0RE,10361
|
|
109
|
+
langchain_core/prompts/structured.py,sha256=V5qfOpSPWBnF5xcRl_qEmrv1u7T_IfzONHJ-rUFiTyE,5957
|
|
110
|
+
langchain_core/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
111
|
+
langchain_core/pydantic_v1/__init__.py,sha256=hqAsQjsfqLduCo5E0oAAAt21Nkls0S6bCQ4tD2moFfU,1080
|
|
112
|
+
langchain_core/pydantic_v1/dataclasses.py,sha256=q4Qst8I0g7odncWZ3-MvW-Xadfu6DQYxCo-DFZgwLPE,889
|
|
113
|
+
langchain_core/pydantic_v1/main.py,sha256=uTB_757DTfo-mFKJUn_a4qS_GxmSxlqYmL2WOCJLdS0,882
|
|
114
|
+
langchain_core/rate_limiters.py,sha256=EZtViY5BZLPBg_JBvv_kYywV9Cl3wd6AC-SDEA0fPPg,9550
|
|
115
|
+
langchain_core/retrievers.py,sha256=622gKRLmBSUXi_o4z57EoctT32XRbqCk_5f_NU7MEFE,16710
|
|
116
|
+
langchain_core/runnables/__init__.py,sha256=efTnFjwN_QSAv5ThLmKuWeu8P1BLARH-cWKZBuimfDM,3858
|
|
117
|
+
langchain_core/runnables/base.py,sha256=7jLT_V9SKOyJZtNvil1COJOyjdLt2EVY2cqldeRsvtc,226048
|
|
118
|
+
langchain_core/runnables/branch.py,sha256=S1rW_dzpkqR-QRdVBA8Ib43cJXTfftKzK0UHDKxx_14,15941
|
|
119
|
+
langchain_core/runnables/config.py,sha256=ZnrxLsk5uH_-xKRS-A3XX70oAc0o402KoO4HLuKN8KA,20334
|
|
120
|
+
langchain_core/runnables/configurable.py,sha256=Ios0MDPViYO9nO_EltAlkDkNNxdz4zXuNcZ1cuHZwzw,24695
|
|
121
|
+
langchain_core/runnables/fallbacks.py,sha256=VeHCrW_Ci9p8G9KojNp5dC7Yo6l5jdZtst9O_yt2sM0,24497
|
|
122
|
+
langchain_core/runnables/graph.py,sha256=60uOAcwD0lXPrMhPAeOTndYINtalGFz8zgaV14ig5dk,23922
|
|
123
|
+
langchain_core/runnables/graph_ascii.py,sha256=DYdH8pv9dJcQHYcNupEs-XCasDd-jrGeEMTbS6K5OAk,10446
|
|
124
|
+
langchain_core/runnables/graph_mermaid.py,sha256=LQZz4hVisPo7ZvsI_-xd2fCInwsHfFVTicbzNrZXWy8,17415
|
|
125
|
+
langchain_core/runnables/graph_png.py,sha256=md4NFNKMY7SkAr3Ysf1FNOU-SIZioSkniT__IPkoUSA,5566
|
|
126
|
+
langchain_core/runnables/history.py,sha256=CeFI41kBoowUKsCuFu1HeEgBIuyhh2oEhcuUyPs_j6M,24775
|
|
127
|
+
langchain_core/runnables/passthrough.py,sha256=HvwNeGVVzhS6EkSurbjU8Ah-UXUj3nsrhiY-gmeyxhE,26443
|
|
128
|
+
langchain_core/runnables/retry.py,sha256=gDvUiUIPQHY3fXIM1ZB6cFovDYrfIOqlvHZnOB0IBVs,13898
|
|
129
|
+
langchain_core/runnables/router.py,sha256=HYGMfOYhpdyL3OlrEjYj1bKqEjDFyWEvFDXx2BoV3s4,7236
|
|
130
|
+
langchain_core/runnables/schema.py,sha256=WHu6l3AF1v_MRsbl8__Oh92xffedUZtM7DDz12aFD8E,5760
|
|
131
|
+
langchain_core/runnables/utils.py,sha256=RTuuNaeJ0_UBXtRkcAjSrWdGFjC2GJ2qiliSOa47qAY,22847
|
|
132
|
+
langchain_core/stores.py,sha256=bjZbmXSGhkCHHUQWmiTxVbmGcwggaR9KH1pxe2Gkqko,10644
|
|
133
|
+
langchain_core/structured_query.py,sha256=SmeP7cYTx2OCxOEo9UsSiHO3seqIoZPjb0CQd8JDWRk,5164
|
|
134
|
+
langchain_core/sys_info.py,sha256=HG1fu2ayPvRQmrlowyO-NdUj_I8Le1S-bPAbYB9VJTY,4045
|
|
135
|
+
langchain_core/tools/__init__.py,sha256=Uqcn6gFAoFbMM4aRXd8ACL4D-owdevGc37Gn-KOB8JU,2860
|
|
136
|
+
langchain_core/tools/base.py,sha256=Buz49ZemDfteMbP_jzRv5ZJ5NH9YTqnFFaJA0VSuISc,50322
|
|
137
|
+
langchain_core/tools/convert.py,sha256=0OpkMOu-cyHannJ_RZ-HaeIvmOIOkvSZfYo2xz4yieU,16260
|
|
138
|
+
langchain_core/tools/render.py,sha256=BosvIWrSvOJgRg_gaSDBS58j99gwQHsLhprOXeJP53I,1842
|
|
139
|
+
langchain_core/tools/retriever.py,sha256=zlSV3HnWhhmtZtkNGbNQW9wxv8GptJKmDhzqZj8e36o,3873
|
|
140
|
+
langchain_core/tools/simple.py,sha256=tW97_Qe4VWJymtXFtN8WRxNk0t4SmLIcgMnz5cq3aQU,6761
|
|
141
|
+
langchain_core/tools/structured.py,sha256=DYnck1Y5GRfBDcg6TRDAgVzTYyL6gAmCuN1a5C04NTU,9463
|
|
142
|
+
langchain_core/tracers/__init__.py,sha256=ixZmLjtoMEPqYEFUtAxleiDDRNIaHrS01VRDo9mCPk8,1611
|
|
143
|
+
langchain_core/tracers/_streaming.py,sha256=U9pWQDJNUDH4oOYF3zvUMUtgkCecJzXQvfo-wYARmhQ,982
|
|
144
|
+
langchain_core/tracers/base.py,sha256=rbIJgMaDga3jFeCWCmzjqUZLMmp9ZczT4wFecVPL2hk,26013
|
|
145
|
+
langchain_core/tracers/context.py,sha256=xCgMjCoulBm3QXjLaVDFC8-93emgsunYcCtZCiVKcTo,7199
|
|
146
|
+
langchain_core/tracers/core.py,sha256=j3cHErFRRNdifrzVmbgzIcf3lVWbi2pJ4F9lmaj3cfk,23566
|
|
147
|
+
langchain_core/tracers/evaluation.py,sha256=o0iIcuYx_mlD8q5_N7yxiVIaGeC3JaepHlZks0xm0nQ,8426
|
|
148
|
+
langchain_core/tracers/event_stream.py,sha256=bFyjx9h75_RbfPB9DYFoEBITvYBa0f-4b_yufQDZhro,35103
|
|
149
|
+
langchain_core/tracers/langchain.py,sha256=bvavDPE5t2J2BNexot0cHsD0asSeoofNtWAQqYbBvTQ,10620
|
|
150
|
+
langchain_core/tracers/langchain_v1.py,sha256=QteCXOsETqngvigalofcKR3l6le6barotAtWHaE8a1w,898
|
|
151
|
+
langchain_core/tracers/log_stream.py,sha256=jaW3tOvBxR4FgSZj4lS9pjVCdc4Y8_DUJoudAEcC-wQ,25491
|
|
152
|
+
langchain_core/tracers/memory_stream.py,sha256=3A-cwA3-lq5YFbCZWYM8kglVv1bPT4kwM2L_q8axkhU,5032
|
|
153
|
+
langchain_core/tracers/root_listeners.py,sha256=44cr4itZknl2VaYS3pNitJIy2DOKmZC09WWeHIBjOnU,4184
|
|
154
|
+
langchain_core/tracers/run_collector.py,sha256=FZkocT41EichTy2QyETbhZjlOptyj-peOhEQUqEcJGg,1305
|
|
155
|
+
langchain_core/tracers/schemas.py,sha256=y16K_c1ji3LHD-addSkn4-n73eknS2RlNRAhTSgs_YM,3826
|
|
156
|
+
langchain_core/tracers/stdout.py,sha256=aZN-yz545zj34kYfrEmYzWeSz83pbqN8wNqi-ZvS1Iw,6732
|
|
157
|
+
langchain_core/utils/__init__.py,sha256=N0ZeV09FHvZIVITLJlqGibb0JNtmmLvvoareFtG0DuI,3169
|
|
158
|
+
langchain_core/utils/_merge.py,sha256=GxSCcGqVhYvx58B6QZFu0SA4B0JCfHLUwYDRX34GBlA,7555
|
|
159
|
+
langchain_core/utils/aiter.py,sha256=R3_2TqQHAUbRig9BddP8NQZdeDDnW6uS9kK9gZAIRr8,10892
|
|
160
|
+
langchain_core/utils/env.py,sha256=5EnSNXr4oHAkGkKfrNf0xl_vqz2ejVKVMUQaQePXv9s,2536
|
|
161
|
+
langchain_core/utils/formatting.py,sha256=fkieArzKXxSsLcEa3B-MX60O4ZLeeLjiPtVtxCJPcOU,1480
|
|
162
|
+
langchain_core/utils/function_calling.py,sha256=8Jy0eUQnC8YtCQUxoeNDzXYgttrHxuDTZ7wQPTcLA9k,29814
|
|
163
|
+
langchain_core/utils/html.py,sha256=fUogMGhd-VoUbsGnMyY6v_gv9nbxJy-vmC4yfICcflM,3780
|
|
164
|
+
langchain_core/utils/image.py,sha256=1MH8Lbg0f2HfhTC4zobKMvpVoHRfpsyvWHq9ae4xENo,532
|
|
165
|
+
langchain_core/utils/input.py,sha256=z3tubdUtsoHqfTyiBGfELLr1xemSe-pGvhfAeGE6O2g,1958
|
|
166
|
+
langchain_core/utils/interactive_env.py,sha256=nm06cucX9ez9H3GBAIRDsivSp0V--2HnBIMogI4gHpQ,287
|
|
167
|
+
langchain_core/utils/iter.py,sha256=SlNRrOFeMAyXa6yoBsuQdaBlB9kFpeyNsj9r-or11sc,7534
|
|
168
|
+
langchain_core/utils/json.py,sha256=OhhQvE7NOeDhQGxn0vUU9_g4wBu167A3w7Ou9SX419o,6537
|
|
169
|
+
langchain_core/utils/json_schema.py,sha256=9fdA1Gb-pLfpcgSOJxxjMt1FqiWi0K95tNjWtlFgMgs,9102
|
|
170
|
+
langchain_core/utils/loading.py,sha256=zHY3y-eW_quqgJDJNY24dO7YDZW9P103Mc77dnGbEpA,1023
|
|
171
|
+
langchain_core/utils/mustache.py,sha256=ey1wgTcsiZWElRboSilF3EAQCz23Asa6h-65z9RPMSo,21362
|
|
172
|
+
langchain_core/utils/pydantic.py,sha256=6IQLwQODfupvtPcQTSOLA57vFKqA-b_xWenjOMwZzGU,18663
|
|
173
|
+
langchain_core/utils/strings.py,sha256=0LaQiqpshHwMrWBGvNfFPc-AxihLGMM9vsQcSx3uAkI,1804
|
|
174
|
+
langchain_core/utils/usage.py,sha256=EYv0poDqA7VejEsPyoA19lEt9M4L24Tppf4OPtOjGwI,1202
|
|
175
|
+
langchain_core/utils/utils.py,sha256=Nu3RHt9ZVRQgNbjXFCFqsbuJyqdOemTQYpMSodpOJng,16297
|
|
176
|
+
langchain_core/vectorstores/__init__.py,sha256=5P0eoeoH5LHab64JjmEeWa6SxX4eMy-etAP1MEHsETY,804
|
|
177
|
+
langchain_core/vectorstores/base.py,sha256=nWlfzbkVdOObfbPpvfdLKHw9J0PryACVohHC_Y6wWZM,41529
|
|
178
|
+
langchain_core/vectorstores/in_memory.py,sha256=ye4hGrj1ZlZsFHQx0Pbn_pvVAJ4F3ENLY74x4oU_FkY,18137
|
|
179
|
+
langchain_core/vectorstores/utils.py,sha256=D6St53Xg1kO73dnw4MPd8vlkro4C3gmCpcghUzcepi0,4971
|
|
180
|
+
langchain_core/version.py,sha256=A39mxvDADQ-V2kWGTQvaBcNYLKxxEZ79po6fYefkO6M,77
|
|
181
|
+
langchain_core-1.0.0a3.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__(
|
|
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)
|