|
13 | 13 | from datapilot.core.platforms.dbt.exceptions import AltimateCLIArgumentError |
14 | 14 | from datapilot.core.platforms.dbt.factory import DBTFactory |
15 | 15 | 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 |
16 | 18 | from datapilot.core.platforms.dbt.schemas.manifest import Catalog |
17 | 19 | from datapilot.core.platforms.dbt.schemas.manifest import Manifest |
18 | 20 | from datapilot.core.platforms.dbt.utils import get_models |
@@ -108,7 +110,6 @@ def run(self): |
108 | 110 | reports = { |
109 | 111 | MODEL: {}, |
110 | 112 | PROJECT: [], |
111 | | - LLM: [], |
112 | 113 | } |
113 | 114 | for insight_class in INSIGHTS: |
114 | 115 | # TODO: Skip insight based on config |
@@ -176,7 +177,38 @@ def run(self): |
176 | 177 |
|
177 | 178 | if self.token and self.instance_name and self.backend_url: |
178 | 179 | 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 |
181 | 213 |
|
182 | 214 | return reports |
0 commit comments