🔧 chore(llm.py): add function to initialize VertexAI credentials

🔧 chore(loading.py): call initialize_vertexai function when node_type is "VertexAI"
The `llm.py` file now includes a new function `initialize_vertexai` that initializes the VertexAI credentials if a `credentials` parameter is provided. This allows for the usage of VertexAI credentials in the application. In `loading.py`, the `initialize_vertexai` function is called when the `node_type` is "VertexAI", ensuring that the VertexAI credentials are properly initialized for that specific node type.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-30 10:09:29 -03:00
commit 3bdc35d238
2 changed files with 12 additions and 0 deletions

View file

@ -0,0 +1,9 @@
def initialize_vertexai(class_object, params):
if credentials_path := params.get("credentials"):
from google.oauth2 import service_account
credentials_object = service_account.Credentials.from_service_account_file(
filename=credentials_path
)
params["credentials"] = credentials_object
return class_object(**params)

View file

@ -6,6 +6,7 @@ from langchain.agents import agent as agent_module
from langchain.agents.agent import AgentExecutor
from langchain.agents.agent_toolkits.base import BaseToolkit
from langchain.agents.tools import BaseTool
from langflow.interface.initialize.llm import initialize_vertexai
from langflow.interface.initialize.vector_store import vecstore_initializer
@ -89,6 +90,8 @@ def instantiate_llm(node_type, class_object, params: Dict):
# if "openai_api_base" in params and "jina" in params["openai_api_base"]:
# False if condition is True
ChatConfig.streaming = "jina" not in params.get("openai_api_base", "")
if node_type == "VertexAI":
return initialize_vertexai(class_object=class_object, params=params)
return class_object(**params)