Skip to content

Commit 308e2e1

Browse files
context record is now based on pydantic.BaseModel rather than dataclass + type hint improvements: fixes, new generics and aliases
1 parent 78f1535 commit 308e2e1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/dbally/context/context.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import ast
22

3-
from typing import List, Optional
3+
from typing import List, Optional, Type, TypeVar
44
from typing_extensions import Self
5-
from dataclasses import dataclass
5+
from pydantic import BaseModel
66

77
from dbally.context.exceptions import ContextNotAvailableError
88

99

10-
@dataclass
11-
class BaseCallerContext:
10+
T = TypeVar('T', bound='BaseCallerContext')
11+
AllCallerContexts = Optional[List[T]] # TODO confirm the naming
12+
13+
14+
class BaseCallerContext(BaseModel):
1215
"""
1316
Base class for contexts that are used to pass additional knowledge about the caller environment to the filters. It is not made abstract for the convinience of IQL parsing.
1417
LLM will always return `BaseCallerContext()` when the context is required and this call will be later substitue by a proper subclass instance selected based on the filter method signature (type hints).
1518
"""
1619

1720
@classmethod
18-
def select_context(cls, contexts: List[Self]) -> Self:
21+
def select_context(cls, contexts: List[T]) -> T:
1922
if not contexts:
2023
raise ContextNotAvailableError("The LLM detected that the context is required to execute the query and the filter signature allows contextualization while the context was not provided.")
2124

0 commit comments

Comments
 (0)