char-fork/llama.cpp

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

Aleksander Grygierui: ESLint config updates (#27700)f1357e499

char/aliceai-t5-moe
6.7 KiB229 linesraw
1<script lang="ts" module>
2	import { defineMeta } from '@storybook/addon-svelte-csf';
3	import ChatMessage from '$lib/components/app/chat/ChatMessages/ChatMessage/ChatMessage.svelte';
4	import type { ChatMessageActions } from '$lib/types';
5
6	const { Story } = defineMeta({
7		component: ChatMessage,
8		parameters: {
9			layout: 'centered'
10		},
11		title: 'Components/ChatScreen/ChatMessage'
12	});
13
14	const chatActions: ChatMessageActions = {
15		continueAssistantMessage: () => {},
16		copy: () => {},
17		delete: () => {},
18		editUserMessagePreserveResponses: () => {},
19		editWithBranching: () => {},
20		editWithReplacement: () => {},
21		forkConversation: () => {},
22		navigateToSibling: () => {},
23		regenerateWithBranching: () => {}
24	};
25
26	// Mock messages for different scenarios
27	const userMessage: DatabaseMessage = {
28		children: [],
29		content: 'What is the meaning of life, the universe, and everything?',
30		convId: 'conv-1',
31		id: '1',
32		parent: '',
33		role: 'user',
34		thinking: '',
35		timestamp: Date.now() - 1000 * 60 * 5,
36		type: 'message'
37	};
38
39	const assistantMessage: DatabaseMessage = {
40		children: [],
41		content:
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.',
43		convId: 'conv-1',
44		id: '2',
45		parent: '1',
46		role: 'assistant',
47		thinking: '',
48		timestamp: Date.now() - 1000 * 60 * 3,
49		type: 'message'
50	};
51
52	const assistantWithReasoning: DatabaseMessage = {
53		children: [],
54		content: "Here's the concise answer, now that I've thought it through carefully for you.",
55		convId: 'conv-1',
56		id: '3',
57		parent: '1',
58		role: 'assistant',
59		thinking:
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.",
61		timestamp: Date.now() - 1000 * 60 * 2,
62		type: 'message'
63	};
64	const rawOutputMessage: DatabaseMessage = {
65		children: [],
66		content:
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?',
68		convId: 'conv-1',
69		id: '6',
70		parent: '1',
71		role: 'assistant',
72		thinking: '',
73		timestamp: Date.now() - 1000 * 60,
74		type: 'message'
75	};
76
77	let processingMessage = $state({
78		children: [],
79		content: '',
80		convId: 'conv-1',
81		id: '4',
82		parent: '1',
83		role: 'assistant',
84		thinking: '',
85		timestamp: 0, // No timestamp = processing
86		type: 'message'
87	});
88
89	let streamingMessage = $state({
90		children: [],
91		content: '',
92		convId: 'conv-1',
93		id: '5',
94		parent: '1',
95		role: 'assistant',
96		thinking: '',
97		timestamp: 0, // No timestamp = streaming
98		type: 'message'
99	});
100</script>
101
102<Story
103	args={{
104		message: userMessage
105	}}
106	name="User"
107	play={async () => {
108		const { settingsStore } = await import('$lib/stores/settings/index.svelte');
109
110		settingsStore.updateConfig('showRawOutputSwitch', false);
111	}}
112/>
113
114<Story
115	args={{
116		class: 'max-w-[56rem] w-[calc(100vw-2rem)]',
117		message: assistantMessage
118	}}
119	name="Assistant"
120	play={async () => {
121		const { settingsStore } = await import('$lib/stores/settings/index.svelte');
122
123		settingsStore.updateConfig('showRawOutputSwitch', false);
124	}}
125/>
126
127<Story
128	args={{
129		class: 'max-w-[56rem] w-[calc(100vw-2rem)]',
130		message: assistantWithReasoning
131	}}
132	name="AssistantWithReasoning"
133	play={async () => {
134		const { settingsStore } = await import('$lib/stores/settings/index.svelte');
135
136		settingsStore.updateConfig('showRawOutputSwitch', false);
137	}}
138/>
139
140<Story
141	args={{
142		class: 'max-w-[56rem] w-[calc(100vw-2rem)]',
143		message: rawOutputMessage
144	}}
145	name="RawLlmOutput"
146	play={async () => {
147		const { settingsStore } = await import('$lib/stores/settings/index.svelte');
148
149		settingsStore.updateConfig('showRawOutputSwitch', true);
150	}}
151/>
152
153<Story
154	args={{
155		message: streamingMessage
156	}}
157	asChild
158	name="WithReasoningContent"
159	play={async () => {
160		const { settingsStore } = await import('$lib/stores/settings/index.svelte');
161
162		settingsStore.updateConfig('showRawOutputSwitch', false);
163		// Phase 1: Stream reasoning content in chunks
164		let 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.';
166		let reasoningChunk = 'I';
167		let i = 0;
168
169		while (i < reasoningText.length) {
170			const chunkSize = Math.floor(Math.random() * 5) + 3; // Random 3-7 characters
171			const chunk = reasoningText.slice(i, i + chunkSize);
172
173			reasoningChunk += chunk;
174
175			// Update the reactive state directly
176			streamingMessage.thinking = reasoningChunk;
177
178			i += chunkSize;
179			await new Promise((resolve) => setTimeout(resolve, 50));
180		}
181
182		const 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
185		let contentChunk = '';
186
187		i = 0;
188
189		while (i < regularText.length) {
190			const chunkSize = Math.floor(Math.random() * 5) + 3; // Random 3-7 characters
191			const chunk = regularText.slice(i, i + chunkSize);
192
193			contentChunk += chunk;
194
195			// Update the reactive state directly
196			streamingMessage.content = contentChunk;
197
198			i += chunkSize;
199			await new Promise((resolve) => setTimeout(resolve, 50));
200		}
201
202		streamingMessage.timestamp = Date.now();
203	}}
204>
205	<div class="w-[56rem]">
206		<ChatMessage {chatActions} message={streamingMessage} />
207	</div>
208</Story>
209
210<Story
211	args={{
212		message: processingMessage
213	}}
214	name="Processing"
215	play={async () => {
216		const { settingsStore } = await import('$lib/stores/settings/index.svelte');
217
218		settingsStore.updateConfig('showRawOutputSwitch', false);
219		// Import the chat store to simulate loading state
220		const { chatStore } = await import('$lib/stores/chat/index.svelte');
221
222		// Set loading state to true to trigger the processing UI
223		chatStore.isLoading = true;
224
225		// Simulate the processing state hook behavior
226		// This will show the "Generating..." text and parameter details
227		await new Promise((resolve) => setTimeout(resolve, 100));
228	}}
229/>