mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-10 23:31:08 +00:00
29 lines
916 B
TypeScript
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;
|
|
}[],
|
|
};
|
|
}
|
|
}
|