Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: model Field Missing Error in Replicate Class Due to Misidentification in Validator #26937

Open
5 tasks done
Pooyash1998 opened this issue Sep 27, 2024 · 3 comments
Open
5 tasks done
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature help wanted Good issue for contributors

Comments

@Pooyash1998
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

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

OS: Linux
OS Version: #1 SMP Fri Mar 29 23:14:13 UTC 2024
Python Version: 3.12.6 (main, Sep 10 2024, 00:05:17) [GCC 11.4.0]

Package Information

langchain_core: 0.3.6
langchain: 0.3.1
langchain_community: 0.3.1
langsmith: 0.1.129
langchain_chroma: 0.1.4
langchain_huggingface: 0.1.0
langchain_ollama: 0.2.0
langchain_openai: 0.2.0
langchain_text_splitters: 0.3.0
langserve: 0.3.0

Optional packages not installed

langgraph

Other Dependencies

aiohttp: 3.10.5
async-timeout: 4.0.3
chromadb: 0.5.7
dataclasses-json: 0.6.7
fastapi: 0.114.2
httpx: 0.27.2
huggingface-hub: 0.24.7
jsonpatch: 1.33
numpy: 1.26.4
ollama: 0.3.3
openai: 1.45.1
orjson: 3.10.7
packaging: 24.1
pydantic: 2.9.1
pydantic-settings: 2.5.2
PyYAML: 6.0.2
requests: 2.32.3
sentence-transformers: 3.1.0
SQLAlchemy: 2.0.34
sse-starlette: 1.8.2
tenacity: 8.5.0
tiktoken: 0.7.0
tokenizers: 0.19.1
transformers: 4.44.2
typing-extensions: 4.12.2

@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Sep 27, 2024
@ccurme ccurme added the help wanted Good issue for contributors label Sep 27, 2024
@devneel
Copy link

devneel commented Sep 30, 2024

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

@ken-vat
Copy link

ken-vat commented Oct 1, 2024

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": []},
)

@Pooyash1998
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature help wanted Good issue for contributors
Projects
None yet
Development

No branches or pull requests

4 participants