@@ -34,149 +34,6 @@ interface AppState {
3434 setStreaming : ( streaming : boolean ) => void ;
3535 setError : ( error : string | null ) => void ;
3636
37- // Inference
38- sendInferenceRequest : ( messages : Message [ ] ) => Promise < Message > ;
39- }
40-
41- export const useAppStore = create < AppState > ( ( set , get ) => ( {
42- // Models
43- models : [ ] ,
44- selectedModel : null ,
45-
46- fetchModels : async ( ) => {
47- try {
48- const response = await fetch ( `${ API_BASE_URL } /v1/models` ) ;
49- if ( ! response . ok ) throw new Error ( 'Failed to fetch models' ) ;
50- const data = await response . json ( ) ;
51-
52- const models : Model [ ] = data . data . map ( ( m : any ) => ( {
53- id : m . id ,
54- name : m . name ,
55- description : `${ m . parameters } parameters, ${ m . quantization } quantization` ,
56- parameters : m . parameters ,
57- quantization : m . quantization ,
58- size : `${ m . size_gb } GB` ,
59- status : m . loaded ? 'loaded' as const : 'unloaded' as const ,
60- } ) ) ;
61-
62- set ( { models } ) ;
63- } catch ( error ) {
64- console . error ( 'Error fetching models:' , error ) ;
65- set ( { error : 'Failed to connect to server. Make sure Mohawk server is running.' } ) ;
66- }
67- } ,
68-
69- setModels : ( models ) => set ( { models } ) ,
70- setSelectedModel : ( model ) => set ( { selectedModel : model } ) ,
71-
72- loadModel : async ( modelId ) => {
73- set ( { isLoading : true } ) ;
74- try {
75- const response = await fetch ( `${ API_BASE_URL } /api/models/load` , {
76- method : 'POST' ,
77- headers : { 'Content-Type' : 'application/json' } ,
78- body : JSON . stringify ( { model_id : modelId } ) ,
79- } ) ;
80-
81- if ( ! response . ok ) throw new Error ( 'Failed to load model' ) ;
82-
83- set ( ( state ) => ( {
84- models : state . models . map ( m =>
85- m . id === modelId ? { ...m , status : 'loaded' as const } : m
86- ) ,
87- selectedModel : state . models . find ( m => m . id === modelId ) || null ,
88- isLoading : false ,
89- } ) ) ;
90- } catch ( error ) {
91- set ( { isLoading : false , error : 'Failed to load model' } ) ;
92- throw error ;
93- }
94- } ,
95-
96- unloadModel : async ( modelId ) => {
97- try {
98- const response = await fetch ( `${ API_BASE_URL } /api/models/unload` , {
99- method : 'POST' ,
100- headers : { 'Content-Type' : 'application/json' } ,
101- body : JSON . stringify ( { model_id : modelId } ) ,
102- } ) ;
103-
104- if ( ! response . ok ) throw new Error ( 'Failed to unload model' ) ;
105-
106- set ( ( state ) => ( {
107- models : state . models . map ( m =>
108- m . id === modelId ? { ...m , status : 'unloaded' as const } : m
109- ) ,
110- selectedModel : state . selectedModel ?. id === modelId ? null : state . selectedModel ,
111- } ) ) ;
112- } catch ( error ) {
113- set ( { error : 'Failed to unload model' } ) ;
114- throw error ;
115- }
116- } ,
117-
118- // Chat Sessions
119- sessions : [ ] ,
120- currentSession : null ,
121- setSessions : ( sessions ) => set ( { sessions } ) ,
122- setCurrentSession : ( session ) => set ( { currentSession : session } ) ,
123- createSession : ( ) => {
124- const newSession : ChatSession = {
125- id : crypto . randomUUID ( ) ,
126- title : 'New Chat' ,
127- messages : [ ] ,
128- modelId : get ( ) . selectedModel ?. id || '' ,
129- createdAt : new Date ( ) ,
130- updatedAt : new Date ( ) ,
131- } ;
132- set ( ( state ) => ( {
133- sessions : [ ...state . sessions , newSession ] ,
134- currentSession : newSession ,
135- } ) ) ;
136- return newSession ;
137- } ,
138- deleteSession : ( sessionId ) => {
139- set ( ( state ) => ( {
140- sessions : state . sessions . filter ( s => s . id !== sessionId ) ,
141- currentSession : state . currentSession ?. id === sessionId ? null : state . currentSession ,
142- } ) ) ;
143- } ,
144- addMessage : ( sessionId , message ) => {
145- set ( ( state ) => ( {
146- sessions : state . sessions . map ( s =>
147- s . id === sessionId
148- ? { ...s , messages : [ ...s . messages , message ] , updatedAt : new Date ( ) }
149- : s
150- ) ,
151- currentSession : state . currentSession ?. id === sessionId
152- ? { ...state . currentSession , messages : [ ...state . currentSession . messages , message ] , updatedAt : new Date ( ) }
153- : state . currentSession ,
154- } ) ) ;
155- } ,
156-
157- // Settings
158- settings : {
159- temperature : 0.7 ,
160- topP : 0.9 ,
161- topK : 40 ,
162- maxTokens : 2048 ,
163- stopSequences : [ ] ,
164- systemPrompt : 'You are a helpful AI assistant.' ,
165- } ,
166- updateSettings : ( newSettings ) => {
167- set ( ( state ) => ( {
168- settings : { ...state . settings , ...newSettings } ,
169- } ) ) ;
170- } ,
171-
172- // UI State
173- isLoading : false ,
174- isStreaming : false ,
175- error : string | null ;
176- setLoading : ( loading : boolean ) => void ;
177- setStreaming : ( streaming : boolean ) => void ;
178- setError: ( error : string | null ) => void ;
179-
18037 // Inference
18138 sendInferenceRequest : ( messages : Message [ ] ) => Promise < Message > ;
18239 sendInferenceRequestStream : ( messages : Message [ ] , onToken : ( token : string ) => void ) => Promise < void > ;
@@ -186,33 +43,36 @@ export const useAppStore = create<AppState>((set, get) => ({
18643 // Models
18744 models : [ ] ,
18845 selectedModel : null ,
189- error : null ,
19046
19147 fetchModels : async ( ) => {
19248 try {
19349 const response = await fetch ( `${ API_BASE_URL } /v1/models` ) ;
19450 if ( ! response . ok ) throw new Error ( 'Failed to fetch models' ) ;
19551 const data = await response . json ( ) ;
19652
197- const models : Model [ ] = data . data . map ( ( m : any ) => ( {
198- id : m . id ,
199- name : m . name || m . id ,
200- description : `${ m . parameters || 'Unknown' } parameters` ,
201- parameters : m . parameters || 0 ,
202- quantization : m . quantization || 'unknown' ,
203- size : `${ m . size_gb || 'Unknown' } GB` ,
204- status : m . loaded ? 'loaded' as const : 'unloaded' as const ,
205- } ) ) ;
53+ const models : Model [ ] = data . data . map ( ( m : any ) => {
54+ const parameters = m . parameters != null ? String ( m . parameters ) : 'Unknown' ;
55+
56+ return {
57+ id : m . id ,
58+ name : m . name || m . id ,
59+ description : `${ parameters } parameters` ,
60+ parameters,
61+ quantization : m . quantization || 'unknown' ,
62+ size : `${ m . size_gb || 'Unknown' } GB` ,
63+ status : m . loaded ? 'loaded' as const : 'unloaded' as const ,
64+ } ;
65+ } ) ;
20666
20767 set ( { models, error : null } ) ;
20868 } catch ( error ) {
20969 console . error ( 'Error fetching models:' , error ) ;
21070 set ( {
21171 error : 'Failed to connect to server. Make sure Mohawk server is running.' ,
21272 models : [
213- { id : 'llama-3.2-3b-instruct' , name : 'Llama 3.2 3B Instruct' , description : '3B parameters, Q4_K_M' , parameters : 3000000000 , quantization : 'Q4_K_M' , size : '2.1 GB' , status : 'unloaded' as const } ,
214- { id : 'mistral-7b-v0.3' , name : 'Mistral 7B v0.3' , description : '7B parameters, Q5_K_M' , parameters : 7000000000 , quantization : 'Q5_K_M' , size : '4.5 GB' , status : 'unloaded' as const } ,
215- { id : 'phi-3-mini' , name : 'Phi-3 Mini' , description : '3.8B parameters, Q4_K_M' , parameters : 3800000000 , quantization : 'Q4_K_M' , size : '2.4 GB' , status : 'unloaded' as const } ,
73+ { id : 'llama-3.2-3b-instruct' , name : 'Llama 3.2 3B Instruct' , description : '3B parameters, Q4_K_M' , parameters : ' 3000000000' , quantization : 'Q4_K_M' , size : '2.1 GB' , status : 'unloaded' as const } ,
74+ { id : 'mistral-7b-v0.3' , name : 'Mistral 7B v0.3' , description : '7B parameters, Q5_K_M' , parameters : ' 7000000000' , quantization : 'Q5_K_M' , size : '4.5 GB' , status : 'unloaded' as const } ,
75+ { id : 'phi-3-mini' , name : 'Phi-3 Mini' , description : '3.8B parameters, Q4_K_M' , parameters : ' 3800000000' , quantization : 'Q4_K_M' , size : '2.4 GB' , status : 'unloaded' as const } ,
21676 ]
21777 } ) ;
21878 }
0 commit comments