langchain-core 0.3.75__py3-none-any.whl → 0.3.76__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 (116) hide show
  1. langchain_core/_api/beta_decorator.py +17 -40
  2. langchain_core/_api/deprecation.py +19 -6
  3. langchain_core/_api/path.py +19 -2
  4. langchain_core/_import_utils.py +7 -0
  5. langchain_core/agents.py +10 -6
  6. langchain_core/beta/runnables/context.py +1 -2
  7. langchain_core/callbacks/base.py +11 -4
  8. langchain_core/callbacks/manager.py +81 -69
  9. langchain_core/callbacks/usage.py +4 -2
  10. langchain_core/chat_history.py +4 -6
  11. langchain_core/document_loaders/base.py +34 -9
  12. langchain_core/document_loaders/langsmith.py +3 -0
  13. langchain_core/documents/base.py +35 -10
  14. langchain_core/documents/transformers.py +4 -2
  15. langchain_core/embeddings/fake.py +8 -5
  16. langchain_core/env.py +2 -3
  17. langchain_core/example_selectors/base.py +12 -0
  18. langchain_core/exceptions.py +7 -0
  19. langchain_core/globals.py +17 -28
  20. langchain_core/indexing/api.py +56 -44
  21. langchain_core/indexing/base.py +5 -8
  22. langchain_core/indexing/in_memory.py +23 -3
  23. langchain_core/language_models/__init__.py +3 -2
  24. langchain_core/language_models/base.py +31 -20
  25. langchain_core/language_models/chat_models.py +94 -25
  26. langchain_core/language_models/fake_chat_models.py +5 -7
  27. langchain_core/language_models/llms.py +49 -17
  28. langchain_core/load/dump.py +2 -3
  29. langchain_core/load/load.py +15 -1
  30. langchain_core/load/serializable.py +38 -43
  31. langchain_core/memory.py +7 -3
  32. langchain_core/messages/ai.py +36 -19
  33. langchain_core/messages/base.py +13 -6
  34. langchain_core/messages/content_blocks.py +23 -2
  35. langchain_core/messages/human.py +2 -6
  36. langchain_core/messages/system.py +2 -6
  37. langchain_core/messages/tool.py +33 -13
  38. langchain_core/messages/utils.py +182 -72
  39. langchain_core/output_parsers/base.py +5 -2
  40. langchain_core/output_parsers/json.py +4 -4
  41. langchain_core/output_parsers/list.py +7 -22
  42. langchain_core/output_parsers/openai_functions.py +3 -0
  43. langchain_core/output_parsers/openai_tools.py +6 -1
  44. langchain_core/output_parsers/pydantic.py +4 -0
  45. langchain_core/output_parsers/string.py +5 -1
  46. langchain_core/output_parsers/xml.py +19 -19
  47. langchain_core/outputs/chat_generation.py +18 -7
  48. langchain_core/outputs/generation.py +14 -3
  49. langchain_core/outputs/llm_result.py +8 -1
  50. langchain_core/prompt_values.py +10 -4
  51. langchain_core/prompts/base.py +4 -9
  52. langchain_core/prompts/chat.py +87 -58
  53. langchain_core/prompts/dict.py +16 -8
  54. langchain_core/prompts/few_shot.py +9 -11
  55. langchain_core/prompts/few_shot_with_templates.py +5 -1
  56. langchain_core/prompts/image.py +12 -5
  57. langchain_core/prompts/message.py +5 -6
  58. langchain_core/prompts/pipeline.py +13 -8
  59. langchain_core/prompts/prompt.py +22 -8
  60. langchain_core/prompts/string.py +18 -10
  61. langchain_core/prompts/structured.py +7 -2
  62. langchain_core/rate_limiters.py +2 -2
  63. langchain_core/retrievers.py +7 -6
  64. langchain_core/runnables/base.py +402 -183
  65. langchain_core/runnables/branch.py +14 -19
  66. langchain_core/runnables/config.py +9 -15
  67. langchain_core/runnables/configurable.py +34 -19
  68. langchain_core/runnables/fallbacks.py +20 -13
  69. langchain_core/runnables/graph.py +44 -37
  70. langchain_core/runnables/graph_ascii.py +40 -17
  71. langchain_core/runnables/graph_mermaid.py +27 -15
  72. langchain_core/runnables/graph_png.py +27 -31
  73. langchain_core/runnables/history.py +55 -58
  74. langchain_core/runnables/passthrough.py +44 -21
  75. langchain_core/runnables/retry.py +9 -5
  76. langchain_core/runnables/router.py +9 -8
  77. langchain_core/runnables/schema.py +2 -0
  78. langchain_core/runnables/utils.py +51 -89
  79. langchain_core/stores.py +13 -25
  80. langchain_core/sys_info.py +9 -8
  81. langchain_core/tools/base.py +30 -23
  82. langchain_core/tools/convert.py +24 -13
  83. langchain_core/tools/simple.py +35 -3
  84. langchain_core/tools/structured.py +25 -2
  85. langchain_core/tracers/base.py +2 -2
  86. langchain_core/tracers/context.py +5 -1
  87. langchain_core/tracers/core.py +109 -39
  88. langchain_core/tracers/evaluation.py +22 -26
  89. langchain_core/tracers/event_stream.py +40 -27
  90. langchain_core/tracers/langchain.py +12 -3
  91. langchain_core/tracers/langchain_v1.py +10 -2
  92. langchain_core/tracers/log_stream.py +56 -17
  93. langchain_core/tracers/root_listeners.py +4 -20
  94. langchain_core/tracers/run_collector.py +6 -16
  95. langchain_core/tracers/schemas.py +5 -1
  96. langchain_core/utils/aiter.py +14 -6
  97. langchain_core/utils/env.py +3 -0
  98. langchain_core/utils/function_calling.py +37 -20
  99. langchain_core/utils/interactive_env.py +6 -2
  100. langchain_core/utils/iter.py +11 -3
  101. langchain_core/utils/json.py +5 -2
  102. langchain_core/utils/json_schema.py +15 -5
  103. langchain_core/utils/loading.py +5 -1
  104. langchain_core/utils/mustache.py +24 -15
  105. langchain_core/utils/pydantic.py +32 -4
  106. langchain_core/utils/utils.py +24 -8
  107. langchain_core/vectorstores/base.py +7 -20
  108. langchain_core/vectorstores/in_memory.py +18 -12
  109. langchain_core/vectorstores/utils.py +18 -12
  110. langchain_core/version.py +1 -1
  111. langchain_core-0.3.76.dist-info/METADATA +77 -0
  112. langchain_core-0.3.76.dist-info/RECORD +174 -0
  113. langchain_core-0.3.75.dist-info/METADATA +0 -106
  114. langchain_core-0.3.75.dist-info/RECORD +0 -174
  115. {langchain_core-0.3.75.dist-info → langchain_core-0.3.76.dist-info}/WHEEL +0 -0
  116. {langchain_core-0.3.75.dist-info → langchain_core-0.3.76.dist-info}/entry_points.txt +0 -0
@@ -68,8 +68,11 @@ class StructuredPrompt(ChatPromptTemplate):
68
68
  def get_lc_namespace(cls) -> list[str]:
69
69
  """Get the namespace of the langchain object.
70
70
 
71
- For example, if the class is `langchain.llms.openai.OpenAI`, then the
72
- namespace is ["langchain", "llms", "openai"]
71
+ For example, if the class is ``langchain.llms.openai.OpenAI``, then the
72
+ namespace is ``["langchain", "llms", "openai"]``
73
+
74
+ Returns:
75
+ The namespace of the langchain object.
73
76
  """
74
77
  return cls.__module__.split(".")
75
78
 
@@ -89,10 +92,12 @@ class StructuredPrompt(ChatPromptTemplate):
89
92
 
90
93
  from langchain_core.prompts import StructuredPrompt
91
94
 
95
+
92
96
  class OutputSchema(BaseModel):
93
97
  name: str
94
98
  value: int
95
99
 
100
+
96
101
  template = StructuredPrompt(
97
102
  [
98
103
  ("human", "Hello, how are you?"),
@@ -110,9 +110,9 @@ class InMemoryRateLimiter(BaseRateLimiter):
110
110
  )
111
111
 
112
112
  from langchain_anthropic import ChatAnthropic
113
+
113
114
  model = ChatAnthropic(
114
- model_name="claude-3-opus-20240229",
115
- rate_limiter=rate_limiter
115
+ model_name="claude-3-opus-20240229", rate_limiter=rate_limiter
116
116
  )
117
117
 
118
118
  for _ in range(5):
@@ -31,6 +31,7 @@ from typing_extensions import Self, TypedDict, override
31
31
 
32
32
  from langchain_core._api import deprecated
33
33
  from langchain_core.callbacks import Callbacks
34
+ from langchain_core.callbacks.manager import AsyncCallbackManager, CallbackManager
34
35
  from langchain_core.documents import Document
35
36
  from langchain_core.runnables import (
36
37
  Runnable,
@@ -109,6 +110,7 @@ class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
109
110
 
110
111
  from sklearn.metrics.pairwise import cosine_similarity
111
112
 
113
+
112
114
  class TFIDFRetriever(BaseRetriever, BaseModel):
113
115
  vectorizer: Any
114
116
  docs: list[Document]
@@ -122,10 +124,12 @@ class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
122
124
  # Ip -- (n_docs,x), Op -- (n_docs,n_Feats)
123
125
  query_vec = self.vectorizer.transform([query])
124
126
  # Op -- (n_docs,1) -- Cosine Sim with each doc
125
- results = cosine_similarity(self.tfidf_array, query_vec).reshape((-1,))
127
+ results = cosine_similarity(self.tfidf_array, query_vec).reshape(
128
+ (-1,)
129
+ )
126
130
  return [self.docs[i] for i in results.argsort()[-self.k :][::-1]]
127
131
 
128
- """ # noqa: E501
132
+ """
129
133
 
130
134
  model_config = ConfigDict(
131
135
  arbitrary_types_allowed=True,
@@ -233,8 +237,6 @@ class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
233
237
  retriever.invoke("query")
234
238
 
235
239
  """
236
- from langchain_core.callbacks.manager import CallbackManager
237
-
238
240
  config = ensure_config(config)
239
241
  inheritable_metadata = {
240
242
  **(config.get("metadata") or {}),
@@ -298,8 +300,6 @@ class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
298
300
  await retriever.ainvoke("query")
299
301
 
300
302
  """
301
- from langchain_core.callbacks.manager import AsyncCallbackManager
302
-
303
303
  config = ensure_config(config)
304
304
  inheritable_metadata = {
305
305
  **(config.get("metadata") or {}),
@@ -359,6 +359,7 @@ class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
359
359
  Args:
360
360
  query: String to find relevant documents for
361
361
  run_manager: The callback handler to use
362
+
362
363
  Returns:
363
364
  List of relevant documents
364
365
  """