diff --git a/examples/smart_scraper_graph/cloudgpu/smart_scraper_cloudgpu.py b/examples/smart_scraper_graph/cloudgpu/smart_scraper_cloudgpu.py new file mode 100644 index 000000000..022de3990 --- /dev/null +++ b/examples/smart_scraper_graph/cloudgpu/smart_scraper_cloudgpu.py @@ -0,0 +1,47 @@ +""" +Basic example of scraping pipeline using SmartScraper with CloudGPU +""" + +import json +import os + +from dotenv import load_dotenv + +from scrapegraphai.graphs import SmartScraperGraph +from scrapegraphai.utils import prettify_exec_info + +load_dotenv() + +# ************************************************ +# Define the configuration for the graph +# ************************************************ + + +graph_config = { + "llm": { + "api_key": os.getenv("CLOUDGPU_API_KEY"), + "model": "cloudgpu/deepseek-v4-flash", + }, + "verbose": True, + "headless": True, +} + +# ************************************************ +# Create the SmartScraperGraph instance and run it +# ************************************************ + +smart_scraper_graph = SmartScraperGraph( + prompt="Extract me the first article", + source="https://www.wired.com", + config=graph_config, +) + +result = smart_scraper_graph.run() +print(json.dumps(result, indent=4)) + +# ************************************************ +# Get graph execution info +# ************************************************ + +graph_exec_info = smart_scraper_graph.get_execution_info() +print(prettify_exec_info(graph_exec_info)) diff --git a/scrapegraphai/graphs/abstract_graph.py b/scrapegraphai/graphs/abstract_graph.py index 21f90460c..8ade7fb06 100644 --- a/scrapegraphai/graphs/abstract_graph.py +++ b/scrapegraphai/graphs/abstract_graph.py @@ -14,6 +14,7 @@ from ..helpers import models_tokens from ..models import XAI, CLoD, DeepSeek, MiniMax, Nvidia, OneApi +from ..models.cloudgpu import CloudGPU from ..utils.logging import get_logger, set_verbosity_info, set_verbosity_warning logger = get_logger(__name__) @@ -175,6 +176,7 @@ def _create_llm(self, llm_config: dict) -> object: "togetherai", "xai", "minimax", + "cloudgpu", } if "/" in llm_params["model"]: @@ -243,6 +245,7 @@ def _create_llm(self, llm_config: dict) -> object: "clod", "xai", "minimax", + "cloudgpu", }: if llm_params["model_provider"] == "bedrock": llm_params["model_kwargs"] = { @@ -263,6 +266,9 @@ def _create_llm(self, llm_config: dict) -> object: if model_provider == "minimax": return MiniMax(**llm_params) + if model_provider == "cloudgpu": + return CloudGPU(**llm_params) + if model_provider == "ernie": from langchain_community.chat_models import ErnieBotChat diff --git a/scrapegraphai/helpers/models_tokens.py b/scrapegraphai/helpers/models_tokens.py index 5a81ecaa7..9ef627d42 100644 --- a/scrapegraphai/helpers/models_tokens.py +++ b/scrapegraphai/helpers/models_tokens.py @@ -352,6 +352,15 @@ "gpt-5.4-mini": 400000, "gpt-5.4": 1000000, }, + "cloudgpu": { + "deepseek-v4-flash": 131072, + "deepseek-v4-pro": 131072, + "glm-5.3": 131072, + "kimi-k2.6": 262144, + "minimax-m3": 1000000, + "qwen3-coder-480b": 262144, + "qwen3.5-397b": 262144, + }, "deepseek": { "deepseek-chat": 128000, "deepseek-coder": 128000, diff --git a/scrapegraphai/models/__init__.py b/scrapegraphai/models/__init__.py index db01cd2e4..4f58d2a65 100644 --- a/scrapegraphai/models/__init__.py +++ b/scrapegraphai/models/__init__.py @@ -5,6 +5,7 @@ from .atlascloud import AtlasCloud from .cheaperinference import CheaperInference from .clod import CLoD +from .cloudgpu import CloudGPU from .deepseek import DeepSeek from .minimax import MiniMax from .nvidia import Nvidia @@ -13,4 +14,16 @@ from .openai_tts import OpenAITextToSpeech from .xai import XAI -__all__ = ["AtlasCloud", "CheaperInference", "DeepSeek", "MiniMax", "OneApi", "OpenAIImageToText", "OpenAITextToSpeech", "CLoD", "XAI", "Nvidia"] +__all__ = [ + "AtlasCloud", + "CheaperInference", + "CloudGPU", + "DeepSeek", + "MiniMax", + "OneApi", + "OpenAIImageToText", + "OpenAITextToSpeech", + "CLoD", + "XAI", + "Nvidia", +] diff --git a/scrapegraphai/models/cloudgpu.py b/scrapegraphai/models/cloudgpu.py new file mode 100644 index 000000000..2f014c207 --- /dev/null +++ b/scrapegraphai/models/cloudgpu.py @@ -0,0 +1,26 @@ +""" +CloudGPU Module +""" + +from langchain_openai import ChatOpenAI + +DEFAULT_CLOUDGPU_BASE_URL = "https://cloudgpu.app/v1" + + +class CloudGPU(ChatOpenAI): + """ + A wrapper for ChatOpenAI configured for CloudGPU's OpenAI-compatible + model API. Model ids are unprefixed, for example ``deepseek-v4-flash``; + ``GET https://cloudgpu.app/v1/models`` lists them. + + Args: + llm_config (dict): Configuration parameters for the language model. + """ + + def __init__(self, **llm_config): + if "api_key" in llm_config: + llm_config["openai_api_key"] = llm_config.pop("api_key") + if "base_url" not in llm_config and "openai_api_base" not in llm_config: + llm_config["openai_api_base"] = DEFAULT_CLOUDGPU_BASE_URL + + super().__init__(**llm_config) diff --git a/tests/test_cloudgpu_model.py b/tests/test_cloudgpu_model.py new file mode 100644 index 000000000..9f71bc3e7 --- /dev/null +++ b/tests/test_cloudgpu_model.py @@ -0,0 +1,68 @@ +"""Tests for the CloudGPU model configuration.""" + +import importlib.util +import os +from unittest.mock import Mock, patch + +from scrapegraphai.graphs import SmartScraperGraph +from scrapegraphai.models.cloudgpu import CloudGPU + + +def _load_models_tokens(): + spec = importlib.util.spec_from_file_location( + "models_tokens", + os.path.join( + os.path.dirname(__file__), + "..", + "scrapegraphai", + "helpers", + "models_tokens.py", + ), + ) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module.models_tokens + + +def test_cloudgpu_model_sets_openai_compatible_base_url(): + """CloudGPU should map api_key and default to the CloudGPU base URL.""" + model = CloudGPU(api_key="test-key", model="deepseek-v4-flash") + + assert str(model.openai_api_base).rstrip("/") == "https://cloudgpu.app/v1" + assert model.openai_api_key.get_secret_value() == "test-key" + + +def test_cloudgpu_model_keeps_custom_base_url(): + """An explicit base_url is not overwritten.""" + model = CloudGPU( + api_key="test-key", + model="deepseek-v4-flash", + base_url="https://example.com/v1", + ) + + assert str(model.openai_api_base).rstrip("/") == "https://example.com/v1" + + +def test_cloudgpu_models_in_token_list(): + """CloudGPU defaults should be listed with their context lengths.""" + cloudgpu_models = _load_models_tokens()["cloudgpu"] + + assert cloudgpu_models["deepseek-v4-flash"] == 131072 + assert cloudgpu_models["kimi-k2.6"] == 262144 + + +def test_cloudgpu_provider_resolves_from_model_prefix(): + """`cloudgpu/` resolves to CloudGPU with the bare model id.""" + config = { + "llm": { + "model": "cloudgpu/deepseek-v4-flash", + "api_key": "test-key", + } + } + with patch.object(SmartScraperGraph, "_create_graph", return_value=Mock(nodes=[])): + graph = SmartScraperGraph("prompt", "https://example.com", config) + + assert isinstance(graph.llm_model, CloudGPU) + assert graph.llm_model.model_name == "deepseek-v4-flash" + assert graph.model_token == 131072 + assert not getattr(graph, "model_tokens_defaulted", False)