upgrade langfuse

This commit is contained in:
2026-08-12 22:17:56 +02:00
parent 2ffba19392
commit a5120d5153
8 changed files with 789 additions and 57 deletions

View File

@@ -1,20 +1,22 @@
import { describe, expect, it, vi } from 'vitest';
const compile = vi.fn().mockReturnValue([{ role: 'user', content: 'hi' }]);
const getPrompt = vi.fn().mockResolvedValue({ name: 'greet', version: 2, config: { model: 'llama3' }, compile });
const promptGet = vi
.fn()
.mockResolvedValue({ name: 'greet', version: 2, config: { model: 'llama3' }, compile });
vi.mock('langfuse', () => ({
Langfuse: vi.fn().mockImplementation(() => ({ getPrompt })),
vi.mock('@langfuse/client', () => ({
LangfuseClient: vi.fn().mockImplementation(() => ({ prompt: { get: promptGet } })),
}));
import { LangfusePromptGateway } from '../../../src/core/langfuse/LangfusePromptGateway';
describe('LangfusePromptGateway', () => {
it('fetches a chat prompt from Langfuse bypassing the SDK cache, and adapts it to RawPrompt', async () => {
it('fetches a chat prompt from Langfuse and adapts it to RawPrompt', async () => {
const gateway = new LangfusePromptGateway({ publicKey: 'pk', secretKey: 'sk', baseUrl: 'http://lf' });
const raw = await gateway.fetch('greet');
expect(getPrompt).toHaveBeenCalledWith('greet', undefined, { type: 'chat', cacheTtlSeconds: 0 });
expect(promptGet).toHaveBeenCalledWith('greet', { type: 'chat' });
expect(raw.name).toBe('greet');
expect(raw.version).toBe(2);
expect(raw.config).toEqual({ model: 'llama3' });