Skip to content

Commit 3423033

Browse files
LLM now pastes Context() instead of BaseCallerContext() to indicate that a context is required
1 parent f867e25 commit 3423033

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

src/dbally/context/context.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
class BaseCallerContext(ABC):
1313
"""
1414
An interface for contexts that are used to pass additional knowledge about
15-
the caller environment to the filters. LLM will always return `BaseCallerContext()`
15+
the caller environment to the filters. LLM will always return `Context()`
1616
when the context is required and this call will be later substituted by an instance of
1717
a class implementing this interface, selected based on the filter method signature (type hints).
1818
"""
1919

20+
_alias: str = "Context"
21+
2022
@classmethod
2123
def select_context(cls, contexts: Iterable[CustomContext]) -> Self:
2224
"""
@@ -55,4 +57,8 @@ def is_context_call(cls, node: ast.expr) -> bool:
5557
Verification result.
5658
"""
5759

58-
return isinstance(node, ast.Call) and isinstance(node.func, ast.Name) and node.func.id == cls.__name__
60+
return (
61+
isinstance(node, ast.Call)
62+
and isinstance(node.func, ast.Name)
63+
and node.func.id in [cls._alias, cls.__name__]
64+
)

src/dbally/iql_generator/prompt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ def __init__(
7474
"You MUST use only these methods:\n"
7575
"\n{filters}\n"
7676
"It is VERY IMPORTANT not to use methods other than those listed above."
77-
"Finally, if a called function argument value is not directly specified in the query but instead requires knowledge of some additional context, than substitute that argument value by: BaseCallerContext()."
77+
"Finally, if a called function argument value is not directly specified in the query but instead requires knowledge of some additional context, than substitute that argument value by: Context()."
7878
'The typical input phrase referencing some additional context contains the word "my" or similar phrasing, e.g. "my position name", "my company valuation".'
7979
"In that case, the part of the output will look like this:"
80-
"filter4(BaseCallerContext())"
80+
"filter4(Context())"
8181
"""If you DON'T KNOW HOW TO ANSWER DON'T SAY \"\", SAY: `UNSUPPORTED QUERY` INSTEAD! """
8282
"This is CRUCIAL, otherwise the system will crash. "
8383
),

tests/unit/iql/test_iql_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async def test_iql_parser():
2626
custom_context2 = AnotherTestCustomContext(some_field="aaa")
2727

2828
parsed = await IQLQuery.parse(
29-
"not (filter_by_name(['John', 'Anne']) and filter_by_city(BaseCallerContext()) and filter_by_company('deepsense.ai'))",
29+
"not (filter_by_name(['John', 'Anne']) and filter_by_city(Context()) and filter_by_company('deepsense.ai'))",
3030
allowed_functions=[
3131
ExposedFunction(
3232
name="filter_by_name", description="", parameters=[MethodParamWithTyping(name="name", type=List[str])]

tests/unit/test_iql_format.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ async def test_iql_prompt_format_default() -> None:
2323
"You MUST use only these methods:\n"
2424
"\n\n"
2525
"It is VERY IMPORTANT not to use methods other than those listed above."
26-
"Finally, if a called function argument value is not directly specified in the query but instead requires knowledge of some additional context, than substitute that argument value by: BaseCallerContext()."
26+
"Finally, if a called function argument value is not directly specified in the query but instead requires knowledge of some additional context, than substitute that argument value by: Context()."
2727
'The typical input phrase referencing some additional context contains the word "my" or similar phrasing, e.g. "my position name", "my company valuation".'
2828
"In that case, the part of the output will look like this:"
29-
"filter4(BaseCallerContext())"
29+
"filter4(Context())"
3030
"""If you DON'T KNOW HOW TO ANSWER DON'T SAY \"\", SAY: `UNSUPPORTED QUERY` INSTEAD! """
3131
"This is CRUCIAL, otherwise the system will crash. ",
3232
"is_example": False,
@@ -57,10 +57,10 @@ async def test_iql_prompt_format_few_shots_injected() -> None:
5757
"You MUST use only these methods:\n"
5858
"\n\n"
5959
"It is VERY IMPORTANT not to use methods other than those listed above."
60-
"Finally, if a called function argument value is not directly specified in the query but instead requires knowledge of some additional context, than substitute that argument value by: BaseCallerContext()."
60+
"Finally, if a called function argument value is not directly specified in the query but instead requires knowledge of some additional context, than substitute that argument value by: Context()."
6161
'The typical input phrase referencing some additional context contains the word "my" or similar phrasing, e.g. "my position name", "my company valuation".'
6262
"In that case, the part of the output will look like this:"
63-
"filter4(BaseCallerContext())"
63+
"filter4(Context())"
6464
"""If you DON'T KNOW HOW TO ANSWER DON'T SAY \"\", SAY: `UNSUPPORTED QUERY` INSTEAD! """
6565
"This is CRUCIAL, otherwise the system will crash. ",
6666
"is_example": False,

0 commit comments

Comments
 (0)