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:
23
test/core/langfuse/LangfusePromptGateway.test.ts
Normal file
23
test/core/langfuse/LangfusePromptGateway.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
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 });
|
||||
|
||||
vi.mock('langfuse', () => ({
|
||||
Langfuse: vi.fn().mockImplementation(() => ({ getPrompt })),
|
||||
}));
|
||||
|
||||
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 () => {
|
||||
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(raw.name).toBe('greet');
|
||||
expect(raw.version).toBe(2);
|
||||
expect(raw.config).toEqual({ model: 'llama3' });
|
||||
expect(raw.compile({ who: 'alice' })).toEqual([{ role: 'user', content: 'hi' }]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user