From e08ac716dfdbb0300fb7ba96738299600990734a Mon Sep 17 00:00:00 2001 From: VinciGit00 Date: Fri, 23 Feb 2024 09:21:06 +0100 Subject: [PATCH] refactoring of the examples folder --- examples/direct use/Readme.md | 2 - examples/direct use/custom_graph.py | 54 ------------------- examples/direct use/graph_builder.py | 23 -------- examples/direct use/smart_scraper_graph.py | 17 ------ examples/direct use/speech_summary_graph.py | 20 ------- examples/{ => graph_examples}/.env.example | 0 .../custom_graph_example.py | 0 .../graph_builder_example.py | 0 .../graph_evaluation_example.py | 11 ++-- .../smart_scraper_example.py | 0 .../speech_summary_graph_example.py | 0 11 files changed, 8 insertions(+), 119 deletions(-) delete mode 100644 examples/direct use/Readme.md delete mode 100644 examples/direct use/custom_graph.py delete mode 100644 examples/direct use/graph_builder.py delete mode 100644 examples/direct use/smart_scraper_graph.py delete mode 100644 examples/direct use/speech_summary_graph.py rename examples/{ => graph_examples}/.env.example (100%) rename examples/{ => graph_examples}/custom_graph_example.py (100%) rename examples/{ => graph_examples}/graph_builder_example.py (100%) rename examples/{ => graph_examples}/graph_evaluation_example.py (68%) rename examples/{ => graph_examples}/smart_scraper_example.py (100%) rename examples/{ => graph_examples}/speech_summary_graph_example.py (100%) diff --git a/examples/direct use/Readme.md b/examples/direct use/Readme.md deleted file mode 100644 index 7b8e226b..00000000 --- a/examples/direct use/Readme.md +++ /dev/null @@ -1,2 +0,0 @@ -For having interacting examples visit the following collab notebook: -[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1sEZBonBMGP44CtO6GQTwAlL0BGJXjtfd?usp=sharing) diff --git a/examples/direct use/custom_graph.py b/examples/direct use/custom_graph.py deleted file mode 100644 index aa9445d7..00000000 --- a/examples/direct use/custom_graph.py +++ /dev/null @@ -1,54 +0,0 @@ - -""" -Example of custom graph using existing nodes -""" -from scrapegraphai.nodes import FetchHTMLNode, ParseHTMLNode, GenerateAnswerNode -from scrapegraphai.graphs import BaseGraph -from scrapegraphai.models import OpenAI -from scrapegraphai.helpers import nodes_metadata - -OPENAI_API_KEY = "YOUR_API_KEY" - -# check available nodes - -nodes_metadata.keys() - -# to get more information about a node -print(nodes_metadata['ImageToTextNode']) - -# Define the configuration for the language model -llm_config = { - "api_key": OPENAI_API_KEY, - "model_name": "gpt-3.5-turbo", - "temperature": 0, - "streaming": True -} -model = OpenAI(llm_config) - -# define the nodes for the graph -fetch_html_node = FetchHTMLNode("fetch_html") -parse_document_node = ParseHTMLNode("parse_document") -generate_answer_node = GenerateAnswerNode(model, "generate_answer") - -# create the graph -graph = BaseGraph( - nodes={ - fetch_html_node, - parse_document_node, - generate_answer_node - }, - edges={ - (fetch_html_node, parse_document_node), - (parse_document_node, generate_answer_node) - }, - entry_point=fetch_html_node -) - -# execute the graph -inputs = {"user_input": "What is the title of the page?", - "url": "https://example.com"} -result = graph.execute(inputs) - -# get the answer from the result -answer = result.get("answer", "No answer found.") -print(answer) diff --git a/examples/direct use/graph_builder.py b/examples/direct use/graph_builder.py deleted file mode 100644 index 87cf21ee..00000000 --- a/examples/direct use/graph_builder.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -Example of graph building -""" -from scrapegraphai.builders import GraphBuilder -OPENAI_API_KEY = "YOUR_API_KEY" - - -llm_config = { - "api_key": OPENAI_API_KEY, - "model_name": "gpt-3.5-turbo", - "temperature": 0, - "streaming": True -} - -# Example usage of GraphBuilder -USER_PROMPT = "Extract the news and generate a text summary with a voiceover." -graph_builder = GraphBuilder(USER_PROMPT, llm_config) -graph_json = graph_builder.build_graph() - -# Convert the resulting JSON to Graphviz format -graphviz_graph = graph_builder.convert_json_to_graphviz(graph_json) - -print(graph_json) diff --git a/examples/direct use/smart_scraper_graph.py b/examples/direct use/smart_scraper_graph.py deleted file mode 100644 index 6eacc6b1..00000000 --- a/examples/direct use/smart_scraper_graph.py +++ /dev/null @@ -1,17 +0,0 @@ -""" -Basic example of scraping pipeline using SmartScraper -""" -from scrapegraphai.graphs import SmartScraperGraph -OPENAI_API_KEY = "YOUR_API_KEY" - - -llm_config = { - "api_key": OPENAI_API_KEY, - "model_name": "gpt-3.5-turbo", -} - -smart_scraper_graph = SmartScraperGraph("List me all the titles and project descriptions", - "https://perinim.github.io/projects/", llm_config) - -answer = smart_scraper_graph.run() -print(answer["projects"][0]) diff --git a/examples/direct use/speech_summary_graph.py b/examples/direct use/speech_summary_graph.py deleted file mode 100644 index 859bcdc8..00000000 --- a/examples/direct use/speech_summary_graph.py +++ /dev/null @@ -1,20 +0,0 @@ -""" -Basic example of scraping pipeline using SpeechSummaryGraph -""" - -from scrapegraphai.graphs import SpeechSummaryGraph -OPENAI_API_KEY = "YOUR_API_KEY" - - -llm_config = { - "api_key": OPENAI_API_KEY -} - -# Save the audio to a file -AUDIO_FILE = "website_summary.mp3" -SPEECH_SUMMARY_GRAPH = SpeechSummaryGraph("Make a summary of the webpage to be converted to audio for blind people.", - "https://perinim.github.io/projects/", llm_config, - AUDIO_FILE) - -final_state = SPEECH_SUMMARY_GRAPH.run() -print(final_state.get("answer", "No answer found.")) diff --git a/examples/.env.example b/examples/graph_examples/.env.example similarity index 100% rename from examples/.env.example rename to examples/graph_examples/.env.example diff --git a/examples/custom_graph_example.py b/examples/graph_examples/custom_graph_example.py similarity index 100% rename from examples/custom_graph_example.py rename to examples/graph_examples/custom_graph_example.py diff --git a/examples/graph_builder_example.py b/examples/graph_examples/graph_builder_example.py similarity index 100% rename from examples/graph_builder_example.py rename to examples/graph_examples/graph_builder_example.py diff --git a/examples/graph_evaluation_example.py b/examples/graph_examples/graph_evaluation_example.py similarity index 68% rename from examples/graph_evaluation_example.py rename to examples/graph_examples/graph_evaluation_example.py index 5edca641..fcb5da2b 100644 --- a/examples/graph_evaluation_example.py +++ b/examples/graph_examples/graph_evaluation_example.py @@ -1,6 +1,9 @@ +""" +Module for evaluating the graph +""" import os -from scrapegraphai.evaluetor import TrulensEvaluator from dotenv import load_dotenv +from scrapegraphai.evaluetor import TrulensEvaluator load_dotenv() @@ -13,8 +16,10 @@ llm_config = { } list_of_inputs = [ - ("List me all the titles and project descriptions", "https://perinim.github.io/projects/", llm_config), - ("Who is the author of the project?", "https://perinim.github.io/projects/", llm_config), + ("List me all the titles and project descriptions", + "https://perinim.github.io/projects/", llm_config), + ("Who is the author of the project?", + "https://perinim.github.io/projects/", llm_config), ("What is the project about?", "https://perinim.github.io/projects/", llm_config) ] diff --git a/examples/smart_scraper_example.py b/examples/graph_examples/smart_scraper_example.py similarity index 100% rename from examples/smart_scraper_example.py rename to examples/graph_examples/smart_scraper_example.py diff --git a/examples/speech_summary_graph_example.py b/examples/graph_examples/speech_summary_graph_example.py similarity index 100% rename from examples/speech_summary_graph_example.py rename to examples/graph_examples/speech_summary_graph_example.py