mirror of
https://github.com/VinciGit00/Scrapegraph-ai.git
synced 2026-06-25 21:11:11 +08:00
feat(llm): implemented groq model
This commit is contained in:
parent
6e0c001946
commit
dbbf10fc77
49
examples/mixed_models/smart_scraper_mixed.py
Normal file
49
examples/mixed_models/smart_scraper_mixed.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
"""
|
||||||
|
Basic example of scraping pipeline using SmartScraper
|
||||||
|
"""
|
||||||
|
|
||||||
|
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
|
||||||
|
# ************************************************
|
||||||
|
|
||||||
|
groq_key = os.getenv("GROQ_APIKEY")
|
||||||
|
|
||||||
|
graph_config = {
|
||||||
|
"llm": {
|
||||||
|
"model": "groq/gemma-7b-it",
|
||||||
|
"api_key": groq_key,
|
||||||
|
"temperature": 0
|
||||||
|
},
|
||||||
|
"embeddings": {
|
||||||
|
"model": "ollama/nomic-embed-text",
|
||||||
|
"temperature": 0,
|
||||||
|
"base_url": "http://localhost:11434", # set ollama URL arbitrarily
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# ************************************************
|
||||||
|
# Create the SmartScraperGraph instance and run it
|
||||||
|
# ************************************************
|
||||||
|
|
||||||
|
smart_scraper_graph = SmartScraperGraph(
|
||||||
|
prompt="List me all the projects with their description and the author.",
|
||||||
|
# also accepts a string with the already downloaded HTML code
|
||||||
|
source="https://perinim.github.io/projects",
|
||||||
|
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))
|
||||||
2807
poetry.lock
generated
2807
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -3,7 +3,7 @@ Module having abstract class for creating all the graphs
|
|||||||
"""
|
"""
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from ..models import OpenAI, Gemini, Ollama, AzureOpenAI, HuggingFace
|
from ..models import OpenAI, Gemini, Ollama, AzureOpenAI, HuggingFace, Groq
|
||||||
from ..helpers import models_tokens
|
from ..helpers import models_tokens
|
||||||
|
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ class AbstractGraph(ABC):
|
|||||||
self.source = source
|
self.source = source
|
||||||
self.config = config
|
self.config = config
|
||||||
self.llm_model = self._create_llm(config["llm"])
|
self.llm_model = self._create_llm(config["llm"])
|
||||||
self.embedder_model = None if "embeddings" not in config else self._create_llm(
|
self.embedder_model = self.llm_model if "embeddings" not in config else self._create_llm(
|
||||||
config["embeddings"])
|
config["embeddings"])
|
||||||
self.graph = self._create_graph()
|
self.graph = self._create_graph()
|
||||||
self.final_state = None
|
self.final_state = None
|
||||||
@ -84,6 +84,14 @@ class AbstractGraph(ABC):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
raise KeyError("Model not supported")
|
raise KeyError("Model not supported")
|
||||||
return HuggingFace(llm_params)
|
return HuggingFace(llm_params)
|
||||||
|
elif "groq" in llm_params["model"]:
|
||||||
|
llm_params["model"] = llm_params["model"].split("/")[-1]
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.model_token = models_tokens["groq"][llm_params["model"]]
|
||||||
|
except KeyError:
|
||||||
|
raise KeyError("Model not supported")
|
||||||
|
return Groq(llm_params)
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Model provided by the configuration not supported")
|
"Model provided by the configuration not supported")
|
||||||
|
|||||||
@ -32,7 +32,11 @@ models_tokens = {
|
|||||||
"mistral-openorca": 32000,
|
"mistral-openorca": 32000,
|
||||||
"stablelm-zephyr": 8192
|
"stablelm-zephyr": 8192
|
||||||
},
|
},
|
||||||
"gemma": {
|
|
||||||
"gemma": 8192,
|
"groq": {
|
||||||
}
|
"llama3-8b-8192": 8192,
|
||||||
|
"llama3-70b-8192": 8192,
|
||||||
|
"mixtral-8x7b-32768": 32768,
|
||||||
|
"gemma-7b-it": 8192,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,3 +9,4 @@ from .openai_tts import OpenAITextToSpeech
|
|||||||
from .gemini import Gemini
|
from .gemini import Gemini
|
||||||
from .ollama import Ollama
|
from .ollama import Ollama
|
||||||
from .hugging_face import HuggingFace
|
from .hugging_face import HuggingFace
|
||||||
|
from .groq import Groq
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user