Skip to content

Commit a4c5216

Browse files
authored
extract log (#7161)
1 parent 01d716f commit a4c5216

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

packages/service/core/workflow/dispatch/ai/extract.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,32 @@ const completions = async (props: ActionProps) => {
241241
}
242242

243243
try {
244+
const arg = json5.parse(jsonStr);
245+
if (!arg || typeof arg !== 'object' || Array.isArray(arg)) {
246+
logger.warn('Content extract result is not an object', {
247+
requestId,
248+
model: extractModel.model,
249+
finishReason,
250+
answerLength: answer.length,
251+
jsonLength: jsonStr.length,
252+
resultType: Array.isArray(arg) ? 'array' : typeof arg
253+
});
254+
255+
return {
256+
rawResponse: answer,
257+
inputTokens,
258+
outputTokens,
259+
usedUserOpenAIKey,
260+
arg: {}
261+
};
262+
}
263+
244264
return {
245265
rawResponse: answer,
246266
inputTokens,
247267
outputTokens,
248268
usedUserOpenAIKey,
249-
arg: json5.parse(jsonStr) as Record<string, any>
269+
arg: arg as Record<string, any>
250270
};
251271
} catch (error) {
252272
logger.warn('Failed to parse extract result', {

packages/service/test/core/workflow/dispatch/ai/extract.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,25 @@ describe('dispatchContentExtract', () => {
209209
});
210210
});
211211

212+
it('ignores scalar JSON responses and keeps the workflow running', async () => {
213+
getLLMModelMock.mockReturnValue({
214+
model: 'gpt-4o',
215+
name: 'GPT-4o',
216+
maxContext: 128000,
217+
reasoning: false,
218+
toolChoice: false
219+
});
220+
createLLMResponseMock.mockResolvedValue(mockLLMResponse('1'));
221+
222+
const result = await dispatchContentExtract(createProps());
223+
224+
expect(result.data).toMatchObject({
225+
success: true,
226+
name: ''
227+
});
228+
expect(result.error).toBeUndefined();
229+
});
230+
212231
it('extracts multiple fields and removes fields outside the schema', async () => {
213232
getLLMModelMock.mockReturnValue({
214233
model: 'gpt-4o',

0 commit comments

Comments
 (0)