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

RuntimeError: no validator found for <class '__main__.Node'>, see arbitrary_types_allowed in Config #1055

Open
xjloong opened this issue Feb 3, 2025 · 2 comments

Comments

@xjloong
Copy link

xjloong commented Feb 3, 2025

from langchain_community.graphs.graph_document import (
    Node as BaseNode,
    Relationship as BaseRelationship,
    GraphDocument,
)
from langchain.schema import Document
from typing import List, Dict, Any, Optional
from langchain.pydantic_v1 import Field, BaseModel

class Property(BaseModel):
    """A single property consisting of key and value"""
    key: str = Field(..., description="key")
    value: str = Field(..., description="value")
        
class Node(BaseNode):
    properties: Optional[List[Property]] = Field(
        None, description="List of node properties")

class Relationship(BaseRelationship):
    properties: Optional[List[Property]] = Field(
        None, description="List of relationship properties"
    )

# class Source(BaseSource):
#     properties: Optional[List[Property]] = Field(
#         None, description="List of sources"
#     )        
        
class KnowledgeGraph(BaseModel):
    """Generate a knowledge graph with entities and relationships."""
    nodes: List[Node] = Field(
        ..., description="List of nodes in the knowledge graph")
    rels: List[Relationship] = Field(
        ..., description="List of relationships in the knowledge graph"
    )

When I run this code, he gets this error. After looking around online, I added

class Config: 
        arbitrary_types_allowed = True

in class Node(BaseNode):.It is still getting the error, so I hope I can get some help!

@kartikpersistent
Copy link
Collaborator

Hi @xjloong can you give more information on which model you are getting this and any error trace ?

@xjloong
Copy link
Author

xjloong commented Feb 6, 2025

Hi @xjloong can you give more information on which model you are getting this and any error trace ?
Thank you for you help,i have solved this error.i used llamam3.1 to run. firstly ,i used

from langchain_ollama.llms import OllamaLLM
model = OllamaLLM(model="llama3.1")

it got this error,but when i changed the code to

from langchain_ollama import ChatOllama
llm = ChatOllama(
    model="llama3.1",
    temperature=0,
    # other params...
)

it can go right into my code , though i don't konw the reason

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants