Skip to content

Commit 799da53

Browse files
committed
fix(core): add test for log streaming LLM calls to database
1 parent 791ad8b commit 799da53

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

packages/core/src/__tests__/runtime-streaming.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,4 +403,73 @@ describe('useModel Streaming', () => {
403403
expect(result).toBe('XYZ');
404404
});
405405
});
406+
407+
describe('database logging', () => {
408+
it('should log streaming model calls to database', async () => {
409+
const mockChunks = ['Hello', ' ', 'World'];
410+
const mockAdapter = createMockAdapter();
411+
412+
const streamingRuntime = new AgentRuntime({
413+
agentId: stringToUuid('test-logging-agent'),
414+
character: mockCharacter,
415+
adapter: mockAdapter,
416+
});
417+
418+
streamingRuntime.registerModel(
419+
ModelType.TEXT_LARGE,
420+
async (_rt, params) => {
421+
if ((params as any).stream) {
422+
return createMockTextStreamResult(mockChunks);
423+
}
424+
return mockChunks.join('');
425+
},
426+
'test-provider'
427+
);
428+
429+
await streamingRuntime.useModel(ModelType.TEXT_LARGE, {
430+
prompt: 'Test prompt',
431+
onStreamChunk: () => {},
432+
});
433+
434+
// Verify adapter.log was called
435+
const logCalls = (mockAdapter.log as any).mock.calls;
436+
expect(logCalls.length).toBeGreaterThan(0);
437+
438+
// Verify the log contains correct model info
439+
const logCall = logCalls[0][0];
440+
expect(logCall.type).toBe('useModel:TEXT_LARGE');
441+
expect(logCall.body.modelKey).toBe('TEXT_LARGE');
442+
expect(logCall.body.response).toBe('Hello World');
443+
});
444+
445+
it('should log non-streaming model calls to database', async () => {
446+
const mockAdapter = createMockAdapter();
447+
448+
const nonStreamingRuntime = new AgentRuntime({
449+
agentId: stringToUuid('test-logging-agent-2'),
450+
character: mockCharacter,
451+
adapter: mockAdapter,
452+
});
453+
454+
nonStreamingRuntime.registerModel(
455+
ModelType.TEXT_LARGE,
456+
async () => 'Non-streamed response',
457+
'test-provider'
458+
);
459+
460+
await nonStreamingRuntime.useModel(ModelType.TEXT_LARGE, {
461+
prompt: 'Test prompt',
462+
});
463+
464+
// Verify adapter.log was called
465+
const logCalls = (mockAdapter.log as any).mock.calls;
466+
expect(logCalls.length).toBeGreaterThan(0);
467+
468+
// Verify the log contains correct model info
469+
const logCall = logCalls[0][0];
470+
expect(logCall.type).toBe('useModel:TEXT_LARGE');
471+
expect(logCall.body.modelKey).toBe('TEXT_LARGE');
472+
expect(logCall.body.response).toBe('Non-streamed response');
473+
});
474+
});
406475
});

0 commit comments

Comments
 (0)