char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Linting & Formatting scripts (#26819)92d1bb0c9

char/aliceai-t5-moe
2.8 KiB88 linesraw
1import { MessageRole } from '$lib/enums';
2import { describe, expect, it } from 'vitest';
3
4/**
5 * Tests for the new reasoning content handling.
6 * In the new architecture, reasoning content is stored in a dedicated
7 * `reasoningContent` field on DatabaseMessage, not embedded in content with tags.
8 * The API sends it as `reasoning_content` on ApiChatMessageData.
9 */
10
11describe('reasoning content in new structured format', () => {
12	it('reasoning is stored as separate field, not in content', () => {
13		// Simulate what the new chat store does
14		const message = {
15			content: 'The answer is 4.',
16			reasoningContent: 'Let me think: 2+2=4, basic arithmetic.'
17		};
18
19		// Content should be clean
20		expect(message.content).not.toContain('<<<');
21		expect(message.content).toBe('The answer is 4.');
22
23		// Reasoning in dedicated field
24		expect(message.reasoningContent).toBe('Let me think: 2+2=4, basic arithmetic.');
25	});
26
27	it('convertDbMessageToApiChatMessageData includes reasoning_content', () => {
28		// Simulate the conversion logic
29		const dbMessage = {
30			content: 'The answer is 4.',
31			reasoningContent: 'Let me think: 2+2=4, basic arithmetic.',
32			role: MessageRole.ASSISTANT
33		};
34		const apiMessage: Record<string, unknown> = {
35			content: dbMessage.content,
36			role: dbMessage.role
37		};
38
39		if (dbMessage.reasoningContent) {
40			apiMessage.reasoning_content = dbMessage.reasoningContent;
41		}
42
43		expect(apiMessage.content).toBe('The answer is 4.');
44		expect(apiMessage.reasoning_content).toBe('Let me think: 2+2=4, basic arithmetic.');
45		// No internal tags leak into either field
46		expect(apiMessage.content).not.toContain('<<<');
47		expect(apiMessage.reasoning_content).not.toContain('<<<');
48	});
49
50	it('API message excludes reasoning when excludeReasoningFromContext is true', () => {
51		const dbMessage = {
52			content: 'The answer is 4.',
53			reasoningContent: 'internal thinking',
54			role: MessageRole.ASSISTANT
55		};
56		const excludeReasoningFromContext = true;
57		const apiMessage: Record<string, unknown> = {
58			content: dbMessage.content,
59			role: dbMessage.role
60		};
61
62		if (!excludeReasoningFromContext && dbMessage.reasoningContent) {
63			apiMessage.reasoning_content = dbMessage.reasoningContent;
64		}
65
66		expect(apiMessage.content).toBe('The answer is 4.');
67		expect(apiMessage.reasoning_content).toBeUndefined();
68	});
69
70	it('handles messages with no reasoning', () => {
71		const dbMessage = {
72			content: 'No reasoning here.',
73			reasoningContent: undefined,
74			role: MessageRole.ASSISTANT
75		};
76		const apiMessage: Record<string, unknown> = {
77			content: dbMessage.content,
78			role: dbMessage.role
79		};
80
81		if (dbMessage.reasoningContent) {
82			apiMessage.reasoning_content = dbMessage.reasoningContent;
83		}
84
85		expect(apiMessage.content).toBe('No reasoning here.');
86		expect(apiMessage.reasoning_content).toBeUndefined();
87	});
88});