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

LLMGraphTransformer with gemini giving error #611

Open
arjun9689 opened this issue Nov 21, 2024 · 1 comment
Open

LLMGraphTransformer with gemini giving error #611

arjun9689 opened this issue Nov 21, 2024 · 1 comment

Comments

@arjun9689
Copy link

Below is the code I am trying to execute:

from dotenv import load_dotenv
load_dotenv()
import os

from langchain_google_genai import ChatGoogleGenerativeAI, GoogleGenerativeAIEmbeddings
from langchain_experimental.graph_transformers import LLMGraphTransformer
import google.generativeai as genai

genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro")

text = """Marie Curie, born in 1867, was a Polish and naturalised-French physicist and chemist who conducted pioneering research on radioactivity.She was the first woman to win a Nobel Prize, the first person to win a Nobel Prize twice, and the only person to win a Nobel Prize in two scientific fields.Her husband, Pierre Curie, was a co-winner of her first Nobel Prize, making them the first-ever married couple to win the Nobel Prize and launching the Curie family legacy of five Nobel Prizes.She was, in 1906, the first woman to become a professor at the University of Paris."""

from langchain_core.documents import Document
documents = [Document(page_content=text)]
llm_transformer = LLMGraphTransformer(llm=llm)
graph_documents = llm_transformer.convert_to_graph_documents(documents)

Below is the error I am getting:

ChatGoogleGenerativeAIError: Invalid argument provided to Gemini: 400 * GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[relationships].items: missing field.
* GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[nodes].items: missing field.
@marfago
Copy link

marfago commented Dec 7, 2024

It seems that the Optional[List] is not supported (Gemini is complaining because of a type=null).
Try to remove it as follows:

class DynamicGraph(_Graph):
        """Represents a graph document consisting of nodes and relationships."""

        nodes: List[SimpleNode] = Field(description="List of nodes")  # type: ignore
        relationships: List[SimpleRelationship] = Field(  # type: ignore
            description="List of relationships"
        )

Unfortunately it may cause a failure if the list of nodes/relationships is empty.

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