mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-11 07:41:08 +00:00
Add core LlmPipeline base class
This commit is contained in:
32
src/core/llm/LlmPipeline.ts
Normal file
32
src/core/llm/LlmPipeline.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { Logger } from '../logging/logger';
|
||||
import type { LlmTool } from './LlmTool';
|
||||
import type { RunContext } from './RunContext';
|
||||
import type { Tracer } from './Tracer';
|
||||
|
||||
export abstract class LlmPipeline<TInput, TOutput> {
|
||||
constructor(
|
||||
protected readonly tracer: Tracer,
|
||||
protected readonly logger: Logger
|
||||
) {}
|
||||
|
||||
protected abstract readonly name: string;
|
||||
protected abstract runInternal(input: TInput, ctx: RunContext): Promise<TOutput>;
|
||||
|
||||
async runAsync(input: TInput): Promise<TOutput> {
|
||||
const trace = this.tracer.startTrace(this.name);
|
||||
const ctx: RunContext = { trace, logger: this.logger };
|
||||
try {
|
||||
return await this.runInternal(input, ctx);
|
||||
} finally {
|
||||
await this.tracer.flush();
|
||||
}
|
||||
}
|
||||
|
||||
protected runTool<TToolInput, TToolOutput>(
|
||||
tool: LlmTool<TToolInput, TToolOutput>,
|
||||
input: TToolInput,
|
||||
ctx: RunContext
|
||||
): Promise<TToolOutput> {
|
||||
return tool.runAsync(input, ctx);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user