Add concrete Langfuse tracer and prompt gateway

This commit is contained in:
2026-08-12 20:55:51 +02:00
parent 299375bcd3
commit cf3c12774f
4 changed files with 130 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import { Langfuse } from 'langfuse';
import type { PromptFetcher, RawPrompt } from './PromptGateway';
export class LangfusePromptGateway implements PromptFetcher {
private readonly client: Langfuse;
constructor(opts: { publicKey: string; secretKey: string; baseUrl: string }) {
this.client = new Langfuse({
publicKey: opts.publicKey,
secretKey: opts.secretKey,
baseUrl: opts.baseUrl,
});
}
async fetch(promptName: string): Promise<RawPrompt> {
const prompt = await this.client.getPrompt(promptName, undefined, { type: 'chat', cacheTtlSeconds: 0 });
return {
name: prompt.name,
version: prompt.version,
config: (prompt.config ?? {}) as Record<string, unknown>,
compile: (variables) =>
prompt.compile(variables) as { role: 'system' | 'user' | 'assistant'; content: string }[],
};
}
}