Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Conditional imports to support pydantic>2
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisguidry committed Oct 4, 2023
1 parent fa78134 commit 004a3a0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 7 additions & 1 deletion prefect_openai/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
from prefect.logging.loggers import get_logger, get_run_logger
from prefect.tasks import Task
from prefect.utilities.asyncutils import is_async_fn, sync_compatible
from pydantic import Field
from pydantic import VERSION as PYDANTIC_VERSION

if PYDANTIC_VERSION.startswith("2."):
from pydantic.v1 import Field
else:
from pydantic import Field

from typing_extensions import Literal

from prefect_openai import OpenAICredentials
Expand Down
7 changes: 6 additions & 1 deletion prefect_openai/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

import openai
from prefect.blocks.abstract import CredentialsBlock
from pydantic import Field, SecretStr
from pydantic import VERSION as PYDANTIC_VERSION

if PYDANTIC_VERSION.startswith("2."):
from pydantic.v1 import Field, SecretStr
else:
from pydantic import Field, SecretStr


class OpenAICredentials(CredentialsBlock):
Expand Down
8 changes: 7 additions & 1 deletion prefect_openai/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
from prefect.exceptions import MissingContextError
from prefect.logging.loggers import get_logger, get_run_logger
from prefect.utilities.asyncutils import sync_compatible
from pydantic import Field
from pydantic import VERSION as PYDANTIC_VERSION

if PYDANTIC_VERSION.startswith("2."):
from pydantic.v1 import Field
else:
from pydantic import Field

from typing_extensions import Literal

from prefect_openai import OpenAICredentials
Expand Down

0 comments on commit 004a3a0

Please sign in to comment.