Skip to content

Commit 8c7c3e3

Browse files
committed
Merge branch 'pre/beta' of https://github.com/VinciGit00/Scrapegraph-ai into pre/beta
2 parents ac0a2e5 + 6911e21 commit 8c7c3e3

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## [0.9.0-beta.7](https://github.com/VinciGit00/Scrapegraph-ai/compare/v0.9.0-beta.6...v0.9.0-beta.7) (2024-05-06)
2+
3+
4+
### Bug Fixes
5+
6+
* **llm:** fixed gemini api_key ([fd01b73](https://github.com/VinciGit00/Scrapegraph-ai/commit/fd01b73b71b515206cfdf51c1d52136293494389))
7+
8+
## [0.9.0-beta.6](https://github.com/VinciGit00/Scrapegraph-ai/compare/v0.9.0-beta.5...v0.9.0-beta.6) (2024-05-06)
9+
10+
11+
### Features
12+
13+
* Fix bug for gemini case when embeddings config not passed ([726de28](https://github.com/VinciGit00/Scrapegraph-ai/commit/726de288982700dab8ab9f22af8e26f01c6198a7))
14+
115
## [0.9.0-beta.5](https://github.com/VinciGit00/Scrapegraph-ai/compare/v0.9.0-beta.4...v0.9.0-beta.5) (2024-05-06)
216

317

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "scrapegraphai"
33

4-
version = "0.9.0b5"
4+
version = "0.9.0b7"
55

66
description = "A web scraping library based on LangChain which uses LLM and direct graph logic to create scraping pipelines."
77
authors = [

scrapegraphai/graphs/abstract_graph.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self, prompt: str, config: dict, source: Optional[str] = None):
4646
self.source = source
4747
self.config = config
4848
self.llm_model = self._create_llm(config["llm"], chat=True)
49-
self.embedder_model = self._create_default_embedder(
49+
self.embedder_model = self._create_default_embedder(llm_config=config["llm"]
5050
) if "embeddings" not in config else self._create_embedder(
5151
config["embeddings"])
5252

@@ -91,6 +91,13 @@ def _set_model_token(self, llm):
9191
self.model_token = models_tokens['mistral'][llm.repo_id]
9292
except KeyError:
9393
raise KeyError("Model not supported")
94+
95+
elif 'Google' in str(type(llm)):
96+
try:
97+
if 'gemini' in llm.model:
98+
self.model_token = models_tokens['gemini'][llm.model]
99+
except KeyError:
100+
raise KeyError("Model not supported")
94101

95102
def _create_llm(self, llm_config: dict, chat=False) -> object:
96103
"""
@@ -197,7 +204,7 @@ def _create_llm(self, llm_config: dict, chat=False) -> object:
197204
raise ValueError(
198205
"Model provided by the configuration not supported")
199206

200-
def _create_default_embedder(self) -> object:
207+
def _create_default_embedder(self, llm_config=None) -> object:
201208
"""
202209
Create an embedding model instance based on the chosen llm model.
203210
@@ -207,6 +214,8 @@ def _create_default_embedder(self) -> object:
207214
Raises:
208215
ValueError: If the model is not supported.
209216
"""
217+
if isinstance(self.llm_model, Gemini):
218+
return GoogleGenerativeAIEmbeddings(google_api_key=llm_config['api_key'], model="models/embedding-001")
210219
if isinstance(self.llm_model, OpenAI):
211220
return OpenAIEmbeddings(api_key=self.llm_model.openai_api_key)
212221
elif isinstance(self.llm_model, AzureOpenAIEmbeddings):
@@ -241,7 +250,6 @@ def _create_embedder(self, embedder_config: dict) -> object:
241250
Raises:
242251
KeyError: If the model is not supported.
243252
"""
244-
245253
if 'model_instance' in embedder_config:
246254
return embedder_config['model_instance']
247255
# Instantiate the embedding model based on the model name

scrapegraphai/helpers/models_tokens.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"gemini": {
2828
"gemini-pro": 128000,
29+
"models/embedding-001": 2048
2930
},
3031

3132
"ollama": {

scrapegraphai/models/gemini.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ class Gemini(ChatGoogleGenerativeAI):
1515
"""
1616

1717
def __init__(self, llm_config: dict):
18+
# replace "api_key" to "google_api_key"
19+
llm_config["google_api_key"] = llm_config.pop("api_key", None)
1820
super().__init__(**llm_config)

0 commit comments

Comments
 (0)