24
24
PromptTemplate ,
25
25
SystemMessagePromptTemplate ,
26
26
)
27
- from langchain . pydantic_v1 import BaseModel , Extra
27
+ from pydantic import BaseModel , ConfigDict
28
28
from langchain .schema import LLMResult
29
29
from langchain .schema .output_parser import StrOutputParser
30
30
from langchain .schema .runnable import Runnable
33
33
from langchain_core .language_models .chat_models import BaseChatModel
34
34
from langchain_core .language_models .llms import BaseLLM
35
35
36
- # this is necessary because `langchain.pydantic_v1.main` does not include
37
- # `ModelMetaclass`, as it is not listed in `__all__` by the `pydantic.main`
38
- # subpackage.
39
- try :
40
- from pydantic .v1 .main import ModelMetaclass
41
- except :
42
- from pydantic .main import ModelMetaclass
43
36
44
37
from . import completion_utils as completion
45
38
from .models .completion import (
@@ -122,7 +115,7 @@ class EnvAuthStrategy(BaseModel):
122
115
name : str
123
116
"""The name of the environment variable, e.g. `'ANTHROPIC_API_KEY'`."""
124
117
125
- keyword_param : Optional [str ]
118
+ keyword_param : Optional [str ] = None
126
119
"""
127
120
If unset (default), the authentication token is provided as a keyword
128
121
argument with the parameter equal to the environment variable name in
@@ -177,51 +170,10 @@ class IntegerField(BaseModel):
177
170
Field = Union [TextField , MultilineTextField , IntegerField ]
178
171
179
172
180
- class ProviderMetaclass (ModelMetaclass ):
181
- """
182
- A metaclass that ensures all class attributes defined inline within the
183
- class definition are accessible and included in `Class.__dict__`.
184
-
185
- This is necessary because Pydantic drops any ClassVars that are defined as
186
- an instance field by a parent class, even if they are defined inline within
187
- the class definition. We encountered this case when `langchain` added a
188
- `name` attribute to a parent class shared by all `Provider`s, which caused
189
- `Provider.name` to be inaccessible. See #558 for more info.
190
- """
191
-
192
- def __new__ (mcs , name , bases , namespace , ** kwargs ):
193
- cls = super ().__new__ (mcs , name , bases , namespace , ** kwargs )
194
- for key in namespace :
195
- # skip private class attributes
196
- if key .startswith ("_" ):
197
- continue
198
- # skip class attributes already listed in `cls.__dict__`
199
- if key in cls .__dict__ :
200
- continue
201
-
202
- setattr (cls , key , namespace [key ])
203
-
204
- return cls
205
-
206
- @property
207
- def server_settings (cls ):
208
- return cls ._server_settings
209
-
210
- @server_settings .setter
211
- def server_settings (cls , value ):
212
- if cls ._server_settings is not None :
213
- raise AttributeError ("'server_settings' attribute was already set" )
214
- cls ._server_settings = value
215
-
216
- _server_settings = None
217
-
218
-
219
- class BaseProvider (BaseModel , metaclass = ProviderMetaclass ):
220
- #
221
- # pydantic config
222
- #
223
- class Config :
224
- extra = Extra .allow
173
+ class BaseProvider (BaseModel ):
174
+ # pydantic v2 model config
175
+ # upstream docs: https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.extra
176
+ model_config = ConfigDict (extra = "allow" )
225
177
226
178
#
227
179
# class attrs
@@ -236,15 +188,25 @@ class Config:
236
188
"""List of supported models by their IDs. For registry providers, this will
237
189
be just ["*"]."""
238
190
239
- help : ClassVar [str ] = None
191
+ help : ClassVar [Optional [ str ] ] = None
240
192
"""Text to display in lieu of a model list for a registry provider that does
241
193
not provide a list of models."""
242
194
243
- model_id_key : ClassVar [str ] = ...
244
- """Kwarg expected by the upstream LangChain provider."""
195
+ model_id_key : ClassVar [Optional [str ]] = None
196
+ """
197
+ Optional field which specifies the key under which `model_id` is passed to
198
+ the parent LangChain class.
245
199
246
- model_id_label : ClassVar [str ] = ""
247
- """Human-readable label of the model ID."""
200
+ If unset, this defaults to "model_id".
201
+ """
202
+
203
+ model_id_label : ClassVar [Optional [str ]] = None
204
+ """
205
+ Optional field which sets the label shown in the UI allowing users to
206
+ select/type a model ID.
207
+
208
+ If unset, the label shown in the UI defaults to "Model ID".
209
+ """
248
210
249
211
pypi_package_deps : ClassVar [List [str ]] = []
250
212
"""List of PyPi package dependencies."""
@@ -586,7 +548,6 @@ def __init__(self, **kwargs):
586
548
587
549
id = "gpt4all"
588
550
name = "GPT4All"
589
- docs = "https://docs.gpt4all.io/gpt4all_python.html"
590
551
models = [
591
552
"ggml-gpt4all-j-v1.2-jazzy" ,
592
553
"ggml-gpt4all-j-v1.3-groovy" ,
0 commit comments