Open Pooyash1998 opened 1 week ago
Having this same issue. Copy pasting the example from https://python.langchain.com/docs/integrations/llms/replicate/ doesn't work. I get the model Field Missing Error
same here, even with model included in kwargs - llm = Replicate( model_kwargs={"model": "meta/meta-llama-3-70b-instruct", "temperature": 0, "max_length": 300, "top_p": 1, "stop": []}, )
A temporary fix is to copy replicate.py from langchain library, modify it by adding the alias to "model" like this : class Replicate(LLM): model: str = Field(..., alias="model") and then import the Replicate class directly from your project and not from langchain library
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