Skip to content

Commit bf82ad6

Browse files
committed
add llm insights to datapilot
1 parent ae7423c commit bf82ad6

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

src/datapilot/core/platforms/dbt/cli/cli.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from datapilot.clients.altimate.utils import validate_credentials
99
from datapilot.clients.altimate.utils import validate_permissions
1010
from datapilot.config.config import load_config
11-
from datapilot.core.platforms.dbt.constants import LLM
1211
from datapilot.core.platforms.dbt.constants import MODEL
1312
from datapilot.core.platforms.dbt.constants import PROJECT
1413
from datapilot.core.platforms.dbt.executor import DBTInsightGenerator
@@ -82,7 +81,6 @@ def project_health(
8281

8382
package_insights = reports[PROJECT]
8483
model_insights = reports[MODEL]
85-
llm_insights = reports[LLM]
8684
model_report = generate_model_insights_table(model_insights)
8785
if len(model_report) > 0:
8886
click.echo("--" * 50)
@@ -101,18 +99,6 @@ def project_health(
10199
click.echo("--" * 50)
102100
click.echo(tabulate_data(project_report, headers="keys"))
103101

104-
if len(llm_insights):
105-
click.echo("--" * 50)
106-
click.echo("Project Governance LLM Insights")
107-
click.echo("--" * 50)
108-
for check in llm_insights:
109-
click.echo(f"Check: {check['name']}")
110-
for answer in check["answer"]:
111-
click.echo(f"Path: {answer['path']}")
112-
click.echo(f"Reason to Flag: {answer['reason_to_flag']}")
113-
click.echo(f"Recommendation: {answer['recommendation']}")
114-
click.echo("\n")
115-
116102

117103
@dbt.command("onboard")
118104
@click.option("--token", prompt="API Token", help="Your API token for authentication.")

src/datapilot/core/platforms/dbt/executor.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from datapilot.core.platforms.dbt.exceptions import AltimateCLIArgumentError
1414
from datapilot.core.platforms.dbt.factory import DBTFactory
1515
from datapilot.core.platforms.dbt.insights import INSIGHTS
16+
from datapilot.core.platforms.dbt.insights.schema import DBTInsightResult
17+
from datapilot.core.platforms.dbt.insights.schema import DBTModelInsightResponse
1618
from datapilot.core.platforms.dbt.schemas.manifest import Catalog
1719
from datapilot.core.platforms.dbt.schemas.manifest import Manifest
1820
from datapilot.core.platforms.dbt.utils import get_models
@@ -108,7 +110,6 @@ def run(self):
108110
reports = {
109111
MODEL: {},
110112
PROJECT: [],
111-
LLM: [],
112113
}
113114
for insight_class in INSIGHTS:
114115
# TODO: Skip insight based on config
@@ -176,7 +177,38 @@ def run(self):
176177

177178
if self.token and self.instance_name and self.backend_url:
178179
llm_check_results = self.run_llm_checks()
179-
if llm_check_results:
180-
reports[LLM].extend(llm_check_results["results"])
180+
llm_reports = llm_check_results["results"]
181+
llm_insights = {}
182+
for report in llm_reports:
183+
for answer in report["answer"]:
184+
location = answer["unique_id"]
185+
if location not in llm_insights:
186+
llm_insights[location] = []
187+
metadata = answer.get("metadata", {})
188+
metadata["source"] = LLM
189+
metadata["llm_id"] = report["id"]
190+
metadata["catagory"] = report["type"]
191+
llm_insights[location].append(
192+
DBTModelInsightResponse(
193+
insight=DBTInsightResult(
194+
type="Custom",
195+
name=report["name"],
196+
message=answer["message"],
197+
reason_to_flag=answer["reason_to_flag"],
198+
recommendation=answer["recommendation"],
199+
metadata=metadata,
200+
),
201+
severity=answer["severity"],
202+
path=answer["path"],
203+
original_file_path=answer["original_file_path"],
204+
package_name=answer["package_name"],
205+
unique_id=answer["unique_id"],
206+
)
207+
)
208+
for key, value in llm_insights.items():
209+
if key in reports[MODEL]:
210+
reports[MODEL][key].extend(value)
211+
else:
212+
reports[MODEL][key] = value
181213

182214
return reports

0 commit comments

Comments
 (0)