fix(triage): tune prompt to return json text and harden eval json extraction

This commit is contained in:
cocosheng-g
2026-02-03 19:55:00 -05:00
parent 5c2f477adf
commit d9a0e9b9c5
4 changed files with 32 additions and 14 deletions
+17 -7
View File
@@ -103,14 +103,24 @@ const assertHasIssueLabel = (issueNumber: number, expectedLabel: string) => {
// The model response JSON is in the 'response' field
const responseText = output.response;
const firstBrace = responseText.indexOf('[');
const lastBrace = responseText.lastIndexOf(']');
if (firstBrace === -1 || lastBrace === -1 || lastBrace < firstBrace) {
throw new Error(
`Could not find a JSON array in the response: "${escapeHtml(responseText)}"`,
);
let jsonString: string;
const match = responseText.match(/```json\s*([\s\S]*?)\s*```/);
if (match?.[1]) {
jsonString = match[1];
} else {
const firstBracket = responseText.indexOf('[');
const lastBracket = responseText.lastIndexOf(']');
if (
firstBracket === -1 ||
lastBracket === -1 ||
lastBracket < firstBracket
) {
throw new Error(
`Could not find a JSON array in the response: "${escapeHtml(responseText)}"`,
);
}
jsonString = responseText.substring(firstBracket, lastBracket + 1);
}
const jsonString = responseText.substring(firstBrace, lastBrace + 1);
let data: { issue_number: number; labels_to_add: string[] }[];
try {
+13 -7
View File
@@ -103,14 +103,20 @@ const assertHasLabel = (expectedLabel: string) => {
// The model response JSON is in the 'response' field
const responseText = output.response;
const firstBrace = responseText.indexOf('{');
const lastBrace = responseText.lastIndexOf('}');
if (firstBrace === -1 || lastBrace === -1 || lastBrace < firstBrace) {
throw new Error(
`Could not find a JSON object in the response: "${escapeHtml(responseText)}"`,
);
let jsonString: string;
const match = responseText.match(/```json\s*([\s\S]*?)\s*```/);
if (match?.[1]) {
jsonString = match[1];
} else {
const firstBrace = responseText.indexOf('{');
const lastBrace = responseText.lastIndexOf('}');
if (firstBrace === -1 || lastBrace === -1 || lastBrace < firstBrace) {
throw new Error(
`Could not find a JSON object in the response: "${escapeHtml(responseText)}"`,
);
}
jsonString = responseText.substring(firstBrace, lastBrace + 1);
}
const jsonString = responseText.substring(firstBrace, lastBrace + 1);
let data: { labels_to_set?: string[] };
try {