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.

Files changed (172) hide show
  1. langchain_core/__init__.py +1 -1
  2. langchain_core/_api/__init__.py +3 -4
  3. langchain_core/_api/beta_decorator.py +45 -70
  4. langchain_core/_api/deprecation.py +80 -80
  5. langchain_core/_api/path.py +22 -8
  6. langchain_core/_import_utils.py +10 -4
  7. langchain_core/agents.py +25 -21
  8. langchain_core/caches.py +53 -63
  9. langchain_core/callbacks/__init__.py +1 -8
  10. langchain_core/callbacks/base.py +341 -348
  11. langchain_core/callbacks/file.py +55 -44
  12. langchain_core/callbacks/manager.py +546 -683
  13. langchain_core/callbacks/stdout.py +29 -30
  14. langchain_core/callbacks/streaming_stdout.py +35 -36
  15. langchain_core/callbacks/usage.py +65 -70
  16. langchain_core/chat_history.py +48 -55
  17. langchain_core/document_loaders/base.py +46 -21
  18. langchain_core/document_loaders/langsmith.py +39 -36
  19. langchain_core/documents/__init__.py +0 -1
  20. langchain_core/documents/base.py +96 -74
  21. langchain_core/documents/compressor.py +12 -9
  22. langchain_core/documents/transformers.py +29 -28
  23. langchain_core/embeddings/fake.py +56 -57
  24. langchain_core/env.py +2 -3
  25. langchain_core/example_selectors/base.py +12 -0
  26. langchain_core/example_selectors/length_based.py +1 -1
  27. langchain_core/example_selectors/semantic_similarity.py +21 -25
  28. langchain_core/exceptions.py +15 -9
  29. langchain_core/globals.py +4 -163
  30. langchain_core/indexing/api.py +132 -125
  31. langchain_core/indexing/base.py +64 -67
  32. langchain_core/indexing/in_memory.py +26 -6
  33. langchain_core/language_models/__init__.py +15 -27
  34. langchain_core/language_models/_utils.py +267 -117
  35. langchain_core/language_models/base.py +92 -177
  36. langchain_core/language_models/chat_models.py +547 -407
  37. langchain_core/language_models/fake.py +11 -11
  38. langchain_core/language_models/fake_chat_models.py +72 -118
  39. langchain_core/language_models/llms.py +168 -242
  40. langchain_core/load/dump.py +8 -11
  41. langchain_core/load/load.py +32 -28
  42. langchain_core/load/mapping.py +2 -4
  43. langchain_core/load/serializable.py +50 -56
  44. langchain_core/messages/__init__.py +36 -51
  45. langchain_core/messages/ai.py +377 -150
  46. langchain_core/messages/base.py +239 -47
  47. langchain_core/messages/block_translators/__init__.py +111 -0
  48. langchain_core/messages/block_translators/anthropic.py +470 -0
  49. langchain_core/messages/block_translators/bedrock.py +94 -0
  50. langchain_core/messages/block_translators/bedrock_converse.py +297 -0
  51. langchain_core/messages/block_translators/google_genai.py +530 -0
  52. langchain_core/messages/block_translators/google_vertexai.py +21 -0
  53. langchain_core/messages/block_translators/groq.py +143 -0
  54. langchain_core/messages/block_translators/langchain_v0.py +301 -0
  55. langchain_core/messages/block_translators/openai.py +1010 -0
  56. langchain_core/messages/chat.py +2 -3
  57. langchain_core/messages/content.py +1423 -0
  58. langchain_core/messages/function.py +7 -7
  59. langchain_core/messages/human.py +44 -38
  60. langchain_core/messages/modifier.py +3 -2
  61. langchain_core/messages/system.py +40 -27
  62. langchain_core/messages/tool.py +160 -58
  63. langchain_core/messages/utils.py +527 -638
  64. langchain_core/output_parsers/__init__.py +1 -14
  65. langchain_core/output_parsers/base.py +68 -104
  66. langchain_core/output_parsers/json.py +13 -17
  67. langchain_core/output_parsers/list.py +11 -33
  68. langchain_core/output_parsers/openai_functions.py +56 -74
  69. langchain_core/output_parsers/openai_tools.py +68 -109
  70. langchain_core/output_parsers/pydantic.py +15 -13
  71. langchain_core/output_parsers/string.py +6 -2
  72. langchain_core/output_parsers/transform.py +17 -60
  73. langchain_core/output_parsers/xml.py +34 -44
  74. langchain_core/outputs/__init__.py +1 -1
  75. langchain_core/outputs/chat_generation.py +26 -11
  76. langchain_core/outputs/chat_result.py +1 -3
  77. langchain_core/outputs/generation.py +17 -6
  78. langchain_core/outputs/llm_result.py +15 -8
  79. langchain_core/prompt_values.py +29 -123
  80. langchain_core/prompts/__init__.py +3 -27
  81. langchain_core/prompts/base.py +48 -63
  82. langchain_core/prompts/chat.py +259 -288
  83. langchain_core/prompts/dict.py +19 -11
  84. langchain_core/prompts/few_shot.py +84 -90
  85. langchain_core/prompts/few_shot_with_templates.py +14 -12
  86. langchain_core/prompts/image.py +19 -14
  87. langchain_core/prompts/loading.py +6 -8
  88. langchain_core/prompts/message.py +7 -8
  89. langchain_core/prompts/prompt.py +42 -43
  90. langchain_core/prompts/string.py +37 -16
  91. langchain_core/prompts/structured.py +43 -46
  92. langchain_core/rate_limiters.py +51 -60
  93. langchain_core/retrievers.py +52 -192
  94. langchain_core/runnables/base.py +1727 -1683
  95. langchain_core/runnables/branch.py +52 -73
  96. langchain_core/runnables/config.py +89 -103
  97. langchain_core/runnables/configurable.py +128 -130
  98. langchain_core/runnables/fallbacks.py +93 -82
  99. langchain_core/runnables/graph.py +127 -127
  100. langchain_core/runnables/graph_ascii.py +63 -41
  101. langchain_core/runnables/graph_mermaid.py +87 -70
  102. langchain_core/runnables/graph_png.py +31 -36
  103. langchain_core/runnables/history.py +145 -161
  104. langchain_core/runnables/passthrough.py +141 -144
  105. langchain_core/runnables/retry.py +84 -68
  106. langchain_core/runnables/router.py +33 -37
  107. langchain_core/runnables/schema.py +79 -72
  108. langchain_core/runnables/utils.py +95 -139
  109. langchain_core/stores.py +85 -131
  110. langchain_core/structured_query.py +11 -15
  111. langchain_core/sys_info.py +31 -32
  112. langchain_core/tools/__init__.py +1 -14
  113. langchain_core/tools/base.py +221 -247
  114. langchain_core/tools/convert.py +144 -161
  115. langchain_core/tools/render.py +10 -10
  116. langchain_core/tools/retriever.py +12 -19
  117. langchain_core/tools/simple.py +52 -29
  118. langchain_core/tools/structured.py +56 -60
  119. langchain_core/tracers/__init__.py +1 -9
  120. langchain_core/tracers/_streaming.py +6 -7
  121. langchain_core/tracers/base.py +103 -112
  122. langchain_core/tracers/context.py +29 -48
  123. langchain_core/tracers/core.py +142 -105
  124. langchain_core/tracers/evaluation.py +30 -34
  125. langchain_core/tracers/event_stream.py +162 -117
  126. langchain_core/tracers/langchain.py +34 -36
  127. langchain_core/tracers/log_stream.py +87 -49
  128. langchain_core/tracers/memory_stream.py +3 -3
  129. langchain_core/tracers/root_listeners.py +18 -34
  130. langchain_core/tracers/run_collector.py +8 -20
  131. langchain_core/tracers/schemas.py +0 -125
  132. langchain_core/tracers/stdout.py +3 -3
  133. langchain_core/utils/__init__.py +1 -4
  134. langchain_core/utils/_merge.py +47 -9
  135. langchain_core/utils/aiter.py +70 -66
  136. langchain_core/utils/env.py +12 -9
  137. langchain_core/utils/function_calling.py +139 -206
  138. langchain_core/utils/html.py +7 -8
  139. langchain_core/utils/input.py +6 -6
  140. langchain_core/utils/interactive_env.py +6 -2
  141. langchain_core/utils/iter.py +48 -45
  142. langchain_core/utils/json.py +14 -4
  143. langchain_core/utils/json_schema.py +159 -43
  144. langchain_core/utils/mustache.py +32 -25
  145. langchain_core/utils/pydantic.py +67 -40
  146. langchain_core/utils/strings.py +5 -5
  147. langchain_core/utils/usage.py +1 -1
  148. langchain_core/utils/utils.py +104 -62
  149. langchain_core/vectorstores/base.py +131 -179
  150. langchain_core/vectorstores/in_memory.py +113 -182
  151. langchain_core/vectorstores/utils.py +23 -17
  152. langchain_core/version.py +1 -1
  153. langchain_core-1.0.0.dist-info/METADATA +68 -0
  154. langchain_core-1.0.0.dist-info/RECORD +172 -0
  155. {langchain_core-0.4.0.dev0.dist-info → langchain_core-1.0.0.dist-info}/WHEEL +1 -1
  156. langchain_core/beta/__init__.py +0 -1
  157. langchain_core/beta/runnables/__init__.py +0 -1
  158. langchain_core/beta/runnables/context.py +0 -448
  159. langchain_core/memory.py +0 -116
  160. langchain_core/messages/content_blocks.py +0 -1435
  161. langchain_core/prompts/pipeline.py +0 -133
  162. langchain_core/pydantic_v1/__init__.py +0 -30
  163. langchain_core/pydantic_v1/dataclasses.py +0 -23
  164. langchain_core/pydantic_v1/main.py +0 -23
  165. langchain_core/tracers/langchain_v1.py +0 -23
  166. langchain_core/utils/loading.py +0 -31
  167. langchain_core/v1/__init__.py +0 -1
  168. langchain_core/v1/chat_models.py +0 -1047
  169. langchain_core/v1/messages.py +0 -755
  170. langchain_core-0.4.0.dev0.dist-info/METADATA +0 -108
  171. langchain_core-0.4.0.dev0.dist-info/RECORD +0 -177
  172. langchain_core-0.4.0.dev0.dist-info/entry_points.txt +0 -4
langchain_core/globals.py CHANGED
@@ -1,6 +1,5 @@
1
1
  """Global values and configuration that apply to all of LangChain."""
2
2
 
3
- import warnings
4
3
  from typing import TYPE_CHECKING, Optional
5
4
 
6
5
  if TYPE_CHECKING:
@@ -22,30 +21,6 @@ def set_verbose(value: bool) -> None: # noqa: FBT001
22
21
  Args:
23
22
  value: The new value for the `verbose` global setting.
24
23
  """
25
- try:
26
- import langchain # type: ignore[import-not-found]
27
-
28
- # We're about to run some deprecated code, don't report warnings from it.
29
- # The user called the correct (non-deprecated) code path and shouldn't get
30
- # warnings.
31
- with warnings.catch_warnings():
32
- warnings.filterwarnings(
33
- "ignore",
34
- message=(
35
- "Importing verbose from langchain root module "
36
- "is no longer supported"
37
- ),
38
- )
39
- # N.B.: This is a workaround for an unfortunate quirk of Python's
40
- # module-level `__getattr__()` implementation:
41
- # https://github.com/langchain-ai/langchain/pull/11311#issuecomment-1743780004
42
- #
43
- # Remove it once `langchain.verbose` is no longer supported, and once all
44
- # users have migrated to using `set_verbose()` here.
45
- langchain.verbose = value
46
- except ImportError:
47
- pass
48
-
49
24
  global _verbose # noqa: PLW0603
50
25
  _verbose = value
51
26
 
@@ -56,37 +31,7 @@ def get_verbose() -> bool:
56
31
  Returns:
57
32
  The value of the `verbose` global setting.
58
33
  """
59
- try:
60
- import langchain
61
-
62
- # We're about to run some deprecated code, don't report warnings from it.
63
- # The user called the correct (non-deprecated) code path and shouldn't get
64
- # warnings.
65
- with warnings.catch_warnings():
66
- warnings.filterwarnings(
67
- "ignore",
68
- message=(
69
- ".*Importing verbose from langchain root module "
70
- "is no longer supported"
71
- ),
72
- )
73
- # N.B.: This is a workaround for an unfortunate quirk of Python's
74
- # module-level `__getattr__()` implementation:
75
- # https://github.com/langchain-ai/langchain/pull/11311#issuecomment-1743780004
76
- #
77
- # Remove it once `langchain.verbose` is no longer supported, and once all
78
- # users have migrated to using `set_verbose()` here.
79
- #
80
- # In the meantime, the `verbose` setting is considered True if either the
81
- # old or the new value are True. This accommodates users who haven't
82
- # migrated to using `set_verbose()` yet. Those users are getting
83
- # deprecation warnings directing them to use `set_verbose()` when they
84
- # import `langchain.verbose`.
85
- old_verbose = langchain.verbose
86
- except ImportError:
87
- old_verbose = False
88
-
89
- return _verbose or old_verbose
34
+ return _verbose
90
35
 
91
36
 
92
37
  def set_debug(value: bool) -> None: # noqa: FBT001
@@ -95,28 +40,6 @@ def set_debug(value: bool) -> None: # noqa: FBT001
95
40
  Args:
96
41
  value: The new value for the `debug` global setting.
97
42
  """
98
- try:
99
- import langchain
100
-
101
- # We're about to run some deprecated code, don't report warnings from it.
102
- # The user called the correct (non-deprecated) code path and shouldn't get
103
- # warnings.
104
- with warnings.catch_warnings():
105
- warnings.filterwarnings(
106
- "ignore",
107
- message="Importing debug from langchain root module "
108
- "is no longer supported",
109
- )
110
- # N.B.: This is a workaround for an unfortunate quirk of Python's
111
- # module-level `__getattr__()` implementation:
112
- # https://github.com/langchain-ai/langchain/pull/11311#issuecomment-1743780004
113
- #
114
- # Remove it once `langchain.debug` is no longer supported, and once all
115
- # users have migrated to using `set_debug()` here.
116
- langchain.debug = value
117
- except ImportError:
118
- pass
119
-
120
43
  global _debug # noqa: PLW0603
121
44
  _debug = value
122
45
 
@@ -127,34 +50,7 @@ def get_debug() -> bool:
127
50
  Returns:
128
51
  The value of the `debug` global setting.
129
52
  """
130
- try:
131
- import langchain
132
-
133
- # We're about to run some deprecated code, don't report warnings from it.
134
- # The user called the correct (non-deprecated) code path and shouldn't get
135
- # warnings.
136
- with warnings.catch_warnings():
137
- warnings.filterwarnings(
138
- "ignore",
139
- message="Importing debug from langchain root module "
140
- "is no longer supported",
141
- )
142
- # N.B.: This is a workaround for an unfortunate quirk of Python's
143
- # module-level `__getattr__()` implementation:
144
- # https://github.com/langchain-ai/langchain/pull/11311#issuecomment-1743780004
145
- #
146
- # Remove it once `langchain.debug` is no longer supported, and once all
147
- # users have migrated to using `set_debug()` here.
148
- #
149
- # In the meantime, the `debug` setting is considered True if either the old
150
- # or the new value are True. This accommodates users who haven't migrated
151
- # to using `set_debug()` yet. Those users are getting deprecation warnings
152
- # directing them to use `set_debug()` when they import `langchain.debug`.
153
- old_debug = langchain.debug
154
- except ImportError:
155
- old_debug = False
156
-
157
- return _debug or old_debug
53
+ return _debug
158
54
 
159
55
 
160
56
  def set_llm_cache(value: Optional["BaseCache"]) -> None:
@@ -163,69 +59,14 @@ def set_llm_cache(value: Optional["BaseCache"]) -> None:
163
59
  Args:
164
60
  value: The new LLM cache to use. If `None`, the LLM cache is disabled.
165
61
  """
166
- try:
167
- import langchain
168
-
169
- # We're about to run some deprecated code, don't report warnings from it.
170
- # The user called the correct (non-deprecated) code path and shouldn't get
171
- # warnings.
172
- with warnings.catch_warnings():
173
- warnings.filterwarnings(
174
- "ignore",
175
- message=(
176
- "Importing llm_cache from langchain root module "
177
- "is no longer supported"
178
- ),
179
- )
180
- # N.B.: This is a workaround for an unfortunate quirk of Python's
181
- # module-level `__getattr__()` implementation:
182
- # https://github.com/langchain-ai/langchain/pull/11311#issuecomment-1743780004
183
- #
184
- # Remove it once `langchain.llm_cache` is no longer supported, and
185
- # once all users have migrated to using `set_llm_cache()` here.
186
- langchain.llm_cache = value
187
- except ImportError:
188
- pass
189
-
190
62
  global _llm_cache # noqa: PLW0603
191
63
  _llm_cache = value
192
64
 
193
65
 
194
- def get_llm_cache() -> "BaseCache":
66
+ def get_llm_cache() -> Optional["BaseCache"]:
195
67
  """Get the value of the `llm_cache` global setting.
196
68
 
197
69
  Returns:
198
70
  The value of the `llm_cache` global setting.
199
71
  """
200
- try:
201
- import langchain
202
-
203
- # We're about to run some deprecated code, don't report warnings from it.
204
- # The user called the correct (non-deprecated) code path and shouldn't get
205
- # warnings.
206
- with warnings.catch_warnings():
207
- warnings.filterwarnings(
208
- "ignore",
209
- message=(
210
- "Importing llm_cache from langchain root module "
211
- "is no longer supported"
212
- ),
213
- )
214
- # N.B.: This is a workaround for an unfortunate quirk of Python's
215
- # module-level `__getattr__()` implementation:
216
- # https://github.com/langchain-ai/langchain/pull/11311#issuecomment-1743780004
217
- #
218
- # Remove it once `langchain.llm_cache` is no longer supported, and
219
- # once all users have migrated to using `set_llm_cache()` here.
220
- #
221
- # In the meantime, the `llm_cache` setting returns whichever of
222
- # its two backing sources is truthy (not `None` and non-empty),
223
- # or the old value if both are falsy. This accommodates users
224
- # who haven't migrated to using `set_llm_cache()` yet.
225
- # Those users are getting deprecation warnings directing them
226
- # to use `set_llm_cache()` when they import `langchain.llm_cache`.
227
- old_llm_cache = langchain.llm_cache
228
- except ImportError:
229
- old_llm_cache = None
230
-
231
- return _llm_cache or old_llm_cache
72
+ return _llm_cache