char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
92d1bb0c9
char/aliceai-t5-moe
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' , () => { 12it ( 'reasoning is stored as separate field, not in content' , () => { 13// Simulate what the new chat store does 14const message = { 15content :'The answer is 4.' , 16reasoningContent :'Let me think: 2+2=4, basic arithmetic.' 17}; 18 19// Content should be clean 20expect ( message . content ). not . toContain ( '<<<' ); 21expect ( message . content ). toBe ( 'The answer is 4.' ); 22 23// Reasoning in dedicated field 24expect ( message . reasoningContent ). toBe ( 'Let me think: 2+2=4, basic arithmetic.' ); 25}); 26 27it ( 'convertDbMessageToApiChatMessageData includes reasoning_content' , () => { 28// Simulate the conversion logic 29const dbMessage = { 30content :'The answer is 4.' , 31reasoningContent :'Let me think: 2+2=4, basic arithmetic.' , 32role :MessageRole . ASSISTANT 33}; 34const apiMessage :Record < string , unknown > = { 35content :dbMessage . content , 36role :dbMessage . role 37}; 38 39if ( dbMessage . reasoningContent ) { 40apiMessage . reasoning_content = dbMessage . reasoningContent ; 41} 42 43expect ( apiMessage . content ). toBe ( 'The answer is 4.' ); 44expect ( apiMessage . reasoning_content ). toBe ( 'Let me think: 2+2=4, basic arithmetic.' ); 45// No internal tags leak into either field 46expect ( apiMessage . content ). not . toContain ( '<<<' ); 47expect ( apiMessage . reasoning_content ). not . toContain ( '<<<' ); 48}); 49 50it ( 'API message excludes reasoning when excludeReasoningFromContext is true' , () => { 51const dbMessage = { 52content :'The answer is 4.' , 53reasoningContent :'internal thinking' , 54role :MessageRole . ASSISTANT 55}; 56const excludeReasoningFromContext = true ; 57const apiMessage :Record < string , unknown > = { 58content :dbMessage . content , 59role :dbMessage . role 60}; 61 62if ( ! excludeReasoningFromContext && dbMessage . reasoningContent ) { 63apiMessage . reasoning_content = dbMessage . reasoningContent ; 64} 65 66expect ( apiMessage . content ). toBe ( 'The answer is 4.' ); 67expect ( apiMessage . reasoning_content ). toBeUndefined (); 68}); 69 70it ( 'handles messages with no reasoning' , () => { 71const dbMessage = { 72content :'No reasoning here.' , 73reasoningContent :undefined , 74role :MessageRole . ASSISTANT 75}; 76const apiMessage :Record < string , unknown > = { 77content :dbMessage . content , 78role :dbMessage . role 79}; 80 81if ( dbMessage . reasoningContent ) { 82apiMessage . reasoning_content = dbMessage . reasoningContent ; 83} 84 85expect ( apiMessage . content ). toBe ( 'No reasoning here.' ); 86expect ( apiMessage . reasoning_content ). toBeUndefined (); 87}); 88});