langchain 0.2.12__py3-none-any.whl → 0.2.14__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.
Files changed (98) hide show
  1. langchain/_api/module_import.py +2 -2
  2. langchain/agents/__init__.py +4 -3
  3. langchain/agents/agent.py +7 -11
  4. langchain/agents/agent_toolkits/__init__.py +1 -1
  5. langchain/agents/agent_toolkits/vectorstore/base.py +114 -2
  6. langchain/agents/agent_toolkits/vectorstore/toolkit.py +2 -7
  7. langchain/agents/agent_types.py +1 -1
  8. langchain/agents/chat/base.py +1 -1
  9. langchain/agents/conversational/base.py +1 -1
  10. langchain/agents/conversational_chat/base.py +1 -1
  11. langchain/agents/initialize.py +2 -2
  12. langchain/agents/json_chat/base.py +1 -1
  13. langchain/agents/loading.py +4 -4
  14. langchain/agents/mrkl/base.py +4 -4
  15. langchain/agents/openai_assistant/base.py +2 -2
  16. langchain/agents/openai_functions_agent/base.py +2 -2
  17. langchain/agents/openai_functions_multi_agent/base.py +2 -2
  18. langchain/agents/react/agent.py +1 -1
  19. langchain/agents/react/base.py +4 -4
  20. langchain/agents/self_ask_with_search/base.py +2 -2
  21. langchain/agents/structured_chat/base.py +3 -2
  22. langchain/agents/tools.py +2 -2
  23. langchain/agents/xml/base.py +2 -2
  24. langchain/chains/__init__.py +1 -0
  25. langchain/chains/api/base.py +121 -1
  26. langchain/chains/base.py +5 -7
  27. langchain/chains/combine_documents/map_reduce.py +2 -4
  28. langchain/chains/combine_documents/map_rerank.py +4 -6
  29. langchain/chains/combine_documents/reduce.py +1 -4
  30. langchain/chains/combine_documents/refine.py +2 -4
  31. langchain/chains/combine_documents/stuff.py +12 -4
  32. langchain/chains/conversation/base.py +2 -4
  33. langchain/chains/conversational_retrieval/base.py +5 -7
  34. langchain/chains/elasticsearch_database/base.py +16 -20
  35. langchain/chains/example_generator.py +3 -4
  36. langchain/chains/flare/base.py +1 -1
  37. langchain/chains/hyde/base.py +1 -4
  38. langchain/chains/llm.py +2 -4
  39. langchain/chains/llm_checker/base.py +12 -4
  40. langchain/chains/llm_math/base.py +2 -4
  41. langchain/chains/llm_summarization_checker/base.py +12 -4
  42. langchain/chains/loading.py +17 -0
  43. langchain/chains/mapreduce.py +12 -4
  44. langchain/chains/natbot/base.py +2 -4
  45. langchain/chains/openai_functions/__init__.py +2 -0
  46. langchain/chains/openai_functions/base.py +2 -2
  47. langchain/chains/openai_functions/citation_fuzzy_match.py +54 -1
  48. langchain/chains/openai_functions/extraction.py +2 -2
  49. langchain/chains/openai_functions/openapi.py +88 -1
  50. langchain/chains/openai_functions/qa_with_structure.py +19 -0
  51. langchain/chains/openai_functions/tagging.py +81 -0
  52. langchain/chains/openai_tools/extraction.py +1 -1
  53. langchain/chains/qa_with_sources/base.py +21 -4
  54. langchain/chains/qa_with_sources/loading.py +16 -0
  55. langchain/chains/query_constructor/base.py +8 -2
  56. langchain/chains/query_constructor/schema.py +0 -2
  57. langchain/chains/question_answering/chain.py +15 -0
  58. langchain/chains/retrieval_qa/base.py +30 -6
  59. langchain/chains/router/base.py +1 -4
  60. langchain/chains/router/embedding_router.py +1 -4
  61. langchain/chains/router/llm_router.py +76 -1
  62. langchain/chains/router/multi_prompt.py +76 -1
  63. langchain/chains/sequential.py +3 -7
  64. langchain/chains/structured_output/base.py +3 -3
  65. langchain/chat_models/base.py +8 -10
  66. langchain/evaluation/agents/trajectory_eval_chain.py +2 -4
  67. langchain/evaluation/comparison/eval_chain.py +2 -4
  68. langchain/evaluation/criteria/eval_chain.py +2 -4
  69. langchain/evaluation/embedding_distance/base.py +0 -2
  70. langchain/evaluation/parsing/json_schema.py +1 -1
  71. langchain/evaluation/qa/eval_chain.py +2 -7
  72. langchain/evaluation/schema.py +8 -8
  73. langchain/evaluation/scoring/eval_chain.py +2 -4
  74. langchain/evaluation/string_distance/base.py +4 -4
  75. langchain/hub.py +60 -26
  76. langchain/indexes/vectorstore.py +3 -7
  77. langchain/memory/entity.py +0 -2
  78. langchain/memory/summary.py +9 -0
  79. langchain/output_parsers/retry.py +1 -1
  80. langchain/retrievers/contextual_compression.py +0 -2
  81. langchain/retrievers/document_compressors/base.py +0 -2
  82. langchain/retrievers/document_compressors/chain_filter.py +1 -1
  83. langchain/retrievers/document_compressors/cohere_rerank.py +3 -5
  84. langchain/retrievers/document_compressors/cross_encoder_rerank.py +1 -4
  85. langchain/retrievers/document_compressors/embeddings_filter.py +0 -2
  86. langchain/retrievers/document_compressors/listwise_rerank.py +1 -1
  87. langchain/retrievers/multi_query.py +4 -2
  88. langchain/retrievers/re_phraser.py +1 -1
  89. langchain/retrievers/self_query/base.py +1 -3
  90. langchain/retrievers/time_weighted_retriever.py +0 -2
  91. langchain/tools/__init__.py +14 -5
  92. langchain/tools/render.py +0 -2
  93. langchain/tools/retriever.py +0 -4
  94. {langchain-0.2.12.dist-info → langchain-0.2.14.dist-info}/METADATA +2 -2
  95. {langchain-0.2.12.dist-info → langchain-0.2.14.dist-info}/RECORD +98 -98
  96. {langchain-0.2.12.dist-info → langchain-0.2.14.dist-info}/LICENSE +0 -0
  97. {langchain-0.2.12.dist-info → langchain-0.2.14.dist-info}/WHEEL +0 -0
  98. {langchain-0.2.12.dist-info → langchain-0.2.14.dist-info}/entry_points.txt +0 -0
@@ -9,7 +9,5 @@ class AttributeInfo(BaseModel):
9
9
  type: str
10
10
 
11
11
  class Config:
12
- """Configuration for this pydantic object."""
13
-
14
12
  arbitrary_types_allowed = True
15
13
  frozen = True
@@ -2,6 +2,7 @@
2
2
 
3
3
  from typing import Any, Mapping, Optional, Protocol
4
4
 
5
+ from langchain_core._api import deprecated
5
6
  from langchain_core.callbacks import BaseCallbackManager, Callbacks
6
7
  from langchain_core.language_models import BaseLanguageModel
7
8
  from langchain_core.prompts import BasePromptTemplate
@@ -216,6 +217,20 @@ def _load_refine_chain(
216
217
  )
217
218
 
218
219
 
220
+ @deprecated(
221
+ since="0.2.13",
222
+ removal="1.0",
223
+ message=(
224
+ "This class is deprecated. See the following migration guides for replacements "
225
+ "based on `chain_type`:\n"
226
+ "stuff: https://python.langchain.com/v0.2/docs/versions/migrating_chains/stuff_docs_chain\n" # noqa: E501
227
+ "map_reduce: https://python.langchain.com/v0.2/docs/versions/migrating_chains/map_reduce_chain\n" # noqa: E501
228
+ "refine: https://python.langchain.com/v0.2/docs/versions/migrating_chains/refine_chain\n" # noqa: E501
229
+ "map_rerank: https://python.langchain.com/v0.2/docs/versions/migrating_chains/map_rerank_docs_chain\n" # noqa: E501
230
+ "\nSee also guides on retrieval and question-answering here: "
231
+ "https://python.langchain.com/v0.2/docs/how_to/#qa-with-rag"
232
+ ),
233
+ )
219
234
  def load_qa_chain(
220
235
  llm: BaseLanguageModel,
221
236
  chain_type: str = "stuff",
@@ -16,7 +16,7 @@ from langchain_core.callbacks import (
16
16
  from langchain_core.documents import Document
17
17
  from langchain_core.language_models import BaseLanguageModel
18
18
  from langchain_core.prompts import PromptTemplate
19
- from langchain_core.pydantic_v1 import Extra, Field, root_validator
19
+ from langchain_core.pydantic_v1 import Field, root_validator
20
20
  from langchain_core.retrievers import BaseRetriever
21
21
  from langchain_core.vectorstores import VectorStore
22
22
 
@@ -28,6 +28,15 @@ from langchain.chains.question_answering import load_qa_chain
28
28
  from langchain.chains.question_answering.stuff_prompt import PROMPT_SELECTOR
29
29
 
30
30
 
31
+ @deprecated(
32
+ since="0.2.13",
33
+ removal="1.0",
34
+ message=(
35
+ "This class is deprecated. Use the `create_retrieval_chain` constructor "
36
+ "instead. See migration guide here: "
37
+ "https://python.langchain.com/v0.2/docs/versions/migrating_chains/retrieval_qa/"
38
+ ),
39
+ )
31
40
  class BaseRetrievalQA(Chain):
32
41
  """Base class for question-answering chains."""
33
42
 
@@ -39,11 +48,9 @@ class BaseRetrievalQA(Chain):
39
48
  """Return the source documents or not."""
40
49
 
41
50
  class Config:
42
- """Configuration for this pydantic object."""
43
-
44
- extra = Extra.forbid
45
- arbitrary_types_allowed = True
46
51
  allow_population_by_field_name = True
52
+ arbitrary_types_allowed = True
53
+ extra = "forbid"
47
54
 
48
55
  @property
49
56
  def input_keys(self) -> List[str]:
@@ -196,7 +203,15 @@ class BaseRetrievalQA(Chain):
196
203
  return {self.output_key: answer}
197
204
 
198
205
 
199
- @deprecated(since="0.1.17", alternative="create_retrieval_chain", removal="0.3.0")
206
+ @deprecated(
207
+ since="0.1.17",
208
+ removal="1.0",
209
+ message=(
210
+ "This class is deprecated. Use the `create_retrieval_chain` constructor "
211
+ "instead. See migration guide here: "
212
+ "https://python.langchain.com/v0.2/docs/versions/migrating_chains/retrieval_qa/"
213
+ ),
214
+ )
200
215
  class RetrievalQA(BaseRetrievalQA):
201
216
  """Chain for question-answering against an index.
202
217
 
@@ -273,6 +288,15 @@ class RetrievalQA(BaseRetrievalQA):
273
288
  return "retrieval_qa"
274
289
 
275
290
 
291
+ @deprecated(
292
+ since="0.2.13",
293
+ removal="1.0",
294
+ message=(
295
+ "This class is deprecated. Use the `create_retrieval_chain` constructor "
296
+ "instead. See migration guide here: "
297
+ "https://python.langchain.com/v0.2/docs/versions/migrating_chains/retrieval_qa/"
298
+ ),
299
+ )
276
300
  class VectorDBQA(BaseRetrievalQA):
277
301
  """Chain for question-answering against a vector database."""
278
302
 
@@ -10,7 +10,6 @@ from langchain_core.callbacks import (
10
10
  CallbackManagerForChainRun,
11
11
  Callbacks,
12
12
  )
13
- from langchain_core.pydantic_v1 import Extra
14
13
 
15
14
  from langchain.chains.base import Chain
16
15
 
@@ -62,10 +61,8 @@ class MultiRouteChain(Chain):
62
61
  Defaults to False."""
63
62
 
64
63
  class Config:
65
- """Configuration for this pydantic object."""
66
-
67
- extra = Extra.forbid
68
64
  arbitrary_types_allowed = True
65
+ extra = "forbid"
69
66
 
70
67
  @property
71
68
  def input_keys(self) -> List[str]:
@@ -8,7 +8,6 @@ from langchain_core.callbacks import (
8
8
  )
9
9
  from langchain_core.documents import Document
10
10
  from langchain_core.embeddings import Embeddings
11
- from langchain_core.pydantic_v1 import Extra
12
11
  from langchain_core.vectorstores import VectorStore
13
12
 
14
13
  from langchain.chains.router.base import RouterChain
@@ -21,10 +20,8 @@ class EmbeddingRouterChain(RouterChain):
21
20
  routing_keys: List[str] = ["query"]
22
21
 
23
22
  class Config:
24
- """Configuration for this pydantic object."""
25
-
26
- extra = Extra.forbid
27
23
  arbitrary_types_allowed = True
24
+ extra = "forbid"
28
25
 
29
26
  @property
30
27
  def input_keys(self) -> List[str]:
@@ -4,6 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  from typing import Any, Dict, List, Optional, Type, cast
6
6
 
7
+ from langchain_core._api import deprecated
7
8
  from langchain_core.callbacks import (
8
9
  AsyncCallbackManagerForChainRun,
9
10
  CallbackManagerForChainRun,
@@ -19,8 +20,82 @@ from langchain.chains import LLMChain
19
20
  from langchain.chains.router.base import RouterChain
20
21
 
21
22
 
23
+ @deprecated(
24
+ since="0.2.12",
25
+ removal="1.0",
26
+ message=(
27
+ "Use RunnableLambda to select from multiple prompt templates. See example "
28
+ "in API reference: "
29
+ "https://api.python.langchain.com/en/latest/chains/langchain.chains.router.llm_router.LLMRouterChain.html" # noqa: E501
30
+ ),
31
+ )
22
32
  class LLMRouterChain(RouterChain):
23
- """A router chain that uses an LLM chain to perform routing."""
33
+ """A router chain that uses an LLM chain to perform routing.
34
+
35
+ This class is deprecated. See below for a replacement, which offers several
36
+ benefits, including streaming and batch support.
37
+
38
+ Below is an example implementation:
39
+
40
+ .. code-block:: python
41
+
42
+ from operator import itemgetter
43
+ from typing import Literal
44
+ from typing_extensions import TypedDict
45
+
46
+ from langchain_core.output_parsers import StrOutputParser
47
+ from langchain_core.prompts import ChatPromptTemplate
48
+ from langchain_core.runnables import RunnableLambda, RunnablePassthrough
49
+ from langchain_openai import ChatOpenAI
50
+
51
+ llm = ChatOpenAI(model="gpt-4o-mini")
52
+
53
+ prompt_1 = ChatPromptTemplate.from_messages(
54
+ [
55
+ ("system", "You are an expert on animals."),
56
+ ("human", "{query}"),
57
+ ]
58
+ )
59
+ prompt_2 = ChatPromptTemplate.from_messages(
60
+ [
61
+ ("system", "You are an expert on vegetables."),
62
+ ("human", "{query}"),
63
+ ]
64
+ )
65
+
66
+ chain_1 = prompt_1 | llm | StrOutputParser()
67
+ chain_2 = prompt_2 | llm | StrOutputParser()
68
+
69
+ route_system = "Route the user's query to either the animal or vegetable expert."
70
+ route_prompt = ChatPromptTemplate.from_messages(
71
+ [
72
+ ("system", route_system),
73
+ ("human", "{query}"),
74
+ ]
75
+ )
76
+
77
+
78
+ class RouteQuery(TypedDict):
79
+ \"\"\"Route query to destination.\"\"\"
80
+ destination: Literal["animal", "vegetable"]
81
+
82
+
83
+ route_chain = (
84
+ route_prompt
85
+ | llm.with_structured_output(RouteQuery)
86
+ | itemgetter("destination")
87
+ )
88
+
89
+ chain = {
90
+ "destination": route_chain, # "animal" or "vegetable"
91
+ "query": lambda x: x["query"], # pass through input query
92
+ } | RunnableLambda(
93
+ # if animal, chain_1. otherwise, chain_2.
94
+ lambda x: chain_1 if x["destination"] == "animal" else chain_2,
95
+ )
96
+
97
+ chain.invoke({"query": "what color are carrots"})
98
+ """ # noqa: E501
24
99
 
25
100
  llm_chain: LLMChain
26
101
  """LLM chain used to perform routing"""
@@ -4,6 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  from typing import Any, Dict, List, Optional
6
6
 
7
+ from langchain_core._api import deprecated
7
8
  from langchain_core.language_models import BaseLanguageModel
8
9
  from langchain_core.prompts import PromptTemplate
9
10
 
@@ -15,8 +16,82 @@ from langchain.chains.router.llm_router import LLMRouterChain, RouterOutputParse
15
16
  from langchain.chains.router.multi_prompt_prompt import MULTI_PROMPT_ROUTER_TEMPLATE
16
17
 
17
18
 
19
+ @deprecated(
20
+ since="0.2.12",
21
+ removal="1.0",
22
+ message=(
23
+ "Use RunnableLambda to select from multiple prompt templates. See example "
24
+ "in API reference: "
25
+ "https://api.python.langchain.com/en/latest/chains/langchain.chains.router.multi_prompt.MultiPromptChain.html" # noqa: E501
26
+ ),
27
+ )
18
28
  class MultiPromptChain(MultiRouteChain):
19
- """A multi-route chain that uses an LLM router chain to choose amongst prompts."""
29
+ """A multi-route chain that uses an LLM router chain to choose amongst prompts.
30
+
31
+ This class is deprecated. See below for a replacement, which offers several
32
+ benefits, including streaming and batch support.
33
+
34
+ Below is an example implementation:
35
+
36
+ .. code-block:: python
37
+
38
+ from operator import itemgetter
39
+ from typing import Literal
40
+ from typing_extensions import TypedDict
41
+
42
+ from langchain_core.output_parsers import StrOutputParser
43
+ from langchain_core.prompts import ChatPromptTemplate
44
+ from langchain_core.runnables import RunnableLambda, RunnablePassthrough
45
+ from langchain_openai import ChatOpenAI
46
+
47
+ llm = ChatOpenAI(model="gpt-4o-mini")
48
+
49
+ prompt_1 = ChatPromptTemplate.from_messages(
50
+ [
51
+ ("system", "You are an expert on animals."),
52
+ ("human", "{query}"),
53
+ ]
54
+ )
55
+ prompt_2 = ChatPromptTemplate.from_messages(
56
+ [
57
+ ("system", "You are an expert on vegetables."),
58
+ ("human", "{query}"),
59
+ ]
60
+ )
61
+
62
+ chain_1 = prompt_1 | llm | StrOutputParser()
63
+ chain_2 = prompt_2 | llm | StrOutputParser()
64
+
65
+ route_system = "Route the user's query to either the animal or vegetable expert."
66
+ route_prompt = ChatPromptTemplate.from_messages(
67
+ [
68
+ ("system", route_system),
69
+ ("human", "{query}"),
70
+ ]
71
+ )
72
+
73
+
74
+ class RouteQuery(TypedDict):
75
+ \"\"\"Route query to destination.\"\"\"
76
+ destination: Literal["animal", "vegetable"]
77
+
78
+
79
+ route_chain = (
80
+ route_prompt
81
+ | llm.with_structured_output(RouteQuery)
82
+ | itemgetter("destination")
83
+ )
84
+
85
+ chain = {
86
+ "destination": route_chain, # "animal" or "vegetable"
87
+ "query": lambda x: x["query"], # pass through input query
88
+ } | RunnableLambda(
89
+ # if animal, chain_1. otherwise, chain_2.
90
+ lambda x: chain_1 if x["destination"] == "animal" else chain_2,
91
+ )
92
+
93
+ chain.invoke({"query": "what color are carrots"})
94
+ """ # noqa: E501
20
95
 
21
96
  @property
22
97
  def output_keys(self) -> List[str]:
@@ -6,7 +6,7 @@ from langchain_core.callbacks import (
6
6
  AsyncCallbackManagerForChainRun,
7
7
  CallbackManagerForChainRun,
8
8
  )
9
- from langchain_core.pydantic_v1 import Extra, root_validator
9
+ from langchain_core.pydantic_v1 import root_validator
10
10
  from langchain_core.utils.input import get_color_mapping
11
11
 
12
12
  from langchain.chains.base import Chain
@@ -21,10 +21,8 @@ class SequentialChain(Chain):
21
21
  return_all: bool = False
22
22
 
23
23
  class Config:
24
- """Configuration for this pydantic object."""
25
-
26
- extra = Extra.forbid
27
24
  arbitrary_types_allowed = True
25
+ extra = "forbid"
28
26
 
29
27
  @property
30
28
  def input_keys(self) -> List[str]:
@@ -132,10 +130,8 @@ class SimpleSequentialChain(Chain):
132
130
  output_key: str = "output" #: :meta private:
133
131
 
134
132
  class Config:
135
- """Configuration for this pydantic object."""
136
-
137
- extra = Extra.forbid
138
133
  arbitrary_types_allowed = True
134
+ extra = "forbid"
139
135
 
140
136
  @property
141
137
  def input_keys(self) -> List[str]:
@@ -41,7 +41,7 @@ from langchain_core.utils.pydantic import is_basemodel_subclass
41
41
  "feedback here: "
42
42
  "<https://github.com/langchain-ai/langchain/discussions/18154>"
43
43
  ),
44
- removal="0.3.0",
44
+ removal="1.0",
45
45
  alternative=(
46
46
  """
47
47
  from langchain_core.pydantic_v1 import BaseModel, Field
@@ -159,7 +159,7 @@ def create_openai_fn_runnable(
159
159
  "feedback here: "
160
160
  "<https://github.com/langchain-ai/langchain/discussions/18154>"
161
161
  ),
162
- removal="0.3.0",
162
+ removal="1.0",
163
163
  alternative=(
164
164
  """
165
165
  from langchain_core.pydantic_v1 import BaseModel, Field
@@ -224,7 +224,7 @@ def create_structured_output_runnable(
224
224
  structured outputs or a single one. If True and model does not return any
225
225
  structured outputs then chain output is None. If False and model does not
226
226
  return any structured outputs then chain output is an empty list.
227
- **kwargs: Additional named arguments.
227
+ kwargs: Additional named arguments.
228
228
 
229
229
  Returns:
230
230
  A runnable sequence that will return a structured output(s) matching the given
@@ -347,16 +347,14 @@ def _init_chat_model_helper(
347
347
  _check_pkg("langchain_ollama")
348
348
  from langchain_ollama import ChatOllama
349
349
  except ImportError:
350
- pass
351
-
352
- # For backwards compatibility
353
- try:
354
- _check_pkg("langchain_community")
355
- from langchain_community.chat_models import ChatOllama
356
- except ImportError:
357
- # If both langchain-ollama and langchain-community aren't available, raise
358
- # an error related to langchain-ollama
359
- _check_pkg("langchain_ollama")
350
+ # For backwards compatibility
351
+ try:
352
+ _check_pkg("langchain_community")
353
+ from langchain_community.chat_models import ChatOllama
354
+ except ImportError:
355
+ # If both langchain-ollama and langchain-community aren't available,
356
+ # raise an error related to langchain-ollama
357
+ _check_pkg("langchain_ollama")
360
358
 
361
359
  return ChatOllama(model=model, **kwargs)
362
360
  elif model_provider == "together":
@@ -28,7 +28,7 @@ from langchain_core.exceptions import OutputParserException
28
28
  from langchain_core.language_models import BaseLanguageModel
29
29
  from langchain_core.language_models.chat_models import BaseChatModel
30
30
  from langchain_core.output_parsers import BaseOutputParser
31
- from langchain_core.pydantic_v1 import Extra, Field
31
+ from langchain_core.pydantic_v1 import Field
32
32
  from langchain_core.tools import BaseTool
33
33
 
34
34
  from langchain.chains.llm import LLMChain
@@ -157,9 +157,7 @@ class TrajectoryEvalChain(AgentTrajectoryEvaluator, LLMEvalChain):
157
157
  """DEPRECATED. Reasoning always returned."""
158
158
 
159
159
  class Config:
160
- """Configuration for the QAEvalChain."""
161
-
162
- extra = Extra.ignore
160
+ extra = "ignore"
163
161
 
164
162
  @property
165
163
  def requires_reference(self) -> bool:
@@ -10,7 +10,7 @@ from langchain_core.callbacks.manager import Callbacks
10
10
  from langchain_core.language_models import BaseLanguageModel
11
11
  from langchain_core.output_parsers import BaseOutputParser
12
12
  from langchain_core.prompts.prompt import PromptTemplate
13
- from langchain_core.pydantic_v1 import Extra, Field
13
+ from langchain_core.pydantic_v1 import Field
14
14
 
15
15
  from langchain.chains.constitutional_ai.models import ConstitutionalPrinciple
16
16
  from langchain.chains.llm import LLMChain
@@ -192,9 +192,7 @@ class PairwiseStringEvalChain(PairwiseStringEvaluator, LLMEvalChain, LLMChain):
192
192
  return False
193
193
 
194
194
  class Config:
195
- """Configuration for the PairwiseStringEvalChain."""
196
-
197
- extra = Extra.ignore
195
+ extra = "ignore"
198
196
 
199
197
  @property
200
198
  def requires_reference(self) -> bool:
@@ -8,7 +8,7 @@ from langchain_core.callbacks.manager import Callbacks
8
8
  from langchain_core.language_models import BaseLanguageModel
9
9
  from langchain_core.output_parsers import BaseOutputParser
10
10
  from langchain_core.prompts import BasePromptTemplate
11
- from langchain_core.pydantic_v1 import Extra, Field
11
+ from langchain_core.pydantic_v1 import Field
12
12
 
13
13
  from langchain.chains.constitutional_ai.models import ConstitutionalPrinciple
14
14
  from langchain.chains.llm import LLMChain
@@ -237,9 +237,7 @@ class CriteriaEvalChain(StringEvaluator, LLMEvalChain, LLMChain):
237
237
  return False
238
238
 
239
239
  class Config:
240
- """Configuration for the QAEvalChain."""
241
-
242
- extra = Extra.ignore
240
+ extra = "ignore"
243
241
 
244
242
  @property
245
243
  def requires_reference(self) -> bool:
@@ -114,8 +114,6 @@ class _EmbeddingDistanceChainMixin(Chain):
114
114
  return values
115
115
 
116
116
  class Config:
117
- """Permit embeddings to go unvalidated."""
118
-
119
117
  arbitrary_types_allowed: bool = True
120
118
 
121
119
  @property
@@ -36,7 +36,7 @@ class JsonSchemaEvaluator(StringEvaluator):
36
36
  """Initializes the JsonSchemaEvaluator.
37
37
 
38
38
  Args:
39
- **kwargs: Additional keyword arguments.
39
+ kwargs: Additional keyword arguments.
40
40
 
41
41
  Raises:
42
42
  ImportError: If the jsonschema package is not installed.
@@ -9,7 +9,6 @@ from typing import Any, List, Optional, Sequence, Tuple
9
9
  from langchain_core.callbacks.manager import Callbacks
10
10
  from langchain_core.language_models import BaseLanguageModel
11
11
  from langchain_core.prompts import PromptTemplate
12
- from langchain_core.pydantic_v1 import Extra
13
12
 
14
13
  from langchain.chains.llm import LLMChain
15
14
  from langchain.evaluation.qa.eval_prompt import CONTEXT_PROMPT, COT_PROMPT, PROMPT
@@ -74,9 +73,7 @@ class QAEvalChain(LLMChain, StringEvaluator, LLMEvalChain):
74
73
  output_key: str = "results" #: :meta private:
75
74
 
76
75
  class Config:
77
- """Configuration for the QAEvalChain."""
78
-
79
- extra = Extra.ignore
76
+ extra = "ignore"
80
77
 
81
78
  @classmethod
82
79
  def is_lc_serializable(cls) -> bool:
@@ -224,9 +221,7 @@ class ContextQAEvalChain(LLMChain, StringEvaluator, LLMEvalChain):
224
221
  return True
225
222
 
226
223
  class Config:
227
- """Configuration for the QAEvalChain."""
228
-
229
- extra = Extra.ignore
224
+ extra = "ignore"
230
225
 
231
226
  @classmethod
232
227
  def _validate_input_vars(cls, prompt: PromptTemplate) -> None:
@@ -158,7 +158,7 @@ class StringEvaluator(_EvalArgsMixin, ABC):
158
158
  prediction (str): The LLM or chain prediction to evaluate.
159
159
  reference (Optional[str], optional): The reference label to evaluate against.
160
160
  input (Optional[str], optional): The input to consider during evaluation.
161
- **kwargs: Additional keyword arguments, including callbacks, tags, etc.
161
+ kwargs: Additional keyword arguments, including callbacks, tags, etc.
162
162
  Returns:
163
163
  dict: The evaluation results containing the score or value.
164
164
  It is recommended that the dictionary contain the following keys:
@@ -181,7 +181,7 @@ class StringEvaluator(_EvalArgsMixin, ABC):
181
181
  prediction (str): The LLM or chain prediction to evaluate.
182
182
  reference (Optional[str], optional): The reference label to evaluate against.
183
183
  input (Optional[str], optional): The input to consider during evaluation.
184
- **kwargs: Additional keyword arguments, including callbacks, tags, etc.
184
+ kwargs: Additional keyword arguments, including callbacks, tags, etc.
185
185
  Returns:
186
186
  dict: The evaluation results containing the score or value.
187
187
  It is recommended that the dictionary contain the following keys:
@@ -212,7 +212,7 @@ class StringEvaluator(_EvalArgsMixin, ABC):
212
212
  prediction (str): The LLM or chain prediction to evaluate.
213
213
  reference (Optional[str], optional): The reference label to evaluate against.
214
214
  input (Optional[str], optional): The input to consider during evaluation.
215
- **kwargs: Additional keyword arguments, including callbacks, tags, etc.
215
+ kwargs: Additional keyword arguments, including callbacks, tags, etc.
216
216
  Returns:
217
217
  dict: The evaluation results containing the score or value.
218
218
  """ # noqa: E501
@@ -235,7 +235,7 @@ class StringEvaluator(_EvalArgsMixin, ABC):
235
235
  prediction (str): The LLM or chain prediction to evaluate.
236
236
  reference (Optional[str], optional): The reference label to evaluate against.
237
237
  input (Optional[str], optional): The input to consider during evaluation.
238
- **kwargs: Additional keyword arguments, including callbacks, tags, etc.
238
+ kwargs: Additional keyword arguments, including callbacks, tags, etc.
239
239
  Returns:
240
240
  dict: The evaluation results containing the score or value.
241
241
  """ # noqa: E501
@@ -265,7 +265,7 @@ class PairwiseStringEvaluator(_EvalArgsMixin, ABC):
265
265
  prediction_b (str): The output string from the second model.
266
266
  reference (Optional[str], optional): The expected output / reference string.
267
267
  input (Optional[str], optional): The input string.
268
- **kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
268
+ kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
269
269
  Returns:
270
270
  dict: A dictionary containing the preference, scores, and/or other information.
271
271
  """ # noqa: E501
@@ -286,7 +286,7 @@ class PairwiseStringEvaluator(_EvalArgsMixin, ABC):
286
286
  prediction_b (str): The output string from the second model.
287
287
  reference (Optional[str], optional): The expected output / reference string.
288
288
  input (Optional[str], optional): The input string.
289
- **kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
289
+ kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
290
290
  Returns:
291
291
  dict: A dictionary containing the preference, scores, and/or other information.
292
292
  """ # noqa: E501
@@ -316,7 +316,7 @@ class PairwiseStringEvaluator(_EvalArgsMixin, ABC):
316
316
  prediction_b (str): The output string from the second model.
317
317
  reference (Optional[str], optional): The expected output / reference string.
318
318
  input (Optional[str], optional): The input string.
319
- **kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
319
+ kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
320
320
  Returns:
321
321
  dict: A dictionary containing the preference, scores, and/or other information.
322
322
  """ # noqa: E501
@@ -345,7 +345,7 @@ class PairwiseStringEvaluator(_EvalArgsMixin, ABC):
345
345
  prediction_b (str): The output string from the second model.
346
346
  reference (Optional[str], optional): The expected output / reference string.
347
347
  input (Optional[str], optional): The input string.
348
- **kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
348
+ kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
349
349
  Returns:
350
350
  dict: A dictionary containing the preference, scores, and/or other information.
351
351
  """ # noqa: E501
@@ -10,7 +10,7 @@ from langchain_core.callbacks.manager import Callbacks
10
10
  from langchain_core.language_models import BaseLanguageModel
11
11
  from langchain_core.output_parsers import BaseOutputParser
12
12
  from langchain_core.prompts.prompt import PromptTemplate
13
- from langchain_core.pydantic_v1 import Extra, Field
13
+ from langchain_core.pydantic_v1 import Field
14
14
 
15
15
  from langchain.chains.constitutional_ai.models import ConstitutionalPrinciple
16
16
  from langchain.chains.llm import LLMChain
@@ -180,9 +180,7 @@ class ScoreStringEvalChain(StringEvaluator, LLMEvalChain, LLMChain):
180
180
  """The name of the criterion being evaluated."""
181
181
 
182
182
  class Config:
183
- """Configuration for the ScoreStringEvalChain."""
184
-
185
- extra = Extra.ignore
183
+ extra = "ignore"
186
184
 
187
185
  @classmethod
188
186
  def is_lc_serializable(cls) -> bool:
@@ -278,7 +278,7 @@ class StringDistanceEvalChain(StringEvaluator, _RapidFuzzChainMixin):
278
278
  reference (Optional[str], optional): The reference string.
279
279
  input (Optional[str], optional): The input string.
280
280
  callbacks (Callbacks, optional): The callbacks to use.
281
- **kwargs: Additional keyword arguments.
281
+ kwargs: Additional keyword arguments.
282
282
 
283
283
  Returns:
284
284
  dict: The evaluation results containing the score.
@@ -314,7 +314,7 @@ class StringDistanceEvalChain(StringEvaluator, _RapidFuzzChainMixin):
314
314
  reference (Optional[str], optional): The reference string.
315
315
  input (Optional[str], optional): The input string.
316
316
  callbacks (Callbacks, optional): The callbacks to use.
317
- **kwargs: Additional keyword arguments.
317
+ kwargs: Additional keyword arguments.
318
318
 
319
319
  Returns:
320
320
  dict: The evaluation results containing the score.
@@ -412,7 +412,7 @@ class PairwiseStringDistanceEvalChain(PairwiseStringEvaluator, _RapidFuzzChainMi
412
412
  callbacks (Callbacks, optional): The callbacks to use.
413
413
  tags (List[str], optional): Tags to apply to traces.
414
414
  metadata (Dict[str, Any], optional): Metadata to apply to traces.
415
- **kwargs: Additional keyword arguments.
415
+ kwargs: Additional keyword arguments.
416
416
 
417
417
  Returns:
418
418
  dict: The evaluation results containing the score.
@@ -446,7 +446,7 @@ class PairwiseStringDistanceEvalChain(PairwiseStringEvaluator, _RapidFuzzChainMi
446
446
  callbacks (Callbacks, optional): The callbacks to use.
447
447
  tags (List[str], optional): Tags to apply to traces.
448
448
  metadata (Dict[str, Any], optional): Metadata to apply to traces.
449
- **kwargs: Additional keyword arguments.
449
+ kwargs: Additional keyword arguments.
450
450
 
451
451
  Returns:
452
452
  dict: The evaluation results containing the score.