diff --git a/front_end/panels/freestyler/FreestylerAgent.test.ts b/front_end/panels/freestyler/FreestylerAgent.test.ts index 0987944da8d..49ea966cfcb 100644 --- a/front_end/panels/freestyler/FreestylerAgent.test.ts +++ b/front_end/panels/freestyler/FreestylerAgent.test.ts @@ -119,6 +119,17 @@ c`; }); }); + it('parses an action with backticks in the code', async () => { + const payload = `const data = { + someKey: "value", +}`; + assert.deepStrictEqual(FreestylerAgent.parseResponse(`ACTION\n\`\`\`\n${payload}\n\`\`\`\nSTOP`), { + action: payload, + thought: undefined, + answer: undefined, + }); + }); + it('parses a thought and an action', async () => { const actionPayload = `const data = { someKey: "value", diff --git a/front_end/panels/freestyler/FreestylerAgent.ts b/front_end/panels/freestyler/FreestylerAgent.ts index 6e6de083ade..d1568f452c6 100644 --- a/front_end/panels/freestyler/FreestylerAgent.ts +++ b/front_end/panels/freestyler/FreestylerAgent.ts @@ -134,11 +134,12 @@ export class FreestylerAgent { const actionLines = []; let j = i + 1; while (j < lines.length && lines[j].trim() !== 'STOP') { - // TODO: handle markdown backticks. actionLines.push(lines[j]); j++; } - action = actionLines.join('\n').trim(); + // TODO: perhaps trying to parse with a Markdown parser would + // yield more reliable results. + action = actionLines.join('\n').replaceAll('```', '').trim(); i = j + 1; } else if (trimmed.startsWith('ANSWER:') && !answer) { const answerLines = [