Skip to content

Commit a85ba33

Browse files
committed
Refactor cleanQueryResponse to simplify response cleaning logic
1 parent daae72b commit a85ba33

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

backend/src/entities/visualizations/panel-position/use-cases/generate-panel-position-with-ai.use.case.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,11 @@ IMPORTANT:
345345
}
346346

347347
private cleanQueryResponse(aiResponse: string): string {
348-
let cleaned = aiResponse.trim();
349-
if (cleaned.startsWith('```sql')) {
350-
cleaned = cleaned.slice(6);
351-
} else if (cleaned.startsWith('```')) {
352-
cleaned = cleaned.slice(3);
353-
}
354-
if (cleaned.endsWith('```')) {
355-
cleaned = cleaned.slice(0, -3);
356-
}
357-
return cleaned.trim();
348+
return aiResponse
349+
.trim()
350+
.replace(/^```[a-zA-Z]*\n?/, '')
351+
.replace(/```\s*$/, '')
352+
.trim();
358353
}
359354

360355
private normalizeWhitespace(query: string): string {

0 commit comments

Comments
 (0)