Commit a4c5216c by Archer Committed by GitHub

extract log (#7161)

parent 01d716f0
...@@ -241,12 +241,32 @@ const completions = async (props: ActionProps) => { ...@@ -241,12 +241,32 @@ const completions = async (props: ActionProps) => {
} }
try { try {
const arg = json5.parse(jsonStr);
if (!arg || typeof arg !== 'object' || Array.isArray(arg)) {
logger.warn('Content extract result is not an object', {
requestId,
model: extractModel.model,
finishReason,
answerLength: answer.length,
jsonLength: jsonStr.length,
resultType: Array.isArray(arg) ? 'array' : typeof arg
});
return {
rawResponse: answer,
inputTokens,
outputTokens,
usedUserOpenAIKey,
arg: {}
};
}
return { return {
rawResponse: answer, rawResponse: answer,
inputTokens, inputTokens,
outputTokens, outputTokens,
usedUserOpenAIKey, usedUserOpenAIKey,
arg: json5.parse(jsonStr) as Record<string, any> arg: arg as Record<string, any>
}; };
} catch (error) { } catch (error) {
logger.warn('Failed to parse extract result', { logger.warn('Failed to parse extract result', {
......
...@@ -209,6 +209,25 @@ describe('dispatchContentExtract', () => { ...@@ -209,6 +209,25 @@ describe('dispatchContentExtract', () => {
}); });
}); });
it('ignores scalar JSON responses and keeps the workflow running', async () => {
getLLMModelMock.mockReturnValue({
model: 'gpt-4o',
name: 'GPT-4o',
maxContext: 128000,
reasoning: false,
toolChoice: false
});
createLLMResponseMock.mockResolvedValue(mockLLMResponse('1'));
const result = await dispatchContentExtract(createProps());
expect(result.data).toMatchObject({
success: true,
name: ''
});
expect(result.error).toBeUndefined();
});
it('extracts multiple fields and removes fields outside the schema', async () => { it('extracts multiple fields and removes fields outside the schema', async () => {
getLLMModelMock.mockReturnValue({ getLLMModelMock.mockReturnValue({
model: 'gpt-4o', model: 'gpt-4o',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment