Files
sugarr/src/core/langfuse/LangfusePromptGateway.ts
2026-08-12 22:17:56 +02:00

29 lines
916 B
TypeScript

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