Fix import error in ChatVertexAIComponent

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-02-22 14:57:03 -03:00
commit c335bf681a

View file

@ -1,7 +1,7 @@
from typing import List, Optional from typing import List, Optional
from langchain_google_vertexai import ChatVertexAI
from langchain_core.messages.base import BaseMessage from langchain_core.messages.base import BaseMessage
from langflow import CustomComponent from langflow import CustomComponent
from langflow.field_typing import Text from langflow.field_typing import Text
@ -62,7 +62,7 @@ class ChatVertexAIComponent(CustomComponent):
def build( def build(
self, self,
inputs:str, inputs: str,
credentials: Optional[str], credentials: Optional[str],
project: str, project: str,
examples: Optional[List[BaseMessage]] = [], examples: Optional[List[BaseMessage]] = [],
@ -74,6 +74,12 @@ class ChatVertexAIComponent(CustomComponent):
top_p: float = 0.95, top_p: float = 0.95,
verbose: bool = False, verbose: bool = False,
) -> Text: ) -> Text:
try:
from langchain_google_vertexai import ChatVertexAI
except ImportError:
raise ImportError(
"To use the ChatVertexAI model, you need to install the langchain-google-vertexai package."
)
output = ChatVertexAI( output = ChatVertexAI(
credentials=credentials, credentials=credentials,
examples=examples, examples=examples,