refactor: Update VertexAIEmbeddingsComponent to use Embeddings field type

Update the VertexAIEmbeddingsComponent to use the `Embeddings` field type instead of importing it from `langchain_google_vertexai`. This ensures compatibility with the latest version of the langflow library and improves code readability.
This commit is contained in:
ogabrielluiz 2024-06-11 20:40:52 -03:00
commit c40188f6b6

View file

@ -1,8 +1,7 @@
from typing import List, Optional
from langchain_google_vertexai import VertexAIEmbeddings
from langflow.custom import CustomComponent
from langflow.field_typing import Embeddings
class VertexAIEmbeddingsComponent(CustomComponent):
@ -71,7 +70,14 @@ class VertexAIEmbeddingsComponent(CustomComponent):
temperature: float = 0.0,
top_k: int = 40,
top_p: float = 0.95,
) -> VertexAIEmbeddings:
) -> Embeddings:
try:
from langchain_google_vertexai import VertexAIEmbeddings
except ImportError:
raise ImportError(
"Please install the langchain-google-vertexai package to use the VertexAIEmbeddings component."
)
return VertexAIEmbeddings(
instance=instance,
credentials=credentials,