Skip to content

Commit 999759b

Browse files
refactor: collection.results.[ViewExecutionResult, ExecutionResult]."context" -> "metadata" (to ommit confusing naming overlap with newly added contextualisation functionality); views.exposed_functions pylint warnings resolved
1 parent 1294a9c commit 999759b

File tree

24 files changed

+86
-60
lines changed

24 files changed

+86
-60
lines changed

src/dbally/audit/event_handlers/cli_event_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,5 @@ async def request_end(self, output: RequestEnd, request_context: Optional[dict]
127127
self._print_syntax("[green bold]REQUEST OUTPUT:")
128128
self._print_syntax(f"Number of rows: {len(output.result.results)}")
129129

130-
if "sql" in output.result.context:
131-
self._print_syntax(f"{output.result.context['sql']}", "psql")
130+
if "sql" in output.result.metadata:
131+
self._print_syntax(f"{output.result.metadata['sql']}", "psql")

src/dbally/audit/event_handlers/langsmith_event_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,5 @@ async def request_end(self, output: RequestEnd, request_context: RunTree) -> Non
101101
output: The output of the request. In this case - PSQL query.
102102
request_context: Optional context passed from request_start method
103103
"""
104-
request_context.end(outputs={"sql": output.result.context["sql"]})
104+
request_context.end(outputs={"sql": output.result.metadata["sql"]})
105105
request_context.post(exclude_child_runs=False)

src/dbally/collection/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ async def ask(
234234

235235
result = ExecutionResult(
236236
results=view_result.results,
237-
context=view_result.context,
237+
metadata=view_result.metadata,
238238
execution_time=time.monotonic() - start_time,
239239
execution_time_view=end_time_view - start_time_view,
240240
view_name=selected_view,

src/dbally/collection/results.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ViewExecutionResult:
1414
"""
1515

1616
results: List[Dict[str, Any]]
17-
context: Dict[str, Any]
17+
metadata: Dict[str, Any]
1818

1919

2020
@dataclass
@@ -37,7 +37,7 @@ class ExecutionResult:
3737
"""
3838

3939
results: List[Dict[str, Any]]
40-
context: Dict[str, Any]
40+
metadata: Dict[str, Any]
4141
execution_time: float
4242
execution_time_view: float
4343
view_name: str

src/dbally/context/context.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class BaseCallerContext(ABC):
1717
a class implementing this interface, selected based on the filter method signature (type hints).
1818
"""
1919

20-
_alias: str = "AskerContext"
20+
alias: str = "AskerContext"
2121

2222
@classmethod
2323
def select_context(cls, contexts: Iterable[CustomContext]) -> Self:
@@ -58,7 +58,5 @@ def is_context_call(cls, node: ast.expr) -> bool:
5858
"""
5959

6060
return (
61-
isinstance(node, ast.Call)
62-
and isinstance(node.func, ast.Name)
63-
and node.func.id in [cls._alias, cls.__name__]
61+
isinstance(node, ast.Call) and isinstance(node.func, ast.Name) and node.func.id in [cls.alias, cls.__name__]
6462
)

src/dbally/gradio/gradio_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ async def _ui_ask_query(
114114
execution_result = await self.collection.ask(
115115
question=question_query, return_natural_response=natural_language_flag
116116
)
117-
generated_query = str(execution_result.context)
117+
generated_query = str(execution_result.metadata)
118118
data = self._load_results_into_dataframe(execution_result.results)
119119
textual_response = str(execution_result.textual_response) if natural_language_flag else textual_response
120120
except UnsupportedQueryError:

src/dbally/iql_generator/prompt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ 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 some additional execution context, than substitute that argument value by: AskerContext()."
77+
"Finally, if a called function argument value is not directly specified in the query but instead requires some additional execution context, than substitute that argument value with: AskerContext()."
7878
'The typical input phrase suggesting that the additional execution context need to be referenced contains words like: "I", "my", "mine", "current", "the" etc..'
7979
'For example: "my position name", "my company valuation", "current day", "the ongoing project".'
8080
"In that case, the part of the output will look like this:"

src/dbally/nl_responder/nl_responder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async def generate_response(
7070
if tokens_count > self._max_tokens_count:
7171
prompt_format = QueryExplanationPromptFormat(
7272
question=question,
73-
context=result.context,
73+
metadata=result.metadata,
7474
results=result.results,
7575
)
7676
formatted_prompt = self._explainer_prompt_template.format_prompt(prompt_format)

src/dbally/nl_responder/prompts.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List
1+
from typing import Any, Dict, List, Optional
22

33
import pandas as pd
44

@@ -40,9 +40,9 @@ def __init__(
4040
self,
4141
*,
4242
question: str,
43-
context: Dict[str, Any],
43+
metadata: Dict[str, Any],
4444
results: List[Dict[str, Any]],
45-
examples: List[FewShotExample] = None,
45+
examples: Optional[List[FewShotExample]] = None,
4646
) -> None:
4747
"""
4848
Constructs a new QueryExplanationPromptFormat instance.
@@ -55,7 +55,7 @@ def __init__(
5555
"""
5656
super().__init__(examples)
5757
self.question = question
58-
self.query = next((context.get(key) for key in ("iql", "sql", "query") if context.get(key)), question)
58+
self.query = next((metadata.get(key) for key in ("iql", "sql", "query") if metadata.get(key)), question)
5959
self.number_of_results = len(results)
6060

6161

src/dbally/prompt/template.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import copy
22
import re
3-
from typing import Callable, Dict, Generic, List, TypeVar
3+
from typing import Callable, Dict, Generic, List, Optional, TypeVar
44

55
from typing_extensions import Self
66

@@ -55,7 +55,7 @@ class PromptFormat:
5555
Generic format for prompts allowing to inject few shot examples into the conversation.
5656
"""
5757

58-
def __init__(self, examples: List[FewShotExample] = None) -> None:
58+
def __init__(self, examples: Optional[List[FewShotExample]] = None) -> None:
5959
"""
6060
Constructs a new PromptFormat instance.
6161

0 commit comments

Comments
 (0)