Skip to content

Commit

Permalink
fix model updates
Browse files Browse the repository at this point in the history
  • Loading branch information
JEMeyer committed Jul 29, 2024
1 parent 98eddb9 commit 1e2ccbb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 19 deletions.
35 changes: 30 additions & 5 deletions src/controllers/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,16 @@ export const getModelByName = async (req: Request, res: Response) => {
export const createModel = async (req: Request, res: Response) => {
const { name, size, model_type, display_order } = req.body;

let id;
switch (model_type) {
case 'llm':
id = await LlmService.createLLM(name, size, display_order);
await LlmService.createLLM(name, size, display_order);
break;
case 'diffusor':
id = await DiffusorService.createDiffusor(name, size, display_order);
await DiffusorService.createDiffusor(name, size, display_order);
break;
case 'stt':
case 'tts':
id = await SpeechModelService.createSpeechModel(
await SpeechModelService.createSpeechModel(
name,
size,
model_type,
Expand All @@ -69,7 +68,7 @@ export const createModel = async (req: Request, res: Response) => {
return;
}

res.json({ id });
res.sendStatus(201);
};

export const deleteModel = async (req: Request, res: Response) => {
Expand All @@ -93,3 +92,29 @@ export const deleteModel = async (req: Request, res: Response) => {
}
res.sendStatus(204);
};

export const updateModel = async (req: Request, res: Response) => {
const { name, size, model_type, display_order } = req.body;
switch (model_type) {
case 'llm':
await LlmService.updateLLM(name, size, display_order);
break;
case 'diffusor':
await DiffusorService.updateDiffusor(name, size, display_order);
break;
case 'stt':
case 'tts':
await SpeechModelService.updateSpeechModel(
name,
size,
model_type,
display_order
);
break;
default:
res.status(400).json({ error: 'Invalid data/payload' });
return;
}

res.sendStatus(204);
};
1 change: 1 addition & 0 deletions src/routes/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ router.get('/', ModelController.getAllModels);
router.post('/', ModelController.createModel);
router.get('/:name', ModelController.getModelByName);
router.delete('/:name', ModelController.deleteModel);
router.put('/', ModelController.updateModel);

export default router;
5 changes: 2 additions & 3 deletions src/services/tables/diffusors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ export const createDiffusor = async (
name: string,
size: number,
display_order: number
): Promise<number> => {
): Promise<void> => {
const query =
'INSERT INTO diffusors (name, size, display_order) VALUES (?, ?, ?)';
const result = await pool.query(query, [name, size, display_order]);
return Number(result.insertId);
await pool.query(query, [name, size, display_order]);
};

// Read all Diffusors
Expand Down
5 changes: 2 additions & 3 deletions src/services/tables/llms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ export const createLLM = async (
name: string,
size: number,
display_order: number
): Promise<number> => {
): Promise<void> => {
const query = 'INSERT INTO llms (name, size, display_order) VALUES (?, ?, ?)';
const result = await pool.query(query, [name, size, display_order]);
return Number(result.insertId);
await pool.query(query, [name, size, display_order]);
};

// Read all LLMs
Expand Down
10 changes: 2 additions & 8 deletions src/services/tables/speechModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ export const createSpeechModel = async (
size: number,
model_type: 'tts' | 'stt',
display_order: number
): Promise<number> => {
): Promise<void> => {
const query =
'INSERT INTO speech_models (name, size, model_type, display_order) VALUES (?, ?, ?, ?)';
const result = await pool.query(query, [
name,
size,
model_type,
display_order,
]);
return Number(result.insertId);
await pool.query(query, [name, size, model_type, display_order]);
};

// Read all SpeechModels
Expand Down

0 comments on commit 1e2ccbb

Please sign in to comment.