Skip to content

Commit 1746a07

Browse files
ulivzycjcl868
authored andcommitted
feat(action-parser): workaround for unexpected newline in content value
1 parent eea93d9 commit 1746a07

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/action-parser/src/index.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,26 @@ describe('actionParser', () => {
9090
],
9191
});
9292
});
93+
94+
it('should remove trailing \\n in content value', () => {
95+
const result = actionParser({
96+
prediction:
97+
'Thought: To proceed with the task of accessing "doubao.com," I need to type the correct URL into the address bar. Since the address bar is already active, the next logical step is to input the URL "doubao.com" to navigate to the desired website.\nType "doubao.com" into the address bar to initiate navigation to the website.\nAction: type(content=\'doubao.com\\n\')',
98+
factor: 1000,
99+
});
100+
101+
expect(result).toEqual({
102+
parsed: [
103+
{
104+
action_inputs: {
105+
content: 'doubao.com',
106+
},
107+
action_type: 'type',
108+
reflection: '',
109+
thought:
110+
'To proceed with the task of accessing "doubao.com," I need to type the correct URL into the address bar. Since the address bar is already active, the next logical step is to input the URL "doubao.com" to navigate to the desired website.\nType "doubao.com" into the address bar to initiate navigation to the website.',
111+
},
112+
],
113+
});
114+
});
93115
});

packages/action-parser/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,16 @@ function parseAction(actionStr: string) {
152152
if (!key) continue;
153153

154154
// Join value parts back together in case there were = signs in the value
155-
const value = valueParts
155+
let value = valueParts
156156
.join('=')
157157
.trim()
158158
.replace(/^['"]|['"]$/g, ''); // Remove surrounding quotes
159159

160+
// Remove trailing \n in content value
161+
if (key.trim() === 'content' && value.endsWith('\\n')) {
162+
value = value.slice(0, -2);
163+
}
164+
160165
//@ts-ignore
161166
kwargs[key.trim()] = value;
162167
}

0 commit comments

Comments
 (0)