Skip to content

Commit

Permalink
Merge pull request #895 from Telsho/main
Browse files Browse the repository at this point in the history
fix: Schema parameter type
  • Loading branch information
PeriniM authored Jan 21, 2025
2 parents 67de52a + 2b5bd80 commit fe9570b
Show file tree
Hide file tree
Showing 25 changed files with 102 additions and 52 deletions.
4 changes: 2 additions & 2 deletions scrapegraphai/graphs/abstract_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import uuid
import warnings
from abc import ABC, abstractmethod
from typing import Optional
from typing import Optional, Type

from langchain.chat_models import init_chat_model
from langchain_core.rate_limiters import InMemoryRateLimiter
Expand Down Expand Up @@ -51,7 +51,7 @@ def __init__(
prompt: str,
config: dict,
source: Optional[str] = None,
schema: Optional[BaseModel] = None,
schema: Optional[Type[BaseModel]] = None,
):
if config.get("llm").get("temperature") is None:
config["llm"]["temperature"] = 0
Expand Down
8 changes: 6 additions & 2 deletions scrapegraphai/graphs/code_generator_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SmartScraperGraph Module
"""

from typing import Optional
from typing import Optional, Type

from pydantic import BaseModel

Expand Down Expand Up @@ -56,7 +56,11 @@ class CodeGeneratorGraph(AbstractGraph):
"""

def __init__(
self, prompt: str, source: str, config: dict, schema: Optional[BaseModel] = None
self,
prompt: str,
source: str,
config: dict,
schema: Optional[Type[BaseModel]] = None,
):
super().__init__(prompt, config, source, schema)

Expand Down
10 changes: 7 additions & 3 deletions scrapegraphai/graphs/csv_scraper_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module for creating the smart scraper
"""

from typing import Optional
from typing import Optional, Type

from pydantic import BaseModel

Expand All @@ -22,7 +22,7 @@ class CSVScraperGraph(AbstractGraph):
config (dict): Additional configuration parameters needed by some nodes in the graph.
Methods:
__init__ (prompt: str, source: str, config: dict, schema: Optional[BaseModel] = None):
__init__ (prompt: str, source: str, config: dict, schema: Optional[Type[BaseModel]] = None):
Initializes the CSVScraperGraph with a prompt, source, and configuration.
__init__ initializes the CSVScraperGraph class. It requires the user's prompt as input,
Expand All @@ -49,7 +49,11 @@ class CSVScraperGraph(AbstractGraph):
"""

def __init__(
self, prompt: str, source: str, config: dict, schema: Optional[BaseModel] = None
self,
prompt: str,
source: str,
config: dict,
schema: Optional[Type[BaseModel]] = None,
):
"""
Initializes the CSVScraperGraph with a prompt, source, and configuration.
Expand Down
4 changes: 2 additions & 2 deletions scrapegraphai/graphs/csv_scraper_multi_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from copy import deepcopy
from typing import List, Optional
from typing import List, Optional, Type

from pydantic import BaseModel

Expand Down Expand Up @@ -47,7 +47,7 @@ def __init__(
prompt: str,
source: List[str],
config: dict,
schema: Optional[BaseModel] = None,
schema: Optional[Type[BaseModel]] = None,
):

self.copy_config = safe_deepcopy(config)
Expand Down
8 changes: 6 additions & 2 deletions scrapegraphai/graphs/depth_search_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
depth search graph Module
"""

from typing import Optional
from typing import Optional, Type

from pydantic import BaseModel

Expand Down Expand Up @@ -54,7 +54,11 @@ class DepthSearchGraph(AbstractGraph):
"""

def __init__(
self, prompt: str, source: str, config: dict, schema: Optional[BaseModel] = None
self,
prompt: str,
source: str,
config: dict,
schema: Optional[Type[BaseModel]] = None,
):
super().__init__(prompt, config, source, schema)

Expand Down
8 changes: 6 additions & 2 deletions scrapegraphai/graphs/document_scraper_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This module implements the Document Scraper Graph for the ScrapeGraphAI application.
"""

from typing import Optional
from typing import Optional, Type

from pydantic import BaseModel

Expand Down Expand Up @@ -44,7 +44,11 @@ class DocumentScraperGraph(AbstractGraph):
"""

def __init__(
self, prompt: str, source: str, config: dict, schema: Optional[BaseModel] = None
self,
prompt: str,
source: str,
config: dict,
schema: Optional[Type[BaseModel]] = None,
):
super().__init__(prompt, config, source, schema)

Expand Down
4 changes: 2 additions & 2 deletions scrapegraphai/graphs/document_scraper_multi_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from copy import deepcopy
from typing import List, Optional
from typing import List, Optional, Type

from pydantic import BaseModel

Expand Down Expand Up @@ -47,7 +47,7 @@ def __init__(
prompt: str,
source: List[str],
config: dict,
schema: Optional[BaseModel] = None,
schema: Optional[Type[BaseModel]] = None,
):
self.copy_config = safe_deepcopy(config)
self.copy_schema = deepcopy(schema)
Expand Down
8 changes: 6 additions & 2 deletions scrapegraphai/graphs/json_scraper_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
JSONScraperGraph Module
"""

from typing import Optional
from typing import Optional, Type

from pydantic import BaseModel

Expand Down Expand Up @@ -42,7 +42,11 @@ class JSONScraperGraph(AbstractGraph):
"""

def __init__(
self, prompt: str, source: str, config: dict, schema: Optional[BaseModel] = None
self,
prompt: str,
source: str,
config: dict,
schema: Optional[Type[BaseModel]] = None,
):
super().__init__(prompt, config, source, schema)

Expand Down
4 changes: 2 additions & 2 deletions scrapegraphai/graphs/json_scraper_multi_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from copy import deepcopy
from typing import List, Optional
from typing import List, Optional, Type

from pydantic import BaseModel

Expand Down Expand Up @@ -47,7 +47,7 @@ def __init__(
prompt: str,
source: List[str],
config: dict,
schema: Optional[BaseModel] = None,
schema: Optional[Type[BaseModel]] = None,
):

self.copy_config = safe_deepcopy(config)
Expand Down
8 changes: 6 additions & 2 deletions scrapegraphai/graphs/omni_scraper_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This module implements the Omni Scraper Graph for the ScrapeGraphAI application.
"""

from typing import Optional
from typing import Optional, Type

from pydantic import BaseModel

Expand Down Expand Up @@ -47,7 +47,11 @@ class OmniScraperGraph(AbstractGraph):
"""

def __init__(
self, prompt: str, source: str, config: dict, schema: Optional[BaseModel] = None
self,
prompt: str,
source: str,
config: dict,
schema: Optional[Type[BaseModel]] = None,
):
self.max_images = 5 if config is None else config.get("max_images", 5)

Expand Down
6 changes: 4 additions & 2 deletions scrapegraphai/graphs/omni_search_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from copy import deepcopy
from typing import Optional
from typing import Optional, Type

from pydantic import BaseModel

Expand Down Expand Up @@ -41,7 +41,9 @@ class OmniSearchGraph(AbstractGraph):
>>> result = search_graph.run()
"""

def __init__(self, prompt: str, config: dict, schema: Optional[BaseModel] = None):
def __init__(
self, prompt: str, config: dict, schema: Optional[Type[BaseModel]] = None
):

self.max_results = config.get("max_results", 3)

Expand Down
10 changes: 7 additions & 3 deletions scrapegraphai/graphs/screenshot_scraper_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ScreenshotScraperGraph Module
"""

from typing import Optional
from typing import Optional, Type

from pydantic import BaseModel

Expand All @@ -21,7 +21,7 @@ class ScreenshotScraperGraph(AbstractGraph):
source (str): The source URL or image link to scrape from.
Methods:
__init__(prompt: str, source: str, config: dict, schema: Optional[BaseModel] = None)
__init__(prompt: str, source: str, config: dict, schema: Optional[Type[BaseModel]] = None)
Initializes the ScreenshotScraperGraph instance with the given prompt,
source, and configuration parameters.
Expand All @@ -33,7 +33,11 @@ class ScreenshotScraperGraph(AbstractGraph):
"""

def __init__(
self, prompt: str, source: str, config: dict, schema: Optional[BaseModel] = None
self,
prompt: str,
source: str,
config: dict,
schema: Optional[Type[BaseModel]] = None,
):
super().__init__(prompt, config, source, schema)

Expand Down
8 changes: 6 additions & 2 deletions scrapegraphai/graphs/script_creator_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ScriptCreatorGraph Module
"""

from typing import Optional
from typing import Optional, Type

from pydantic import BaseModel

Expand Down Expand Up @@ -44,7 +44,11 @@ class ScriptCreatorGraph(AbstractGraph):
"""

def __init__(
self, prompt: str, source: str, config: dict, schema: Optional[BaseModel] = None
self,
prompt: str,
source: str,
config: dict,
schema: Optional[Type[BaseModel]] = None,
):
self.library = config["library"]

Expand Down
4 changes: 2 additions & 2 deletions scrapegraphai/graphs/script_creator_multi_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from copy import deepcopy
from typing import List, Optional
from typing import List, Optional, Type

from pydantic import BaseModel

Expand Down Expand Up @@ -46,7 +46,7 @@ def __init__(
prompt: str,
source: List[str],
config: dict,
schema: Optional[BaseModel] = None,
schema: Optional[Type[BaseModel]] = None,
):

self.copy_config = safe_deepcopy(config)
Expand Down
6 changes: 4 additions & 2 deletions scrapegraphai/graphs/search_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from copy import deepcopy
from typing import List, Optional
from typing import List, Optional, Type

from pydantic import BaseModel

Expand Down Expand Up @@ -42,7 +42,9 @@ class SearchGraph(AbstractGraph):
>>> print(search_graph.get_considered_urls())
"""

def __init__(self, prompt: str, config: dict, schema: Optional[BaseModel] = None):
def __init__(
self, prompt: str, config: dict, schema: Optional[Type[BaseModel]] = None
):
self.max_results = config.get("max_results", 3)

self.copy_config = safe_deepcopy(config)
Expand Down
6 changes: 4 additions & 2 deletions scrapegraphai/graphs/search_link_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SearchLinkGraph Module
"""

from typing import Optional
from typing import Optional, Type

from pydantic import BaseModel

Expand Down Expand Up @@ -36,7 +36,9 @@ class SearchLinkGraph(AbstractGraph):
"""

def __init__(self, source: str, config: dict, schema: Optional[BaseModel] = None):
def __init__(
self, source: str, config: dict, schema: Optional[Type[BaseModel]] = None
):
super().__init__("", config, source, schema)

self.input_key = "url" if source.startswith("http") else "local_dir"
Expand Down
8 changes: 6 additions & 2 deletions scrapegraphai/graphs/smart_scraper_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SmartScraperGraph Module
"""

from typing import Optional
from typing import Optional, Type

from pydantic import BaseModel

Expand Down Expand Up @@ -52,7 +52,11 @@ class SmartScraperGraph(AbstractGraph):
"""

def __init__(
self, prompt: str, source: str, config: dict, schema: Optional[BaseModel] = None
self,
prompt: str,
source: str,
config: dict,
schema: Optional[Type[BaseModel]] = None,
):
super().__init__(prompt, config, source, schema)

Expand Down
4 changes: 2 additions & 2 deletions scrapegraphai/graphs/smart_scraper_lite_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SmartScraperGraph Module
"""

from typing import Optional
from typing import Optional, Type

from pydantic import BaseModel

Expand Down Expand Up @@ -44,7 +44,7 @@ def __init__(
source: str,
config: dict,
prompt: str = "",
schema: Optional[BaseModel] = None,
schema: Optional[Type[BaseModel]] = None,
):
super().__init__(prompt, config, source, schema)

Expand Down
Loading

0 comments on commit fe9570b

Please sign in to comment.