Error when running the Custom Graph Example #309
Closed
andreichis97
started this conversation in
General
Replies: 1 comment
-
Hey @andreichis97 thanks for noticing the error! There was an old version of the fetch_node, I have fixed it ;) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I am trying to run the example of creating a Custom Graph locally. It is exactly as in the Collab File provided.
import nest_asyncio
import os
import json
from apikey import apiKey
nest_asyncio.apply()
from scrapegraphai.helpers import nodes_metadata
from scrapegraphai.models import OpenAI
from scrapegraphai.graphs import BaseGraph
from scrapegraphai.nodes import FetchNode, ParseNode, RAGNode, GenerateAnswerNode
os.environ['OPENAI_API_KEY'] = apiKey
Define the configuration for the graph
graph_config = {
"llm": {
"api_key": apiKey,
"model": "gpt-3.5-turbo",
"temperature": 0,
"streaming": True
},
}
llm_model = OpenAI(graph_config["llm"])
define the nodes for the graph
fetch_node = FetchNode(
input="url | local_dir",
output=["doc"],
)
parse_node = ParseNode(
input="doc",
output=["parsed_doc"],
node_config={"chunk_size": 4096}
)
rag_node = RAGNode(
input="user_prompt & (parsed_doc | doc)",
output=["relevant_chunks"],
node_config={"llm_model": llm_model},
)
generate_answer_node = GenerateAnswerNode(
input="user_prompt & (relevant_chunks | parsed_doc | doc)",
output=["answer"],
node_config={"llm_model": llm_model},
)
create the graph by defining the nodes and their connections
graph = BaseGraph(
nodes=[
fetch_node,
parse_node,
rag_node,
generate_answer_node,
],
edges=[
(fetch_node, parse_node),
(parse_node, rag_node),
(rag_node, generate_answer_node)
],
entry_point=fetch_node
)
execute the graph
result = graph.execute({
"user_prompt": "List me the projects with their description",
"url": "https://perinim.github.io/projects/"
})
get the answer from the result
result = result.get("answer", "No answer found.")
Everytime I run this code, I am getting the following error:
File "D:\Andrei\Python_Scripts\Scrapegraphai.venv\lib\site-packages\scrapegraphai\graphs\base_graph.py", line 107, in execute
result = current_node.execute(state)
File "D:\Andrei\Python_Scripts\Scrapegraphai.venv\lib\site-packages\scrapegraphai\nodes\fetch_node.py", line 165, in execute
state.update({self.output[0]: compressed_document, self.output[1]: link_urls, self.output[2]: image_urls})
IndexError: list index out of range
Do you have any idea what could cause it? It's the exact code as in the documentation provided here.
Many thanks in advance! :)
Beta Was this translation helpful? Give feedback.
All reactions