File size: 1,959 Bytes
0110dee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { create } from 'zustand';

export type ModelStatus = 'idle' | 'loading' | 'ready' | 'error';

export interface ModelState {
  // Model info
  modelId: string;
  status: ModelStatus;
  error: string | null;
  
  // Loading progress
  loadingProgress: number;
  loadingPhase: string;
  
  // Capabilities
  supportsWebGPU: boolean;
  maxTokens: number;
  temperature: number;
  
  // Actions
  setModelId: (modelId: string) => void;
  setStatus: (status: ModelStatus) => void;
  setError: (error: string | null) => void;
  setLoadingProgress: (progress: number, phase: string) => void;
  setSupportsWebGPU: (supports: boolean) => void;
  setTemperature: (temperature: number) => void;
  setMaxTokens: (maxTokens: number) => void;
  reset: () => void;
}

const DEFAULT_MODEL = 'Llama-3.2-1B-Instruct-q4f16_1-MLC';

export const useModelStore = create<ModelState>((set) => ({
  // Initial state
  modelId: DEFAULT_MODEL,
  status: 'idle',
  error: null,
  loadingProgress: 0,
  loadingPhase: '',
  supportsWebGPU: false,
  maxTokens: 2048,
  temperature: 0.7,

  // Actions
  setModelId: (modelId) => {
    set({ modelId, status: 'idle', error: null });
  },

  setStatus: (status) => {
    set({ status });
  },

  setError: (error) => {
    set({ error, status: 'error' });
  },

  setLoadingProgress: (progress, phase) => {
    set({ loadingProgress: progress, loadingPhase: phase });
  },

  setSupportsWebGPU: (supports) => {
    set({ supportsWebGPU: supports });
  },

  setTemperature: (temperature) => {
    set({ temperature: Math.max(0, Math.min(2, temperature)) });
  },

  setMaxTokens: (maxTokens) => {
    set({ maxTokens: Math.max(1, Math.min(4096, maxTokens)) });
  },

  reset: () => {
    set({
      modelId: DEFAULT_MODEL,
      status: 'idle',
      error: null,
      loadingProgress: 0,
      loadingPhase: '',
    });
  },
}));

// Made with Bob