-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
GraphIteratorNode and MergeAnswersNode #155
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
84fcb44
feat: fixed custom_graphs example and robots_node
PeriniM 16f53c5
add example custom search graph
PeriniM 1c4ba91
exposed abstract_graph allowing the user to create new graphs
PeriniM dbb614a
feat: multiple graph instances
PeriniM 930adb3
feat(node): multiple url search in SearchGraph + fixes
PeriniM 88d999e
add website content
VinciGit00 d9a4ab2
Delete custom_search_graph.py
VinciGit00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
""" | ||
Example of custom graph using existing nodes | ||
""" | ||
|
||
import os | ||
from dotenv import load_dotenv | ||
from langchain_openai import OpenAIEmbeddings | ||
from scrapegraphai.models import OpenAI | ||
from scrapegraphai.graphs import BaseGraph, SmartScraperGraph | ||
from scrapegraphai.nodes import SearchInternetNode, GraphIteratorNode, MergeAnswersNode | ||
load_dotenv() | ||
|
||
# ************************************************ | ||
# Define the configuration for the graph | ||
# ************************************************ | ||
|
||
openai_key = os.getenv("OPENAI_APIKEY") | ||
|
||
graph_config = { | ||
"llm": { | ||
"api_key": openai_key, | ||
"model": "gpt-3.5-turbo", | ||
}, | ||
} | ||
|
||
# ************************************************ | ||
# Create a SmartScraperGraph instance | ||
# ************************************************ | ||
|
||
smart_scraper_graph = SmartScraperGraph( | ||
prompt="", | ||
source="", | ||
config=graph_config | ||
) | ||
|
||
# ************************************************ | ||
# Define the graph nodes | ||
# ************************************************ | ||
|
||
llm_model = OpenAI(graph_config["llm"]) | ||
embedder = OpenAIEmbeddings(api_key=llm_model.openai_api_key) | ||
|
||
search_internet_node = SearchInternetNode( | ||
input="user_prompt", | ||
output=["urls"], | ||
node_config={ | ||
"llm_model": llm_model, | ||
"max_results": 5, # num of search results to fetch | ||
"verbose": True, | ||
} | ||
) | ||
|
||
graph_iterator_node = GraphIteratorNode( | ||
input="user_prompt & urls", | ||
output=["results"], | ||
node_config={ | ||
"graph_instance": smart_scraper_graph, | ||
"verbose": True, | ||
} | ||
) | ||
|
||
merge_answers_node = MergeAnswersNode( | ||
input="user_prompt & results", | ||
output=["answer"], | ||
node_config={ | ||
"llm_model": llm_model, | ||
"verbose": True, | ||
} | ||
) | ||
|
||
# ************************************************ | ||
# Create the graph by defining the connections | ||
# ************************************************ | ||
|
||
graph = BaseGraph( | ||
nodes=[ | ||
search_internet_node, | ||
graph_iterator_node, | ||
merge_answers_node | ||
], | ||
edges=[ | ||
(search_internet_node, graph_iterator_node), | ||
(graph_iterator_node, merge_answers_node) | ||
], | ||
entry_point=search_internet_node | ||
) | ||
|
||
# ************************************************ | ||
# Execute the graph | ||
# ************************************************ | ||
|
||
result, execution_info = graph.execute({ | ||
"user_prompt": "List me all the typical Chioggia dishes." | ||
}) | ||
|
||
# get the answer from the result | ||
result = result.get("answer", "No answer found.") | ||
print(result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why you do not use smart scraper graph?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm passing it inside the
GraphIteratorNode
configuration with empty prompt and source since they are mandatory for aSmartScraper
. InsideGraphIteratorNode
they will be replaced correctly