refactor: Implement LLM tracing callback to improve parsing of tokens usage stats (#9311)

Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
oleg
2024-05-12 21:12:07 +02:00
committed by GitHub
parent 244520547b
commit 359ade45bc
19 changed files with 282 additions and 111 deletions

View File

@@ -9,9 +9,9 @@ import {
import type { ChatOllamaInput } from '@langchain/community/chat_models/ollama';
import { ChatOllama } from '@langchain/community/chat_models/ollama';
import { logWrapper } from '../../../utils/logWrapper';
import { getConnectionHintNoticeField } from '../../../utils/sharedFields';
import { ollamaModel, ollamaOptions, ollamaDescription } from '../LMOllama/description';
import { N8nLlmTracing } from '../N8nLlmTracing';
export class LmChatOllama implements INodeType {
description: INodeTypeDescription = {
@@ -62,10 +62,11 @@ export class LmChatOllama implements INodeType {
baseUrl: credentials.baseUrl as string,
model: modelName,
format: options.format === 'default' ? undefined : options.format,
callbacks: [new N8nLlmTracing(this)],
});
return {
response: logWrapper(model, this),
response: model,
};
}
}