mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(Basic LLM Chain Node): Use JSON parsing for Claude 3.7 with thinking enabled (#15381)
This commit is contained in:
@@ -38,6 +38,18 @@ export function isModelWithResponseFormat(
|
||||
);
|
||||
}
|
||||
|
||||
export function isModelInThinkingMode(
|
||||
llm: BaseLanguageModel,
|
||||
): llm is BaseLanguageModel & { lc_kwargs: { invocationKwargs: { thinking: { type: string } } } } {
|
||||
return (
|
||||
'lc_kwargs' in llm &&
|
||||
'invocationKwargs' in llm.lc_kwargs &&
|
||||
typeof llm.lc_kwargs.invocationKwargs === 'object' &&
|
||||
'thinking' in llm.lc_kwargs.invocationKwargs &&
|
||||
llm.lc_kwargs.invocationKwargs.thinking.type === 'enabled'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard to check if the LLM has a format property(Ollama)
|
||||
*/
|
||||
@@ -61,6 +73,10 @@ export function getOutputParserForLLM(
|
||||
return new NaiveJsonOutputParser();
|
||||
}
|
||||
|
||||
if (isModelInThinkingMode(llm)) {
|
||||
return new NaiveJsonOutputParser();
|
||||
}
|
||||
|
||||
return new StringOutputParser();
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,20 @@ describe('chainExecutor', () => {
|
||||
const parser = chainExecutor.getOutputParserForLLM(regularModel);
|
||||
expect(parser).toBeInstanceOf(StringOutputParser);
|
||||
});
|
||||
|
||||
it('should return NaiveJsonOutputParser for Anthropic models in thinking mode', () => {
|
||||
const model = {
|
||||
lc_kwargs: {
|
||||
invocationKwargs: {
|
||||
thinking: {
|
||||
type: 'enabled',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const parser = chainExecutor.getOutputParserForLLM(model as unknown as BaseChatModel);
|
||||
expect(parser).toBeInstanceOf(NaiveJsonOutputParser);
|
||||
});
|
||||
});
|
||||
|
||||
describe('NaiveJsonOutputParser', () => {
|
||||
|
||||
Reference in New Issue
Block a user