-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4921a4f
commit 49b2e18
Showing
5 changed files
with
52 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from pydantic import BaseModel | ||
from scrapegraphaiapisdk.scrape import scrape | ||
from dotenv import load_dotenv | ||
import os | ||
|
||
# Load environment variables from .env file | ||
load_dotenv() | ||
|
||
# Define a Pydantic schema | ||
class CompanyInfoSchema(BaseModel): | ||
company_name: str | ||
description: str | ||
main_products: list[str] | ||
|
||
# Example usage | ||
api_key = os.getenv("SCRAPEGRAPH_API_KEY") | ||
url = "https://scrapegraphai.com/" | ||
prompt = "What does the company do?" | ||
|
||
# Create an instance of the schema with initial values | ||
schema = CompanyInfoSchema( | ||
company_name="Example Company", | ||
description="An example company description.", | ||
main_products=["Product1", "Product2"] | ||
) | ||
|
||
# Call the scrape function with the schema | ||
result = scrape(api_key=api_key, url=url, prompt=prompt, schema=schema) | ||
|
||
print(result) |
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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
from scrapegraphaiapisdk.feedback import feedback | ||
import requests | ||
|
||
class TestFeedback(unittest.TestCase): | ||
|
||
@patch('scrapegraphaiapisdk.feedback.requests.post') | ||
def test_feedback_success(self, mock_post): | ||
mock_post.return_value.status_code = 200 | ||
mock_post.return_value.text = '{"status": "success"}' | ||
response = feedback("test_api_key", "Great service!") | ||
response = feedback("test_api_key", "3fa85f64-5717-4562-b3fc-2c963f66afa6", 5, "Great service!") | ||
self.assertEqual(response, '{"status": "success"}') | ||
|
||
@patch('scrapegraphaiapisdk.feedback.requests.post') | ||
def test_feedback_http_error(self, mock_post): | ||
mock_post.side_effect = requests.exceptions.HTTPError | ||
response = feedback("test_api_key", "Great service!") | ||
response = feedback("test_api_key", "3fa85f64-5717-4562-b3fc-2c963f66afa6", 5, "Great service!") | ||
self.assertIn("HTTP error occurred", response) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |