|
5 | 5 | from dbally.audit.event_tracker import EventTracker
|
6 | 6 | from dbally.collection.results import ViewExecutionResult
|
7 | 7 | from dbally.iql import IQLQuery
|
| 8 | +from dbally.iql._exceptions import IQLError |
8 | 9 | from dbally.iql_generator.iql_generator import IQLGenerator
|
| 10 | +from dbally.iql_generator.prompt import UnsupportedQueryError |
9 | 11 | from dbally.llms.base import LLM
|
10 | 12 | from dbally.llms.clients.base import LLMOptions
|
| 13 | +from dbally.views.exceptions import IQLGenerationError |
11 | 14 | from dbally.views.exposed_functions import ExposedFunction
|
12 | 15 |
|
13 | 16 | from ..similarity import AbstractSimilarityIndex
|
@@ -57,21 +60,36 @@ async def ask(
|
57 | 60 | The result of the query.
|
58 | 61 |
|
59 | 62 | Raises:
|
60 |
| - IQLError: If the generated IQL query is not valid. |
| 63 | + LLMError: If LLM text generation API fails. |
| 64 | + IQLGenerationError: If the IQL generation fails. |
61 | 65 | """
|
62 | 66 | iql_generator = self.get_iql_generator(llm)
|
63 | 67 |
|
64 | 68 | filters = self.list_filters()
|
65 | 69 | examples = self.list_few_shots()
|
66 | 70 |
|
67 |
| - iql = await iql_generator.generate_iql( |
68 |
| - question=query, |
69 |
| - filters=filters, |
70 |
| - examples=examples, |
71 |
| - event_tracker=event_tracker, |
72 |
| - llm_options=llm_options, |
73 |
| - n_retries=n_retries, |
74 |
| - ) |
| 71 | + try: |
| 72 | + iql = await iql_generator.generate_iql( |
| 73 | + question=query, |
| 74 | + filters=filters, |
| 75 | + examples=examples, |
| 76 | + event_tracker=event_tracker, |
| 77 | + llm_options=llm_options, |
| 78 | + n_retries=n_retries, |
| 79 | + ) |
| 80 | + except UnsupportedQueryError as exc: |
| 81 | + raise IQLGenerationError( |
| 82 | + view_name=self.__class__.__name__, |
| 83 | + filters=None, |
| 84 | + aggregation=None, |
| 85 | + ) from exc |
| 86 | + except IQLError as exc: |
| 87 | + raise IQLGenerationError( |
| 88 | + view_name=self.__class__.__name__, |
| 89 | + filters=exc.source, |
| 90 | + aggregation=None, |
| 91 | + ) from exc |
| 92 | + |
75 | 93 | await self.apply_filters(iql)
|
76 | 94 |
|
77 | 95 | result = self.execute(dry_run=dry_run)
|
|
0 commit comments