BaseStructuredView#
Tip
- To understand the general idea better, visit Concept: Structured Views
- To learn how to support custom data sources, visit How-to: create your custom view page
dbally.views.structured.BaseStructuredView
#
Bases: BaseView
Base class for all structured Views. All classes implementing this interface has to be able to list all available filters, apply them and execute queries.
list_few_shots
#
list_few_shots() -> List[FewShotExample]
List all examples to be injected into few-shot prompt.
RETURNS | DESCRIPTION |
---|---|
List[FewShotExample]
|
List of few-shot examples |
get_iql_generator
#
get_iql_generator() -> IQLGenerator
Returns the IQL generator for the view.
RETURNS | DESCRIPTION |
---|---|
IQLGenerator
|
IQL generator for the view. |
ask
async
#
ask(query: str, llm: LLM, event_tracker: Optional[EventTracker] = None, n_retries: int = 3, dry_run: bool = False, llm_options: Optional[LLMOptions] = None) -> ViewExecutionResult
Executes the query and returns the result. It generates the IQL query from the natural language query and applies the filters to the view. It retries the process in case of errors.
PARAMETER | DESCRIPTION |
---|---|
query |
The natural language query to execute.
TYPE:
|
llm |
The LLM used to execute the query.
TYPE:
|
event_tracker |
The event tracker used to audit the query execution.
TYPE:
|
n_retries |
The number of retries to execute the query in case of errors.
TYPE:
|
dry_run |
If True, the query will not be used to fetch data from the datasource.
TYPE:
|
llm_options |
Options to use for the LLM.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ViewExecutionResult
|
The result of the query. |
RAISES | DESCRIPTION |
---|---|
ViewExecutionError
|
When an error occurs while executing the view. |
Source code in src/dbally/views/structured.py
list_filters
abstractmethod
#
list_filters() -> List[ExposedFunction]
Lists all available filters for the View.
RETURNS | DESCRIPTION |
---|---|
List[ExposedFunction]
|
Filters defined inside the View. |
list_aggregations
abstractmethod
#
list_aggregations() -> List[ExposedFunction]
Lists all available aggregations for the View.
RETURNS | DESCRIPTION |
---|---|
List[ExposedFunction]
|
Aggregations defined inside the View. |
apply_filters
abstractmethod
async
#
Applies the chosen filters to the view.
PARAMETER | DESCRIPTION |
---|---|
filters |
IQLQuery object representing the filters to apply.
TYPE:
|
apply_aggregation
abstractmethod
async
#
Applies the chosen aggregation to the view.
PARAMETER | DESCRIPTION |
---|---|
aggregation |
IQLQuery object representing the aggregation to apply.
TYPE:
|
execute
abstractmethod
#
execute(dry_run: bool = False) -> ViewExecutionResult
Executes the query and returns the result.
PARAMETER | DESCRIPTION |
---|---|
dry_run |
if True, should only generate the query without executing it.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ViewExecutionResult
|
The view execution result. |
Source code in src/dbally/views/structured.py
list_similarity_indexes
#
Lists all the similarity indexes used by the view.
RETURNS | DESCRIPTION |
---|---|
Dict[AbstractSimilarityIndex, List[IndexLocation]]
|
Mapping of similarity indexes to their locations in the (view_name, filter_name, argument_name) format. |
Source code in src/dbally/views/structured.py
dbally.views.exposed_functions.ExposedFunction
dataclass
#
ExposedFunction(name: str, description: str, parameters: List[MethodParamWithTyping])
Represents a function exposed to the AI model.
dbally.views.exposed_functions.MethodParamWithTyping
dataclass
#
MethodParamWithTyping(name: str, type: Union[type, _GenericAlias])
dbally.views.methods_base.MethodsBaseView
#
Bases: BaseStructuredView
, ABC
Base class for views that use view methods to expose filters.
ask
async
#
ask(query: str, llm: LLM, event_tracker: Optional[EventTracker] = None, n_retries: int = 3, dry_run: bool = False, llm_options: Optional[LLMOptions] = None) -> ViewExecutionResult
Executes the query and returns the result. It generates the IQL query from the natural language query and applies the filters to the view. It retries the process in case of errors.
PARAMETER | DESCRIPTION |
---|---|
query |
The natural language query to execute.
TYPE:
|
llm |
The LLM used to execute the query.
TYPE:
|
event_tracker |
The event tracker used to audit the query execution.
TYPE:
|
n_retries |
The number of retries to execute the query in case of errors.
TYPE:
|
dry_run |
If True, the query will not be used to fetch data from the datasource.
TYPE:
|
llm_options |
Options to use for the LLM.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ViewExecutionResult
|
The result of the query. |
RAISES | DESCRIPTION |
---|---|
ViewExecutionError
|
When an error occurs while executing the view. |
Source code in src/dbally/views/structured.py
list_similarity_indexes
#
Lists all the similarity indexes used by the view.
RETURNS | DESCRIPTION |
---|---|
Dict[AbstractSimilarityIndex, List[IndexLocation]]
|
Mapping of similarity indexes to their locations in the (view_name, filter_name, argument_name) format. |
Source code in src/dbally/views/structured.py
list_few_shots
#
list_few_shots() -> List[FewShotExample]
List all examples to be injected into few-shot prompt.
RETURNS | DESCRIPTION |
---|---|
List[FewShotExample]
|
List of few-shot examples |
get_iql_generator
#
get_iql_generator() -> IQLGenerator
Returns the IQL generator for the view.
RETURNS | DESCRIPTION |
---|---|
IQLGenerator
|
IQL generator for the view. |
apply_filters
abstractmethod
async
#
Applies the chosen filters to the view.
PARAMETER | DESCRIPTION |
---|---|
filters |
IQLQuery object representing the filters to apply.
TYPE:
|
apply_aggregation
abstractmethod
async
#
Applies the chosen aggregation to the view.
PARAMETER | DESCRIPTION |
---|---|
aggregation |
IQLQuery object representing the aggregation to apply.
TYPE:
|
execute
abstractmethod
#
execute(dry_run: bool = False) -> ViewExecutionResult
Executes the query and returns the result.
PARAMETER | DESCRIPTION |
---|---|
dry_run |
if True, should only generate the query without executing it.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ViewExecutionResult
|
The view execution result. |
Source code in src/dbally/views/structured.py
list_methods_by_decorator
classmethod
#
list_methods_by_decorator(decorator: Callable) -> List[ExposedFunction]
Lists all methods decorated with the given decorator.
PARAMETER | DESCRIPTION |
---|---|
decorator |
The decorator to filter the methods
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[ExposedFunction]
|
List of exposed methods |
Source code in src/dbally/views/methods_base.py
list_filters
#
list_filters() -> List[ExposedFunction]
List filters in the given view
RETURNS | DESCRIPTION |
---|---|
List[ExposedFunction]
|
Filters defined inside the View and decorated with |
Source code in src/dbally/views/methods_base.py
list_aggregations
#
list_aggregations() -> List[ExposedFunction]
List aggregations in the given view
RETURNS | DESCRIPTION |
---|---|
List[ExposedFunction]
|
Aggregations defined inside the View and decorated with |
Source code in src/dbally/views/methods_base.py
call_filter_method
async
#
call_filter_method(func: FunctionCall) -> Any
Converts a IQL FunctonCall filter to a method call. If the method is a coroutine, it will be awaited.
PARAMETER | DESCRIPTION |
---|---|
func |
IQL FunctionCall node
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
The result of the method call |
Source code in src/dbally/views/methods_base.py
call_aggregation_method
async
#
call_aggregation_method(func: FunctionCall) -> Any
Converts a IQL FunctonCall aggregation to a method call. If the method is a coroutine, it will be awaited.
PARAMETER | DESCRIPTION |
---|---|
func |
IQL FunctionCall node
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
The result of the method call |