BaseText2SQLView#
dbally.views.freeform.text2sql.view.BaseText2SQLView
#
Bases: BaseView
, ABC
Text2SQLFreeformView is a class designed to interact with the database using text2sql queries.
Source code in src/dbally/views/freeform/text2sql/view.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_tables
abstractmethod
#
get_tables() -> List[TableConfig]
Get the tables used by the view.
RETURNS | DESCRIPTION |
---|---|
List[TableConfig]
|
The list of tables used by 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 SQL query from the natural language query and executes it against the database. 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 |
---|---|
Text2SQLError
|
If the text2sql query generation fails after n_retries. |
Source code in src/dbally/views/freeform/text2sql/view.py
list_similarity_indexes
#
List all similarity indexes used by the view.
RETURNS | DESCRIPTION |
---|---|
Dict[AbstractSimilarityIndex, List[IndexLocation]]
|
Mapping of similarity indexes to their locations in the (view_name, table_name, column_name) format. |
Source code in src/dbally/views/freeform/text2sql/view.py
dbally.views.freeform.text2sql.config.TableConfig
dataclass
#
TableConfig(name: str, columns: List[ColumnConfig], description: Optional[str] = None)
Configuration of a table used in the Text2SQL view.
ddl
property
#
Returns the DDL for the table which can be provided to the LLM as a context.
RETURNS | DESCRIPTION |
---|---|
str
|
The DDL for the table. |
dbally.views.freeform.text2sql.config.ColumnConfig
dataclass
#
ColumnConfig(name: str, data_type: str, description: Optional[str] = None, similarity_index: Optional[SimilarityIndex] = None)
Configuration of a column used in the Text2SQL view.
similarity_index
class-attribute
instance-attribute
#
similarity_index: Optional[SimilarityIndex] = None