refactor: disable type-var error code (#2868)

* fix: disable error code "type-var" in mypy configuration

* refactor(VertexAiModel.py): restructure the return statement to improve readability and maintainability by using type casting for LanguageModel
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-07-22 12:03:36 -03:00 committed by GitHub
commit decc979e99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 12 deletions

View file

@ -192,6 +192,7 @@ line-length = 120
[tool.mypy]
plugins = ["pydantic.mypy"]
follow_imports = "silent"
disable_error_code = ["type-var"]
[build-system]
requires = ["poetry-core"]

View file

@ -1,3 +1,5 @@
from typing import cast
from langflow.base.models.model import LCModelComponent
from langflow.field_typing import LanguageModel
from langflow.inputs import MessageTextInput
@ -37,8 +39,8 @@ class ChatVertexAIComponent(LCModelComponent):
)
location = self.location or None
if self.credentials:
from google.oauth2 import service_account
from google.cloud import aiplatform
from google.oauth2 import service_account
credentials = service_account.Credentials.from_service_account_file(self.credentials)
project = self.project or credentials.project_id
@ -52,15 +54,18 @@ class ChatVertexAIComponent(LCModelComponent):
project = self.project or None
credentials = None
return ChatVertexAI(
credentials=credentials,
location=location,
project=project,
max_output_tokens=self.max_output_tokens,
max_retries=self.max_retries,
model_name=self.model_name,
temperature=self.temperature,
top_k=self.top_k,
top_p=self.top_p,
verbose=self.verbose,
return cast(
LanguageModel,
ChatVertexAI(
credentials=credentials,
location=location,
project=project,
max_output_tokens=self.max_output_tokens,
max_retries=self.max_retries,
model_name=self.model_name,
temperature=self.temperature,
top_k=self.top_k,
top_p=self.top_p,
verbose=self.verbose,
),
)

View file

@ -97,6 +97,7 @@ markers = ["async_test"]
namespace_packages = true
mypy_path = "langflow"
ignore_missing_imports = true
disable_error_code = ["type-var"]
[tool.ruff]