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
1 change: 1 addition & 0 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
tests/test_depth_search_graph.py
tests/test_error_page_detection.py
tests/test_json_scraper_graph.py
tests/test_litellm_model.py
tests/test_minimax_models.py
tests/test_scrape_do.py
tests/test_search_graph.py
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ For each of these graphs there is the multi version. It allows to make calls of

It is possible to use different LLM through APIs, such as **OpenAI**, **Groq**, **Azure**, **Gemini**, **[MiniMax](docs/minimax.md)** and more, or local models using **Ollama**.

To reach any provider supported by [LiteLLM](https://docs.litellm.ai/docs/providers) (Anthropic, Bedrock, Vertex AI, Azure, ...), install `scrapegraphai[litellm]` and set the model to `litellm/<provider>/<model>`, for example `litellm/anthropic/claude-sonnet-4-6`. The context window and the cost reported in the execution info come from LiteLLM's model map.

Remember to have [Ollama](https://ollama.com/) installed and download the models using the **ollama pull** command, if you want to use local models.


Expand Down
51 changes: 51 additions & 0 deletions examples/smart_scraper_graph/litellm/smart_scraper_litellm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
Basic example of scraping pipeline using SmartScraper with LiteLLM

Install the extra first: pip install scrapegraphai[litellm]
"""

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
# ************************************************

# "litellm/<provider>/<model>" routes the call through the LiteLLM SDK, so any
# provider LiteLLM supports works here, e.g. "litellm/anthropic/claude-sonnet-4-6",
# "litellm/vertex_ai/gemini-2.5-flash" or "litellm/bedrock/<model id>".
# Credentials are read from the provider's usual environment variables.
graph_config = {
"llm": {
"model": os.getenv("LITELLM_MODEL", "litellm/anthropic/claude-sonnet-4-6"),
"temperature": 0,
},
"verbose": True,
"headless": False,
}

# ************************************************
# Create the SmartScraperGraph instance and run it
# ************************************************

smart_scraper_graph = SmartScraperGraph(
prompt="Find some information about the founders.",
source="https://scrapegraphai.com/",
config=graph_config,
)

result = smart_scraper_graph.run()
print(result)

# ************************************************
# Get graph execution info
# ************************************************

graph_exec_info = smart_scraper_graph.get_execution_info()
print(prettify_exec_info(graph_exec_info))
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ requires-python = ">=3.12,<4.0"

[project.optional-dependencies]
burr = ["burr[start]==0.22.1"]
litellm = ["litellm>=1.94.0,<1.105.0"]
nvidia = ["langchain-nvidia-ai-endpoints>=0.1.0"]
ocr = [
"surya-ocr>=0.5.0",
Expand Down
22 changes: 18 additions & 4 deletions scrapegraphai/graphs/abstract_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from pydantic import BaseModel

from ..helpers import models_tokens
from ..models import XAI, CLoD, DeepSeek, MiniMax, Nvidia, OneApi
from ..models import XAI, CLoD, DeepSeek, LiteLLM, MiniMax, Nvidia, OneApi
from ..models.litellm import get_litellm_model_tokens
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",
"litellm",
}

if "/" in llm_params["model"]:
Expand Down Expand Up @@ -209,9 +211,17 @@ def _create_llm(self, llm_config: dict) -> object:

if llm_params.get("model_tokens", None) is None:
try:
self.model_token = models_tokens[llm_params["model_provider"]][
llm_params["model"]
]
if llm_params["model_provider"] == "litellm":
# LiteLLM routes to any provider, so read the context
# window from its model map instead of models_tokens.
model_token = get_litellm_model_tokens(llm_params["model"])
if model_token is None:
raise KeyError(llm_params["model"])
self.model_token = model_token
else:
self.model_token = models_tokens[llm_params["model_provider"]][
llm_params["model"]
]
except KeyError:
logger.warning(
"Max input tokens for model %s/%s not found, "
Expand Down Expand Up @@ -243,6 +253,7 @@ def _create_llm(self, llm_config: dict) -> object:
"clod",
"xai",
"minimax",
"litellm",
}:
if llm_params["model_provider"] == "bedrock":
llm_params["model_kwargs"] = {
Expand All @@ -263,6 +274,9 @@ def _create_llm(self, llm_config: dict) -> object:
if model_provider == "minimax":
return MiniMax(**llm_params)

if model_provider == "litellm":
return LiteLLM(**llm_params)

if model_provider == "ernie":
from langchain_community.chat_models import ErnieBotChat

Expand Down
3 changes: 2 additions & 1 deletion scrapegraphai/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
from .cheaperinference import CheaperInference
from .clod import CLoD
from .deepseek import DeepSeek
from .litellm import LiteLLM
from .minimax import MiniMax
from .nvidia import Nvidia
from .oneapi import OneApi
from .openai_itt import OpenAIImageToText
from .openai_tts import OpenAITextToSpeech
from .xai import XAI

__all__ = ["AtlasCloud", "CheaperInference", "DeepSeek", "MiniMax", "OneApi", "OpenAIImageToText", "OpenAITextToSpeech", "CLoD", "XAI", "Nvidia"]
__all__ = ["AtlasCloud", "CheaperInference", "DeepSeek", "LiteLLM", "MiniMax", "OneApi", "OpenAIImageToText", "OpenAITextToSpeech", "CLoD", "XAI", "Nvidia"]
Loading