Skip to content

Commit

Permalink
feat: update pydantic to v2 (#165)
Browse files Browse the repository at this point in the history
* update pydantic version, use pydantic.v1 for models that use aidial_sdk

* add VSCode extension for TOML linting

* Minor refactor

* Update pyproject.toml to poetry 2.0

* Fix bad merge with development
  • Loading branch information
roman-romanov-o authored Jan 10, 2025
1 parent 9244979 commit 752f239
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 62 deletions.
4 changes: 2 additions & 2 deletions aidial_adapter_vertexai/chat/bison/adapter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import AsyncIterator, List, Optional, TypedDict
from typing import AsyncIterator, List, Optional

from typing_extensions import override
from typing_extensions import TypedDict, override
from vertexai.preview.language_models import ChatModel, CodeChatModel

from aidial_adapter_vertexai.chat.bison.base import BisonChatCompletionAdapter
Expand Down
2 changes: 1 addition & 1 deletion aidial_adapter_vertexai/chat/gemini/prompt/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC
from typing import List, Set

from pydantic import BaseModel, Field
from pydantic.v1 import BaseModel, Field
from vertexai.preview.generative_models import Content, Part
from vertexai.preview.generative_models import Tool as GeminiTool

Expand Down
6 changes: 3 additions & 3 deletions aidial_adapter_vertexai/chat/static_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
StaticFunction,
StaticTool,
)
from pydantic import BaseModel, ConstrainedFloat, Field
from pydantic import ValidationError as PydanticValidationError
from pydantic import root_validator
from pydantic.v1 import BaseModel, ConstrainedFloat, Field
from pydantic.v1 import ValidationError as PydanticValidationError
from pydantic.v1 import root_validator
from vertexai.preview.generative_models import Tool as GeminiTool

from aidial_adapter_vertexai.chat.errors import ValidationError
Expand Down
2 changes: 1 addition & 1 deletion aidial_adapter_vertexai/chat/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ToolChoice,
)
from aidial_sdk.chat_completion.request import AzureChatCompletionRequest, Tool
from pydantic import BaseModel
from pydantic.v1 import BaseModel
from vertexai.preview.generative_models import (
FunctionDeclaration as GeminiFunction,
)
Expand Down
2 changes: 1 addition & 1 deletion aidial_adapter_vertexai/chat/truncate_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
InvalidRequestError,
TruncatePromptSystemAndLastUserError,
)
from pydantic import BaseModel
from pydantic.v1 import BaseModel

DiscardedMessages = List[int]

Expand Down
2 changes: 1 addition & 1 deletion aidial_adapter_vertexai/dial_api/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import List

from aidial_sdk.chat_completion import Attachment
from pydantic import BaseModel, Field, root_validator, validator
from pydantic.v1 import BaseModel, Field, root_validator, validator

from aidial_adapter_vertexai.dial_api.storage import FileStorage, download_file
from aidial_adapter_vertexai.utils.resource import Resource
Expand Down
3 changes: 2 additions & 1 deletion aidial_adapter_vertexai/dial_api/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import io
import mimetypes
import os
from typing import Mapping, Optional, TypedDict
from typing import Mapping, Optional
from urllib.parse import unquote, urljoin

import aiohttp
from pydantic import BaseModel
from typing_extensions import TypedDict

from aidial_adapter_vertexai.utils.log_config import app_logger as log

Expand Down
189 changes: 140 additions & 49 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fastapi = "0.115.2"
google-cloud-aiplatform = "^1.70.0"
google-auth = "2.21.0"
openai = "1.13.3"
pydantic = "1.10.13"
pydantic = "^2.10.4"
uvicorn = "0.22.0"
aiocache = "0.12.2"
pillow = "^10.3.0"
Expand Down Expand Up @@ -52,11 +52,13 @@ google-auth-oauthlib = "1.0.0"
[tool.pytest.ini_options]
addopts = "-n=auto --asyncio-mode=auto"
env_override_existing_values = 1
# muting warnings from google.rpc https://github.com/googleapis/google-cloud-python/issues/11184 and opentelemetry packages
filterwarnings = [
# muting warnings from google.rpc https://github.com/googleapis/google-cloud-python/issues/11184 and opentelemetry packages
"ignore:Deprecated call to `pkg_resources\\.declare_namespace\\('.*'\\):DeprecationWarning",
"ignore::DeprecationWarning:google.rpc",
"ignore::DeprecationWarning:opentelemetry.instrumentation.dependencies"
"ignore::DeprecationWarning:opentelemetry.instrumentation.dependencies",
# Pydantic v2 class-based config deprecation warning
"ignore:Support for class-based `config` is deprecated:DeprecationWarning",
]

[tool.pyright]
Expand Down

0 comments on commit 752f239

Please sign in to comment.