Skip to content

Commit

Permalink
make compatible with python 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
AdeelH committed Dec 6, 2024
1 parent 35d1295 commit de8d454
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/e84_geoai_common/llm/models/claude.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from collections.abc import Callable, Sequence
from typing import Any, Literal, Self
from typing import TYPE_CHECKING, Any, Literal

import boto3
import botocore.exceptions
Expand All @@ -13,6 +13,9 @@
from e84_geoai_common.llm.core.llm import LLM, LLMInferenceConfig, LLMMessage
from e84_geoai_common.util import timed_function

if TYPE_CHECKING:
from typing import Self

log = logging.getLogger(__name__)

# See https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-anthropic-claude-messages.html
Expand Down Expand Up @@ -68,7 +71,7 @@ class ClaudeMessage(LLMMessage):
)

@classmethod
def from_llm_message(cls, message: LLMMessage) -> Self:
def from_llm_message(cls, message: LLMMessage) -> "Self":
"""Construct from an LLMMessage."""
return cls.model_validate(message.model_dump())

Expand Down Expand Up @@ -120,7 +123,7 @@ class ClaudeTool(BaseModel):
_func: Callable[..., Any]

@classmethod
def from_function(cls, func: Callable[..., Any]) -> Self:
def from_function(cls, func: Callable[..., Any]) -> "Self":
"""Construct from a Python funtion."""
schema = get_function_schema(func, format="claude") # type: ignore[reportUnknownVariableType]
out = cls.model_validate(schema)
Expand Down Expand Up @@ -188,7 +191,7 @@ def from_inference_config(
cls,
cfg: LLMInferenceConfig,
messages: Sequence[ClaudeMessage] | None = None,
) -> Self:
) -> "Self":
"""Construct from an LLMInferenceConfig."""
messages = [] if messages is None else list(messages)
response_prefix = cfg.response_prefix
Expand Down

0 comments on commit de8d454

Please sign in to comment.