char-fork/llama.cpp

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

Aleksander Grygierui: Stores split refactor (#27240)521a64cd0

char/aliceai-t5-moe
2.0 KiB83 linesraw
1/**
2 * Active model resolution and capability detection for the ChatScreen.
3 *
4 * Picks the model that should be used for the current view
5 * (router: user-selected or conversation fallback; non-router: first
6 * available option), and reactively tracks which modalities (vision /
7 * audio / video) it supports — fetching model props from the server on
8 * demand if they aren't cached yet.
9 */
10
11import { conversationsStore, modelsStore, serverStore } from '$lib/stores';
12import { getConversationModel } from '$lib/utils';
13
14export function useChatScreenActiveModel() {
15	const isRouter = $derived(serverStore.isRouterMode);
16	const conversationModel = $derived(
17		getConversationModel(conversationsStore.activeMessages as DatabaseMessage[])
18	);
19	const activeModelId = $derived(modelsStore.activeModelId);
20
21	let modelPropsVersion = $state(0);
22
23	$effect(() => {
24		if (activeModelId) {
25			const cached = modelsStore.props.getModelProps(activeModelId);
26
27			if (!cached) {
28				modelsStore.props.fetchModelProps(activeModelId).then(() => {
29					modelPropsVersion++;
30				});
31			}
32		}
33	});
34
35	const hasAudioModality = $derived.by(() => {
36		if (activeModelId) {
37			void modelPropsVersion;
38
39			return modelsStore.props.modelSupportsAudio(activeModelId);
40		}
41
42		return false;
43	});
44	const hasVideoModality = $derived.by(() => {
45		if (activeModelId) {
46			void modelPropsVersion;
47
48			return modelsStore.props.modelSupportsVideo(activeModelId);
49		}
50
51		return false;
52	});
53	const hasVisionModality = $derived.by(() => {
54		if (activeModelId) {
55			void modelPropsVersion;
56
57			return modelsStore.props.modelSupportsVision(activeModelId);
58		}
59
60		return false;
61	});
62
63	return {
64		get activeModelId() {
65			return activeModelId;
66		},
67		get conversationModel() {
68			return conversationModel;
69		},
70		get hasAudioModality() {
71			return hasAudioModality;
72		},
73		get hasVideoModality() {
74			return hasVideoModality;
75		},
76		get hasVisionModality() {
77			return hasVisionModality;
78		},
79		get isRouter() {
80			return isRouter;
81		}
82	};
83}