Bug: model Field Missing Error in Replicate Class Due to Misidentification in Validator #26937
Open
5 tasks done
Labels
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
help wanted
Good issue for contributors
Checked other resources
Example Code
from langchain_community.llms import Replicate
replicate = Replicate(
model="meta/meta-llama-3-405b-instruct",
model_kwargs={"temperature": 0.7}
)
Error Message and Stack Trace (if applicable)
pydantic_core._pydantic_core.ValidationError: 1 validation error for Replicate
model
Field required [type=missing, input_value=..., input_type=..., ...]
Description
When initializing the Replicate class, the model field is incorrectly treated as an extra field and moved into model_kwargs, resulting in a validation error. This happens due to the way the build_extra validator processes the field aliases.
Suggested Fix:
In the build_extra method, replace the use of field.alias with field.name to ensure proper recognition of all fields:
@model_validator(mode="before") @classmethod def build_extra(cls, values: Dict[str, Any]) -> Any: all_required_field_names = {field.name for field in get_fields(cls).values()} # Remaining logic...
Or defining "model" as an alias in a Field can also solve the problem :
class Replicate(LLM): model: str = Field(..., alias="model")
System Info
System Information
Package Information
Optional packages not installed
Other Dependencies
The text was updated successfully, but these errors were encountered: