Skip to content

Commit

Permalink
[Freestyler] Parse backticks out of the code
Browse files Browse the repository at this point in the history
Bug: 340805507
Change-Id: I24f92dce2b860a31eb2520cf18352ff4474e8dbf
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5633337
Commit-Queue: Alex Rudenko <[email protected]>
Reviewed-by: Ergün Erdoğmuş <[email protected]>
  • Loading branch information
OrKoN authored and Devtools-frontend LUCI CQ committed Jun 14, 2024
1 parent f377833 commit 4e2ef92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions front_end/panels/freestyler/FreestylerAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions front_end/panels/freestyler/FreestylerAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit 4e2ef92

Please sign in to comment.