mirror of
https://github.com/VinciGit00/Scrapegraph-ai.git
synced 2026-07-01 21:00:48 +08:00
feat: add vertexai integration
This commit is contained in:
parent
79a2f51c34
commit
119514bdfc
@ -16,6 +16,7 @@ dependencies = [
|
|||||||
"langchain==0.1.15",
|
"langchain==0.1.15",
|
||||||
"langchain-openai==0.1.6",
|
"langchain-openai==0.1.6",
|
||||||
"langchain-google-genai==1.0.3",
|
"langchain-google-genai==1.0.3",
|
||||||
|
"langchain-google-vertexai==1.0.6",
|
||||||
"langchain-groq==0.1.3",
|
"langchain-groq==0.1.3",
|
||||||
"langchain-aws==0.1.3",
|
"langchain-aws==0.1.3",
|
||||||
"langchain-anthropic==0.1.11",
|
"langchain-anthropic==0.1.11",
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
langchain==0.1.14
|
langchain==0.1.14
|
||||||
langchain-openai==0.1.1
|
langchain-openai==0.1.1
|
||||||
langchain-google-genai==1.0.1
|
langchain-google-genai==1.0.1
|
||||||
|
langchain-google-vertexai==1.0.6
|
||||||
langchain-anthropic==0.1.11
|
langchain-anthropic==0.1.11
|
||||||
html2text==2020.1.16
|
html2text==2020.1.16
|
||||||
faiss-cpu==1.8.0
|
faiss-cpu==1.8.0
|
||||||
|
|||||||
@ -10,9 +10,9 @@ from pydantic import BaseModel
|
|||||||
from langchain_aws import BedrockEmbeddings
|
from langchain_aws import BedrockEmbeddings
|
||||||
from langchain_community.embeddings import HuggingFaceHubEmbeddings, OllamaEmbeddings
|
from langchain_community.embeddings import HuggingFaceHubEmbeddings, OllamaEmbeddings
|
||||||
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
||||||
|
from langchain_google_vertexai import VertexAIEmbeddings
|
||||||
from langchain_google_genai.embeddings import GoogleGenerativeAIEmbeddings
|
from langchain_google_genai.embeddings import GoogleGenerativeAIEmbeddings
|
||||||
from langchain_openai import AzureOpenAIEmbeddings, OpenAIEmbeddings
|
from langchain_openai import AzureOpenAIEmbeddings, OpenAIEmbeddings
|
||||||
|
|
||||||
from ..helpers import models_tokens
|
from ..helpers import models_tokens
|
||||||
from ..models import (
|
from ..models import (
|
||||||
Anthropic,
|
Anthropic,
|
||||||
@ -23,7 +23,8 @@ from ..models import (
|
|||||||
HuggingFace,
|
HuggingFace,
|
||||||
Ollama,
|
Ollama,
|
||||||
OpenAI,
|
OpenAI,
|
||||||
OneApi
|
OneApi,
|
||||||
|
VertexAI
|
||||||
)
|
)
|
||||||
from ..models.ernie import Ernie
|
from ..models.ernie import Ernie
|
||||||
from ..utils.logging import set_verbosity_debug, set_verbosity_warning, set_verbosity_info
|
from ..utils.logging import set_verbosity_debug, set_verbosity_warning, set_verbosity_info
|
||||||
@ -170,7 +171,6 @@ class AbstractGraph(ABC):
|
|||||||
except KeyError as exc:
|
except KeyError as exc:
|
||||||
raise KeyError("Model not supported") from exc
|
raise KeyError("Model not supported") from exc
|
||||||
return AzureOpenAI(llm_params)
|
return AzureOpenAI(llm_params)
|
||||||
|
|
||||||
elif "gemini" in llm_params["model"]:
|
elif "gemini" in llm_params["model"]:
|
||||||
try:
|
try:
|
||||||
self.model_token = models_tokens["gemini"][llm_params["model"]]
|
self.model_token = models_tokens["gemini"][llm_params["model"]]
|
||||||
@ -183,6 +183,12 @@ class AbstractGraph(ABC):
|
|||||||
except KeyError as exc:
|
except KeyError as exc:
|
||||||
raise KeyError("Model not supported") from exc
|
raise KeyError("Model not supported") from exc
|
||||||
return Anthropic(llm_params)
|
return Anthropic(llm_params)
|
||||||
|
elif llm_params["model"].startswith("vertexai"):
|
||||||
|
try:
|
||||||
|
self.model_token = models_tokens["vertexai"][llm_params["model"]]
|
||||||
|
except KeyError as exc:
|
||||||
|
raise KeyError("Model not supported") from exc
|
||||||
|
return VertexAI(llm_params)
|
||||||
elif "ollama" in llm_params["model"]:
|
elif "ollama" in llm_params["model"]:
|
||||||
llm_params["model"] = llm_params["model"].split("ollama/")[-1]
|
llm_params["model"] = llm_params["model"].split("ollama/")[-1]
|
||||||
|
|
||||||
@ -275,10 +281,12 @@ class AbstractGraph(ABC):
|
|||||||
google_api_key=llm_config["api_key"], model="models/embedding-001"
|
google_api_key=llm_config["api_key"], model="models/embedding-001"
|
||||||
)
|
)
|
||||||
if isinstance(self.llm_model, OpenAI):
|
if isinstance(self.llm_model, OpenAI):
|
||||||
return OpenAIEmbeddings(api_key=self.llm_model.openai_api_key, base_url=self.llm_model.openai_api_base)
|
return OpenAIEmbeddings(api_key=self.llm_model.openai_api_key,
|
||||||
|
base_url=self.llm_model.openai_api_base)
|
||||||
elif isinstance(self.llm_model, DeepSeek):
|
elif isinstance(self.llm_model, DeepSeek):
|
||||||
return OpenAIEmbeddings(api_key=self.llm_model.openai_api_key)
|
return OpenAIEmbeddings(api_key=self.llm_model.openai_api_key)
|
||||||
|
elif isinstance(self.llm_model, VertexAI):
|
||||||
|
return VertexAIEmbeddings()
|
||||||
elif isinstance(self.llm_model, AzureOpenAIEmbeddings):
|
elif isinstance(self.llm_model, AzureOpenAIEmbeddings):
|
||||||
return self.llm_model
|
return self.llm_model
|
||||||
elif isinstance(self.llm_model, AzureOpenAI):
|
elif isinstance(self.llm_model, AzureOpenAI):
|
||||||
|
|||||||
@ -75,6 +75,11 @@ models_tokens = {
|
|||||||
"claude2.1": 200000,
|
"claude2.1": 200000,
|
||||||
"claude3": 200000
|
"claude3": 200000
|
||||||
},
|
},
|
||||||
|
"vertexai": {
|
||||||
|
"gemini-1.5-flash": 128000,
|
||||||
|
"gemini-1.5-pro": 128000,
|
||||||
|
"gemini-1.0-pro": 128000
|
||||||
|
},
|
||||||
"bedrock": {
|
"bedrock": {
|
||||||
"anthropic.claude-3-haiku-20240307-v1:0": 200000,
|
"anthropic.claude-3-haiku-20240307-v1:0": 200000,
|
||||||
"anthropic.claude-3-sonnet-20240229-v1:0": 200000,
|
"anthropic.claude-3-sonnet-20240229-v1:0": 200000,
|
||||||
|
|||||||
@ -14,3 +14,4 @@ from .bedrock import Bedrock
|
|||||||
from .anthropic import Anthropic
|
from .anthropic import Anthropic
|
||||||
from .deepseek import DeepSeek
|
from .deepseek import DeepSeek
|
||||||
from .oneapi import OneApi
|
from .oneapi import OneApi
|
||||||
|
from .vertex import VertexAI
|
||||||
|
|||||||
16
scrapegraphai/models/vertex.py
Normal file
16
scrapegraphai/models/vertex.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
"""
|
||||||
|
VertexAI Module
|
||||||
|
"""
|
||||||
|
from langchain_google_vertexai import ChatVertexAI
|
||||||
|
|
||||||
|
class VertexAI(ChatVertexAI):
|
||||||
|
"""
|
||||||
|
A wrapper for the ChatVertexAI class that provides default configuration
|
||||||
|
and could be extended with additional methods if needed.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
llm_config (dict): Configuration parameters for the language model.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, llm_config: dict):
|
||||||
|
super().__init__(**llm_config)
|
||||||
Loading…
Reference in New Issue
Block a user