Skip to content

Commit 0ded684

Browse files
post-merge fixes + minor refactor
1 parent efe212f commit 0ded684

File tree

6 files changed

+18
-8
lines changed

6 files changed

+18
-8
lines changed

src/dbally/collection/collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ async def ask(
157157
dry_run: bool = False,
158158
return_natural_response: bool = False,
159159
llm_options: Optional[LLMOptions] = None,
160-
context: Optional[CustomContextsList] = None
160+
contexts: Optional[CustomContextsList] = None
161161
) -> ExecutionResult:
162162
"""
163163
Ask question in a text form and retrieve the answer based on the available views.
@@ -217,7 +217,7 @@ async def ask(
217217
n_retries=self.n_retries,
218218
dry_run=dry_run,
219219
llm_options=llm_options,
220-
context=context
220+
contexts=contexts
221221
)
222222
end_time_view = time.monotonic()
223223

src/dbally/iql/_query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def parse(
3030
source: str,
3131
allowed_functions: List["ExposedFunction"],
3232
event_tracker: Optional[EventTracker] = None,
33-
context: Optional[CustomContextsList] = None
33+
contexts: Optional[CustomContextsList] = None
3434
) -> Self:
3535
"""
3636
Parse IQL string to IQLQuery object.
@@ -43,5 +43,5 @@ async def parse(
4343
IQLQuery object
4444
"""
4545

46-
root = await IQLProcessor(source, allowed_functions, context, event_tracker).process()
46+
root = await IQLProcessor(source, allowed_functions, contexts, event_tracker).process()
4747
return cls(root=root, source=source)

src/dbally/iql_generator/iql_generator.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from dbally.prompt.elements import FewShotExample
99
from dbally.prompt.template import PromptTemplate
1010
from dbally.views.exposed_functions import ExposedFunction
11+
from dbally.context.context import CustomContextsList
1112

1213
ERROR_MESSAGE = "Unfortunately, generated IQL is not valid. Please try again, \
1314
generation of correct IQL is very important. Below you have errors generated by the system:\n{error}"
@@ -42,7 +43,8 @@ async def generate_iql(
4243
examples: Optional[List[FewShotExample]] = None,
4344
llm_options: Optional[LLMOptions] = None,
4445
n_retries: int = 3,
45-
) -> IQLQuery:
46+
contexts: Optional[CustomContextsList] = None
47+
) -> Optional[IQLQuery]:
4648
"""
4749
Generates IQL in text form using LLM.
4850
@@ -60,7 +62,7 @@ async def generate_iql(
6062
prompt_format = IQLGenerationPromptFormat(
6163
question=question,
6264
filters=filters,
63-
examples=examples,
65+
examples=examples or [],
6466
)
6567
formatted_prompt = self._prompt_template.format_prompt(prompt_format)
6668

@@ -78,7 +80,9 @@ async def generate_iql(
7880
source=iql,
7981
allowed_functions=filters,
8082
event_tracker=event_tracker,
83+
contexts=contexts
8184
)
8285
except IQLError as exc:
86+
# TODO handle the possibility of variable `response` being not initialized while runnning the following line
8387
formatted_prompt = formatted_prompt.add_assistant_message(response)
8488
formatted_prompt = formatted_prompt.add_user_message(ERROR_MESSAGE.format(error=exc))

src/dbally/iql_generator/prompt.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ 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+
"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()."
78+
'The typical input phrase referencing some additional context contains the word "my" or similar phrasing, e.g. "my position name", "my company valuation".'
79+
"In that case, the part of the output will look like this:"
80+
"filter4(BaseCallerContext())"
81+
"It is VERY IMPORTANT not to use methods other than those listed above."
7782
"""If you DON'T KNOW HOW TO ANSWER DON'T SAY \"\", SAY: `UNSUPPORTED QUERY` INSTEAD! """
7883
"This is CRUCIAL, otherwise the system will crash. "
7984
),

src/dbally/views/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async def ask(
2727
n_retries: int = 3,
2828
dry_run: bool = False,
2929
llm_options: Optional[LLMOptions] = None,
30-
context: Optional[CustomContextsList] = None
30+
contexts: Optional[CustomContextsList] = None
3131
) -> ViewExecutionResult:
3232
"""
3333
Executes the query and returns the result.

src/dbally/views/structured.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def ask(
4242
n_retries: int = 3,
4343
dry_run: bool = False,
4444
llm_options: Optional[LLMOptions] = None,
45-
context: Optional[CustomContextsList] = None
45+
contexts: Optional[CustomContextsList] = None
4646
) -> ViewExecutionResult:
4747
"""
4848
Executes the query and returns the result. It generates the IQL query from the natural language query\
@@ -71,6 +71,7 @@ async def ask(
7171
event_tracker=event_tracker,
7272
llm_options=llm_options,
7373
n_retries=n_retries,
74+
contexts=contexts
7475
)
7576

7677
await self.apply_filters(iql)

0 commit comments

Comments
 (0)