-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into refactoring-parse-html
- Loading branch information
Showing
10 changed files
with
169 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 @@ | ||
OPENAI_APIKEY="your openai.com api key" |
This file contains 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,58 @@ | ||
""" | ||
Module for testing the class custom_graph class | ||
""" | ||
import unittest | ||
import os | ||
from dotenv import load_dotenv | ||
from scrapegraphai.models import OpenAI | ||
from scrapegraphai.graphs import BaseGraph | ||
from scrapegraphai.nodes import FetchHTMLNode, ParseHTMLNode, GenerateAnswerNode | ||
|
||
|
||
class TestCustomGraph(unittest.TestCase): | ||
""" | ||
class for testing the class custom_graph | ||
""" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
load_dotenv() | ||
openai_key = os.getenv("OPENAI_APIKEY") | ||
llm_config = { | ||
"api_key": openai_key, | ||
"model_name": "gpt-3.5-turbo", | ||
"temperature": 0, | ||
"streaming": True | ||
} | ||
cls.model = OpenAI(llm_config) | ||
cls.fetch_html_node = FetchHTMLNode("fetch_html") | ||
cls.parse_document_node = ParseHTMLNode("parse_document") | ||
cls.generate_answer_node = GenerateAnswerNode( | ||
cls.model, "generate_answer") | ||
cls.graph = BaseGraph( | ||
nodes={ | ||
cls.fetch_html_node, | ||
cls.parse_document_node, | ||
cls.generate_answer_node | ||
}, | ||
edges={ | ||
(cls.fetch_html_node, cls.parse_document_node), | ||
(cls.parse_document_node, cls.generate_answer_node) | ||
}, | ||
entry_point=cls.fetch_html_node | ||
) | ||
|
||
def test_execution(self): | ||
""" | ||
Execution of the test | ||
""" | ||
inputs = {"user_input": "Give me the news", | ||
"url": "https://www.ansa.it/sito/notizie/topnews/index.shtml"} | ||
result = self.graph.execute(inputs) | ||
answer = result.get("answer", "No answer found.") | ||
self.assertIsNotNone(answer) | ||
self.assertNotEqual(answer, "No answer found.") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains 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,38 @@ | ||
""" | ||
Module for testing the class SmartScraperGraph | ||
""" | ||
import unittest | ||
import os | ||
from dotenv import load_dotenv | ||
from scrapegraphai.graphs import SmartScraperGraph | ||
|
||
|
||
class TestSmartScraperGraph(unittest.TestCase): | ||
""" | ||
class for testing the class SmartScraperGraph | ||
""" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
load_dotenv() | ||
openai_key = os.getenv("OPENAI_APIKEY") | ||
cls.llm_config = { | ||
"api_key": openai_key, | ||
"model_name": "gpt-3.5-turbo", | ||
} | ||
cls.URL = "https://perinim.github.io/projects/" | ||
cls.PROMPT = "List me all the titles and project descriptions and give me an audio" | ||
cls.smart_scraper_graph = SmartScraperGraph( | ||
cls.PROMPT, cls.URL, cls.llm_config) | ||
|
||
def test_scraper_execution(self): | ||
""" | ||
Execution of the test | ||
""" | ||
answer = self.smart_scraper_graph.run() | ||
self.assertIsNotNone(answer) | ||
self.assertNotEqual(answer, "") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains 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,42 @@ | ||
""" | ||
Module for testing the class SpeechSummaryGraph | ||
""" | ||
import unittest | ||
import os | ||
from dotenv import load_dotenv | ||
from scrapegraphai.graphs import SpeechSummaryGraph | ||
|
||
|
||
class TestSpeechSummaryGraph(unittest.TestCase): | ||
""" | ||
class for testing the class SpeechSummaryGraph | ||
""" | ||
|
||
def setUp(self): | ||
load_dotenv() | ||
openai_key = os.getenv("OPENAI_APIKEY") | ||
self.llm_config = { | ||
"api_key": openai_key, | ||
} | ||
self.curr_dir = os.path.dirname(os.path.realpath(__file__)) | ||
self.output_file_path = os.path.join( | ||
self.curr_dir, "website_summary.mp3") | ||
|
||
def test_summary_generation(self): | ||
""" | ||
Execution of the test | ||
""" | ||
speech_summary_graph = SpeechSummaryGraph("""Make a summary of the news to be | ||
converted to audio for | ||
blind people.""", | ||
"https://www.wired.com/category/science/", | ||
self.llm_config, | ||
self.output_file_path) | ||
final_state = speech_summary_graph.run() | ||
result = final_state.get("answer", "No answer found.") | ||
self.assertIsNotNone(result) | ||
self.assertNotEqual(result, "No answer found.") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |