Skip to content

Commit

Permalink
fix: fixing ruff errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanleomk committed Dec 18, 2024
1 parent 6b5c90e commit 31ef97a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
8 changes: 3 additions & 5 deletions instructor/client_vertexai.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, Type, Union, get_origin
from typing import Any, Union, get_origin

from vertexai.preview.generative_models import ToolConfig # type: ignore
import vertexai.generative_models as gm # type: ignore
Expand All @@ -27,16 +27,14 @@ def _create_gemini_json_schema(model: BaseModel):
return gemini_schema


def _create_vertexai_tool(models: Union[BaseModel, list[BaseModel], Type]) -> gm.Tool:
def _create_vertexai_tool(models: Union[BaseModel, list[BaseModel], type]) -> gm.Tool: # noqa: UP007
"""Creates a tool with function declarations for single model or list of models"""
# Handle Iterable case first
if get_origin(models) is not None:
model_list = list(get_types_array(models))

Check failure on line 34 in instructor/client_vertexai.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Type of "model_list" is partially unknown   Type of "model_list" is "list[Unknown]" (reportUnknownVariableType)

Check failure on line 34 in instructor/client_vertexai.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Argument type is partially unknown   Argument corresponds to parameter "iterable" in function "__init__"   Argument type is "tuple[Unknown, ...]" (reportUnknownArgumentType)

Check failure on line 34 in instructor/client_vertexai.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Argument of type "BaseModel | list[BaseModel] | type" cannot be assigned to parameter "typehint" of type "type[Iterable[T@get_types_array]]" in function "get_types_array"   Type "BaseModel | list[BaseModel] | type" is incompatible with type "type[Iterable[T@get_types_array]]"     Type "BaseModel" is incompatible with type "type[Iterable[T@get_types_array]]" (reportArgumentType)

Check failure on line 34 in instructor/client_vertexai.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-latest, 3.11)

Type of "model_list" is partially unknown   Type of "model_list" is "list[Unknown]" (reportUnknownVariableType)

Check failure on line 34 in instructor/client_vertexai.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-latest, 3.11)

Argument type is partially unknown   Argument corresponds to parameter "iterable" in function "__init__"   Argument type is "tuple[Unknown, ...]" (reportUnknownArgumentType)

Check failure on line 34 in instructor/client_vertexai.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-latest, 3.11)

Argument of type "BaseModel | list[BaseModel] | type" cannot be assigned to parameter "typehint" of type "type[Iterable[T@get_types_array]]" in function "get_types_array"   Type "BaseModel | list[BaseModel] | type" is incompatible with type "type[Iterable[T@get_types_array]]"     Type "BaseModel" is incompatible with type "type[Iterable[T@get_types_array]]" (reportArgumentType)
else:
# Handle both single model and list of models
model_list = models if isinstance(models, list) else [models]

print(f"Debug - Model list: {[model.__name__ for model in model_list]}")

declarations = []
for model in model_list:

Check failure on line 40 in instructor/client_vertexai.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Type of "model" is partially unknown   Type of "model" is "Unknown | BaseModel | type" (reportUnknownVariableType)

Check failure on line 40 in instructor/client_vertexai.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-latest, 3.11)

Type of "model" is partially unknown   Type of "model" is "Unknown | BaseModel | type" (reportUnknownVariableType)
Expand Down Expand Up @@ -101,7 +99,7 @@ def vertexai_function_response_parser(
)


def vertexai_process_response(_kwargs: dict[str, Any], model: Union[BaseModel, list[BaseModel], Type]):
def vertexai_process_response(_kwargs: dict[str, Any], model: Union[BaseModel, list[BaseModel], type]): # noqa: UP007
messages: list[dict[str, str]] = _kwargs.pop("messages")
contents = _vertexai_message_list_parser(messages) # type: ignore

Expand Down
1 change: 0 additions & 1 deletion instructor/process_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ def handle_vertexai_parallel_tools(
), "stream=True is not supported when using PARALLEL_TOOLS mode"

from instructor.client_vertexai import vertexai_process_response
from instructor.dsl.parallel import VertexAIParallelModel

# Extract concrete types before passing to vertexai_process_response
model_types = list(get_types_array(response_model))
Expand Down
2 changes: 1 addition & 1 deletion tests/llm/test_vertexai/test_modes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from itertools import product
from pydantic import BaseModel, Field
from pydantic import BaseModel
import vertexai.generative_models as gm # type: ignore
import pytest
import instructor
Expand Down

0 comments on commit 31ef97a

Please sign in to comment.