Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ on:

env:
CARGO_TERM_COLOR: always
RUST_VERSION: 1.75
RUST_VERSION: 1.87
CARGO_BUILD_JOBS: 1

jobs:
# Build and test Rust server
Expand All @@ -19,9 +20,10 @@ jobs:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-action@stable
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_VERSION }}
components: rustfmt, clippy

- name: Cache Cargo dependencies
uses: swatinem/rust-cache@v2
Expand Down Expand Up @@ -58,12 +60,10 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: gui/package-lock.json

- name: Install dependencies
working-directory: ./gui
run: npm ci
run: npm install

- name: Build GUI
working-directory: ./gui
Expand All @@ -73,10 +73,6 @@ jobs:
working-directory: ./gui
run: npx tsc --noEmit

- name: Run linting
working-directory: ./gui
run: npm run lint

# Build Docker images
build-docker:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -129,7 +125,7 @@ jobs:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-action@stable
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_VERSION }}

Expand Down
172 changes: 16 additions & 156 deletions gui/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,149 +34,6 @@ interface AppState {
setStreaming: (streaming: boolean) => void;
setError: (error: string | null) => void;

// Inference
sendInferenceRequest: (messages: Message[]) => Promise<Message>;
}

export const useAppStore = create<AppState>((set, get) => ({
// Models
models: [],
selectedModel: null,

fetchModels: async () => {
try {
const response = await fetch(`${API_BASE_URL}/v1/models`);
if (!response.ok) throw new Error('Failed to fetch models');
const data = await response.json();

const models: Model[] = data.data.map((m: any) => ({
id: m.id,
name: m.name,
description: `${m.parameters} parameters, ${m.quantization} quantization`,
parameters: m.parameters,
quantization: m.quantization,
size: `${m.size_gb} GB`,
status: m.loaded ? 'loaded' as const : 'unloaded' as const,
}));

set({ models });
} catch (error) {
console.error('Error fetching models:', error);
set({ error: 'Failed to connect to server. Make sure Mohawk server is running.' });
}
},

setModels: (models) => set({ models }),
setSelectedModel: (model) => set({ selectedModel: model }),

loadModel: async (modelId) => {
set({ isLoading: true });
try {
const response = await fetch(`${API_BASE_URL}/api/models/load`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ model_id: modelId }),
});

if (!response.ok) throw new Error('Failed to load model');

set((state) => ({
models: state.models.map(m =>
m.id === modelId ? { ...m, status: 'loaded' as const } : m
),
selectedModel: state.models.find(m => m.id === modelId) || null,
isLoading: false,
}));
} catch (error) {
set({ isLoading: false, error: 'Failed to load model' });
throw error;
}
},

unloadModel: async (modelId) => {
try {
const response = await fetch(`${API_BASE_URL}/api/models/unload`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ model_id: modelId }),
});

if (!response.ok) throw new Error('Failed to unload model');

set((state) => ({
models: state.models.map(m =>
m.id === modelId ? { ...m, status: 'unloaded' as const } : m
),
selectedModel: state.selectedModel?.id === modelId ? null : state.selectedModel,
}));
} catch (error) {
set({ error: 'Failed to unload model' });
throw error;
}
},

// Chat Sessions
sessions: [],
currentSession: null,
setSessions: (sessions) => set({ sessions }),
setCurrentSession: (session) => set({ currentSession: session }),
createSession: () => {
const newSession: ChatSession = {
id: crypto.randomUUID(),
title: 'New Chat',
messages: [],
modelId: get().selectedModel?.id || '',
createdAt: new Date(),
updatedAt: new Date(),
};
set((state) => ({
sessions: [...state.sessions, newSession],
currentSession: newSession,
}));
return newSession;
},
deleteSession: (sessionId) => {
set((state) => ({
sessions: state.sessions.filter(s => s.id !== sessionId),
currentSession: state.currentSession?.id === sessionId ? null : state.currentSession,
}));
},
addMessage: (sessionId, message) => {
set((state) => ({
sessions: state.sessions.map(s =>
s.id === sessionId
? { ...s, messages: [...s.messages, message], updatedAt: new Date() }
: s
),
currentSession: state.currentSession?.id === sessionId
? { ...state.currentSession, messages: [...state.currentSession.messages, message], updatedAt: new Date() }
: state.currentSession,
}));
},

// Settings
settings: {
temperature: 0.7,
topP: 0.9,
topK: 40,
maxTokens: 2048,
stopSequences: [],
systemPrompt: 'You are a helpful AI assistant.',
},
updateSettings: (newSettings) => {
set((state) => ({
settings: { ...state.settings, ...newSettings },
}));
},

// UI State
isLoading: false,
isStreaming: false,
error: string | null;
setLoading: (loading: boolean) => void;
setStreaming: (streaming: boolean) => void;
setError: (error: string | null) => void;

// Inference
sendInferenceRequest: (messages: Message[]) => Promise<Message>;
sendInferenceRequestStream: (messages: Message[], onToken: (token: string) => void) => Promise<void>;
Expand All @@ -186,33 +43,36 @@ export const useAppStore = create<AppState>((set, get) => ({
// Models
models: [],
selectedModel: null,
error: null,

fetchModels: async () => {
try {
const response = await fetch(`${API_BASE_URL}/v1/models`);
if (!response.ok) throw new Error('Failed to fetch models');
const data = await response.json();

const models: Model[] = data.data.map((m: any) => ({
id: m.id,
name: m.name || m.id,
description: `${m.parameters || 'Unknown'} parameters`,
parameters: m.parameters || 0,
quantization: m.quantization || 'unknown',
size: `${m.size_gb || 'Unknown'} GB`,
status: m.loaded ? 'loaded' as const : 'unloaded' as const,
}));
const models: Model[] = data.data.map((m: any) => {
const parameters = m.parameters != null ? String(m.parameters) : 'Unknown';

return {
id: m.id,
name: m.name || m.id,
description: `${parameters} parameters`,
parameters,
quantization: m.quantization || 'unknown',
size: `${m.size_gb || 'Unknown'} GB`,
status: m.loaded ? 'loaded' as const : 'unloaded' as const,
};
});

set({ models, error: null });
} catch (error) {
console.error('Error fetching models:', error);
set({
error: 'Failed to connect to server. Make sure Mohawk server is running.',
models: [
{ 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 },
{ 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 },
{ 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 },
{ 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 },
{ 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 },
{ 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 },
]
});
}
Expand Down
1 change: 1 addition & 0 deletions gui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"noUnusedLocals": false,
"noUnusedParameters": false,
"noFallthroughCasesInSwitch": true,
"types": ["vite/client"],
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
Expand Down
Loading
Loading