char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
f1357e499
char/aliceai-t5-moe
1< script lang ="ts "module > 2import { defineMeta } from '@storybook/addon-svelte-csf' ; 3import ChatMessage from '$lib/components/app/chat/ChatMessages/ChatMessage/ChatMessage.svelte' ; 4import type { ChatMessageActions } from '$lib/types' ; 5 6const { Story} = defineMeta ({ 7component :ChatMessage , 8parameters :{ 9layout :'centered' 10}, 11title :'Components/ChatScreen/ChatMessage' 12}); 13 14const chatActions :ChatMessageActions = { 15continueAssistantMessage :() => {}, 16copy :() => {}, 17delete :() => {}, 18editUserMessagePreserveResponses :() => {}, 19editWithBranching :() => {}, 20editWithReplacement :() => {}, 21forkConversation :() => {}, 22navigateToSibling :() => {}, 23regenerateWithBranching :() => {} 24}; 25 26// Mock messages for different scenarios 27const userMessage :DatabaseMessage = { 28children :[], 29content :'What is the meaning of life, the universe, and everything?' , 30convId :'conv-1' , 31id :'1' , 32parent :'' , 33role :'user' , 34thinking :'' , 35timestamp :Date . now () - 1000 * 60 * 5 , 36type :'message' 37}; 38 39const assistantMessage :DatabaseMessage = { 40children :[], 41content : 42'The answer to the ultimate question of life, the universe, and everything is **42**.\n\nThis comes from Douglas Adams\' "The Hitchhiker\'s Guide to the Galaxy," where a supercomputer named Deep Thought calculated this answer over 7.5 million years. However, the question itself was never properly formulated, which is why the answer seems meaningless without context.' , 43convId :'conv-1' , 44id :'2' , 45parent :'1' , 46role :'assistant' , 47thinking :'' , 48timestamp :Date . now () - 1000 * 60 * 3 , 49type :'message' 50}; 51 52const assistantWithReasoning :DatabaseMessage = { 53children :[], 54content :"Here's the concise answer, now that I've thought it through carefully for you." , 55convId :'conv-1' , 56id :'3' , 57parent :'1' , 58role :'assistant' , 59thinking : 60"Let's consider the user's question step by step:\\n\\n1. Identify the core problem\\n2. Evaluate relevant information\\n3. Formulate a clear answer\\n\\nFollowing this process ensures the final response stays focused and accurate." , 61timestamp :Date . now () - 1000 * 60 * 2 , 62type :'message' 63}; 64const rawOutputMessage :DatabaseMessage = { 65children :[], 66content : 67'<|channel|>analysis<|message|>User greeted me. Initiating overcomplicated analysis: Is this a trap? No, just a normal hello. Respond calmly, act like a helpful assistant, and do not start explaining quantum physics again. Confidence 0.73. Engaging socially acceptable greeting protocol...<|end|>Hello there! How can I help you today?' , 68convId :'conv-1' , 69id :'6' , 70parent :'1' , 71role :'assistant' , 72thinking :'' , 73timestamp :Date . now () - 1000 * 60 , 74type :'message' 75}; 76 77let processingMessage = $state ({ 78children :[], 79content :'' , 80convId :'conv-1' , 81id :'4' , 82parent :'1' , 83role :'assistant' , 84thinking :'' , 85timestamp :0 , // No timestamp = processing 86type :'message' 87}); 88 89let streamingMessage = $state ({ 90children :[], 91content :'' , 92convId :'conv-1' , 93id :'5' , 94parent :'1' , 95role :'assistant' , 96thinking :'' , 97timestamp :0 , // No timestamp = streaming 98type :'message' 99}); 100</ script > 101 102< Story 103args ={{ 104message :userMessage 105}} 106name ="User " 107play ={ async () => { 108const { settingsStore} = await import ( '$lib/stores/settings/index.svelte' ); 109 110settingsStore . updateConfig ( 'showRawOutputSwitch' , false ); 111}} 112/> 113 114< Story 115args ={{ 116class :'max-w-[56rem] w-[calc(100vw-2rem)]' , 117message :assistantMessage 118}} 119name ="Assistant " 120play ={ async () => { 121const { settingsStore} = await import ( '$lib/stores/settings/index.svelte' ); 122 123settingsStore . updateConfig ( 'showRawOutputSwitch' , false ); 124}} 125/> 126 127< Story 128args ={{ 129class :'max-w-[56rem] w-[calc(100vw-2rem)]' , 130message :assistantWithReasoning 131}} 132name ="AssistantWithReasoning " 133play ={ async () => { 134const { settingsStore} = await import ( '$lib/stores/settings/index.svelte' ); 135 136settingsStore . updateConfig ( 'showRawOutputSwitch' , false ); 137}} 138/> 139 140< Story 141args ={{ 142class :'max-w-[56rem] w-[calc(100vw-2rem)]' , 143message :rawOutputMessage 144}} 145name ="RawLlmOutput " 146play ={ async () => { 147const { settingsStore} = await import ( '$lib/stores/settings/index.svelte' ); 148 149settingsStore . updateConfig ( 'showRawOutputSwitch' , true ); 150}} 151/> 152 153< Story 154args ={{ 155message :streamingMessage 156}} 157asChild 158name ="WithReasoningContent " 159play ={ async () => { 160const { settingsStore} = await import ( '$lib/stores/settings/index.svelte' ); 161 162settingsStore . updateConfig ( 'showRawOutputSwitch' , false ); 163// Phase 1: Stream reasoning content in chunks 164let reasoningText = 165'I need to think about this carefully. Let me break down the problem:\n\n1. The user is asking for help with something complex\n2. I should provide a thorough and helpful response\n3. I need to consider multiple approaches\n4. The best solution would be to explain step by step\n\nThis approach will ensure clarity and understanding.' ; 166let reasoningChunk = 'I' ; 167let i = 0 ; 168 169while ( i < reasoningText . length ) { 170const chunkSize = Math . floor ( Math . random () * 5 ) + 3 ; // Random 3-7 characters 171const chunk = reasoningText . slice ( i , i + chunkSize ); 172 173reasoningChunk += chunk ; 174 175// Update the reactive state directly 176streamingMessage . thinking = reasoningChunk ; 177 178i += chunkSize ; 179await new Promise (( resolve ) => setTimeout ( resolve , 50 )); 180} 181 182const regularText = 183"Based on my analysis, here's the solution:\n\n**Step 1:** First, we need to understand the requirements clearly.\n\n**Step 2:** Then we can implement the solution systematically.\n\n**Step 3:** Finally, we test and validate the results.\n\nThis approach ensures we cover all aspects of the problem effectively." ; 184 185let contentChunk = '' ; 186 187i = 0 ; 188 189while ( i < regularText . length ) { 190const chunkSize = Math . floor ( Math . random () * 5 ) + 3 ; // Random 3-7 characters 191const chunk = regularText . slice ( i , i + chunkSize ); 192 193contentChunk += chunk ; 194 195// Update the reactive state directly 196streamingMessage . content = contentChunk ; 197 198i += chunkSize ; 199await new Promise (( resolve ) => setTimeout ( resolve , 50 )); 200} 201 202streamingMessage . timestamp = Date . now (); 203}} 204> 205< div class ="w-[56rem] "> 206< ChatMessage { chatActions } message ={ streamingMessage } /> 207</ div > 208</ Story > 209 210< Story 211args ={{ 212message :processingMessage 213}} 214name ="Processing " 215play ={ async () => { 216const { settingsStore} = await import ( '$lib/stores/settings/index.svelte' ); 217 218settingsStore . updateConfig ( 'showRawOutputSwitch' , false ); 219// Import the chat store to simulate loading state 220const { chatStore} = await import ( '$lib/stores/chat/index.svelte' ); 221 222// Set loading state to true to trigger the processing UI 223chatStore . isLoading = true ; 224 225// Simulate the processing state hook behavior 226// This will show the "Generating..." text and parameter details 227await new Promise (( resolve ) => setTimeout ( resolve , 100 )); 228}} 229/>