Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions examples/smart_scraper_graph/cloudgpu/smart_scraper_cloudgpu.py
Original file line number Diff line number Diff line change
@@ -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))
6 changes: 6 additions & 0 deletions scrapegraphai/graphs/abstract_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -175,6 +176,7 @@ def _create_llm(self, llm_config: dict) -> object:
"togetherai",
"xai",
"minimax",
"cloudgpu",
}

if "/" in llm_params["model"]:
Expand Down Expand Up @@ -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"] = {
Expand All @@ -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

Expand Down
9 changes: 9 additions & 0 deletions scrapegraphai/helpers/models_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 14 additions & 1 deletion scrapegraphai/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
]
26 changes: 26 additions & 0 deletions scrapegraphai/models/cloudgpu.py
Original file line number Diff line number Diff line change
@@ -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)
68 changes: 68 additions & 0 deletions tests/test_cloudgpu_model.py
Original file line number Diff line number Diff line change
@@ -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/<model>` 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)