You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
17
-
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).
15
+
Pydantic-based record class. Base class for contexts that are used to pass additional knowledge about
16
+
the caller environment to the filters. It is not made abstract for the convinience of IQL parsing.
17
+
LLM will always return `BaseCallerContext()` when the context is required and this call will be
18
+
later substituted by a proper subclass instance selected based on the filter method signature (type hints).
Typically called from a subclass of BaseCallerContext, selects a member object from `contexts` being
25
+
an instance of the same class. Effectively provides a type dispatch mechanism, substituting the context
26
+
class by its right instance.
27
+
28
+
Args:
29
+
contexts: A sequence of objects, each being an instance of a different BaseCallerContext subclass.
30
+
31
+
Returns:
32
+
An instance of the same BaseCallerContext subclass this method is caller from.
33
+
34
+
Raises:
35
+
ContextNotAvailableError: If the sequence of context objects passed as argument is empty.
36
+
"""
37
+
22
38
ifnotcontexts:
23
-
raiseContextNotAvailableError("The LLM detected that the context is required to execute the query and the filter signature allows contextualization while the context was not provided.")
39
+
raiseContextNotAvailableError(
40
+
"The LLM detected that the context is required to execute the query +\
41
+
and the filter signature allows contextualization while the context was not provided."
42
+
)
24
43
25
-
# this method is called from the subclass of BaseCallerContext pointing the right type of custom context
iffunc.idnotinself.allowed_functions:# TODO add context class constructors to self.allowed_functions
107
+
iffunc.idnotinself.allowed_functions:
93
108
raiseIQLFunctionNotExists(func, self.source)
94
109
95
110
func_def=self.allowed_functions[func.id]
@@ -117,9 +132,8 @@ def _parse_arg(
117
132
self,
118
133
arg: ast.expr,
119
134
arg_spec: Optional[MethodParamWithTyping] =None,
120
-
parent_func_def: Optional[ExposedFunction] =None
135
+
parent_func_def: Optional[ExposedFunction] =None,
121
136
) ->Any:
122
-
123
137
ifisinstance(arg, ast.List):
124
138
return [self._parse_arg(x) forxinarg.elts]
125
139
@@ -129,10 +143,16 @@ def _parse_arg(
129
143
raiseIQLArgumentParsingError(arg, self.source)
130
144
131
145
ifparent_func_def.context_classisNone:
132
-
raiseContextualisationNotAllowed("The LLM detected that the context is required to execute the query while the filter signature does not allow it at all.")
146
+
raiseContextualisationNotAllowed(
147
+
"The LLM detected that the context is required +\
148
+
to execute the query while the filter signature does not allow it at all."
149
+
)
133
150
134
151
ifnot_does_arg_allow_context(arg_spec):
135
-
raiseContextualisationNotAllowed(f"The LLM detected that the context is required to execute the query while the filter signature does allow it for `{arg_spec.name}` argument.")
152
+
raiseContextualisationNotAllowed(
153
+
f"The LLM detected that the context is required +\
154
+
to execute the query while the filter signature does allow it for `{arg_spec.name}` argument."
actual_type=type_ext.get_origin(required_type) ifisinstance(required_type, _GenericAlias) elserequired_type# typing.Union is an instance of _GenericAlias
71
-
ifactual_typeisNone: # workaround to prevent type warning in line `if isisntanc(value, actual_type):`, TODO check whether necessary
0 commit comments