mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat: Add model selector node (#16371)
This commit is contained in:
@@ -41,6 +41,8 @@ export class N8nLlmTracing extends BaseCallbackHandler {
|
||||
|
||||
completionTokensEstimate = 0;
|
||||
|
||||
#parentRunIndex?: number;
|
||||
|
||||
/**
|
||||
* A map to associate LLM run IDs to run details.
|
||||
* Key: Unique identifier for each LLM run (run ID)
|
||||
@@ -141,9 +143,16 @@ export class N8nLlmTracing extends BaseCallbackHandler {
|
||||
return message;
|
||||
});
|
||||
|
||||
this.executionFunctions.addOutputData(this.connectionType, runDetails.index, [
|
||||
[{ json: { ...response } }],
|
||||
]);
|
||||
const sourceNodeRunIndex =
|
||||
this.#parentRunIndex !== undefined ? this.#parentRunIndex + runDetails.index : undefined;
|
||||
|
||||
this.executionFunctions.addOutputData(
|
||||
this.connectionType,
|
||||
runDetails.index,
|
||||
[[{ json: { ...response } }]],
|
||||
undefined,
|
||||
sourceNodeRunIndex,
|
||||
);
|
||||
|
||||
logAiEvent(this.executionFunctions, 'ai-llm-generated-output', {
|
||||
messages: parsedMessages,
|
||||
@@ -154,19 +163,27 @@ export class N8nLlmTracing extends BaseCallbackHandler {
|
||||
|
||||
async handleLLMStart(llm: Serialized, prompts: string[], runId: string) {
|
||||
const estimatedTokens = await this.estimateTokensFromStringList(prompts);
|
||||
const sourceNodeRunIndex =
|
||||
this.#parentRunIndex !== undefined
|
||||
? this.#parentRunIndex + this.executionFunctions.getNextRunIndex()
|
||||
: undefined;
|
||||
|
||||
const options = llm.type === 'constructor' ? llm.kwargs : llm;
|
||||
const { index } = this.executionFunctions.addInputData(this.connectionType, [
|
||||
const { index } = this.executionFunctions.addInputData(
|
||||
this.connectionType,
|
||||
[
|
||||
{
|
||||
json: {
|
||||
messages: prompts,
|
||||
estimatedTokens,
|
||||
options,
|
||||
[
|
||||
{
|
||||
json: {
|
||||
messages: prompts,
|
||||
estimatedTokens,
|
||||
options,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
]);
|
||||
sourceNodeRunIndex,
|
||||
);
|
||||
|
||||
// Save the run details for later use when processing `handleLLMEnd` event
|
||||
this.runsMap[runId] = {
|
||||
@@ -218,4 +235,9 @@ export class N8nLlmTracing extends BaseCallbackHandler {
|
||||
parentRunId,
|
||||
});
|
||||
}
|
||||
|
||||
// Used to associate subsequent runs with the correct parent run in subnodes of subnodes
|
||||
setParentRunIndex(runIndex: number) {
|
||||
this.#parentRunIndex = runIndex;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user