mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-11 15:51:09 +00:00
Add concrete Langfuse tracer and prompt gateway
This commit is contained in:
25
src/core/langfuse/LangfusePromptGateway.ts
Normal file
25
src/core/langfuse/LangfusePromptGateway.ts
Normal 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 }[],
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user