Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
feat: add grok integration
Marco Vinciguerra0c476a4a7bbb
diff --git a/scrapegraphai/graphs/abstract_graph.py b/scrapegraphai/graphs/abstract_graph.pyindex c42e4daf..90f6efc2 100644--- a/scrapegraphai/graphs/abstract_graph.py+++ b/scrapegraphai/graphs/abstract_graph.py@@ -13,7 +13,7 @@ from langchain_core.rate_limiters import InMemoryRateLimiterfrom pydantic import BaseModelfrom ..helpers import models_tokens-from ..models import CLoD, DeepSeek, OneApi+from ..models import CLoD, DeepSeek, OneApi, XAIfrom ..utils.logging import set_verbosity_info, set_verbosity_warning@@ -163,6 +163,7 @@ class AbstractGraph(ABC):"fireworks","clod","togetherai",+ "xai",}if "/" in llm_params["model"]:@@ -217,6 +218,7 @@ class AbstractGraph(ABC):"deepseek","togetherai","clod",+ "xai",}:if llm_params["model_provider"] == "bedrock":llm_params["model_kwargs"] = {@@ -242,6 +244,9 @@ class AbstractGraph(ABC):elif model_provider == "oneapi":return OneApi(**llm_params)+ elif model_provider == "xai":+ return XAI(**llm_params)+elif model_provider == "togetherai":try:from langchain_together import ChatTogetherdiff --git a/scrapegraphai/helpers/models_tokens.py b/scrapegraphai/helpers/models_tokens.pyindex ec8e935d..4cd9fe6e 100644--- a/scrapegraphai/helpers/models_tokens.py+++ b/scrapegraphai/helpers/models_tokens.py@@ -150,7 +150,7 @@ models_tokens = {"llama3-70b-8192": 8192,"mixtral-8x7b-32768": 32768,"gemma-7b-it": 8192,- "claude-3-haiku-20240307'": 8192,+ "claude-3-haiku-20240307": 8192,},"toghetherai": {"meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo": 128000,@@ -303,4 +303,7 @@ models_tokens = {"grok-2-latest": 128000,},"togetherai": {"Meta-Llama-3.1-70B-Instruct-Turbo": 128000},+ "xai": {+ "grok-1": 8192+ },}diff --git a/scrapegraphai/models/__init__.py b/scrapegraphai/models/__init__.pyindex bb736a6b..0031f9a1 100644--- a/scrapegraphai/models/__init__.py+++ b/scrapegraphai/models/__init__.py@@ -7,5 +7,6 @@ from .deepseek import DeepSeekfrom .oneapi import OneApifrom .openai_itt import OpenAIImageToTextfrom .openai_tts import OpenAITextToSpeech+from .xai import XAI-__all__ = ["DeepSeek", "OneApi", "OpenAIImageToText", "OpenAITextToSpeech", "CLoD"]+__all__ = ["DeepSeek", "OneApi", "OpenAIImageToText", "OpenAITextToSpeech", "CLoD", "XAI"]diff --git a/scrapegraphai/models/xai.py b/scrapegraphai/models/xai.pynew file mode 100644index 00000000..405f88b6--- /dev/null+++ b/scrapegraphai/models/xai.py@@ -0,0 +1,23 @@+"""+xAI Grok Module+"""+from langchain_groq import ChatGroq as LangchainChatGroq++class XAI(LangchainChatGroq):+ """+ Wrapper for the ChatGroq class from langchain_groq, for use with xAI models.+ Handles API key mapping from generic 'api_key' to 'groq_api_key' and+ maps 'model' to 'model_name'.++ Args:+ llm_config (dict): Configuration parameters for the language model.+ """++ def __init__(self, **llm_config):+ if "api_key" in llm_config and "groq_api_key" not in llm_config:+ llm_config["groq_api_key"] = llm_config.pop("api_key")++ if "model" in llm_config and "model_name" not in llm_config:+ llm_config["model_name"] = llm_config.pop("model")++ super().__init__(**llm_config)\ No newline at end of file