From 0a155b680ae5e014999acb1328ce1932ed28fc94 Mon Sep 17 00:00:00 2001 From: j-myeong Date: Mon, 20 May 2024 01:48:03 +0900 Subject: [PATCH] Apply FM (llama, diffusion) deploy api in console (frontend) --- frontend/sskai-console/src/api/index.jsx | 108 +++++++++++++++++- .../src/pages/Inference/index.jsx | 38 +++--- 2 files changed, 129 insertions(+), 17 deletions(-) diff --git a/frontend/sskai-console/src/api/index.jsx b/frontend/sskai-console/src/api/index.jsx index 79ac6c00e8..86e88fc173 100644 --- a/frontend/sskai-console/src/api/index.jsx +++ b/frontend/sskai-console/src/api/index.jsx @@ -6,7 +6,12 @@ const INFERENCE_SERVERLESS_API = import.meta.env .VITE_INFERENCE_SERVERLESS_API_URL; const MODEL_PROFILE_API = import.meta.env.VITE_MODEL_PROFILE_API_URL; const USER_TRAIN_API = import.meta.env.VITE_USER_TRAIN_API_URL; +const LLAMA_TRAIN_API = import.meta.env.VITE_LLAMA_TRAIN_API_URL; +const DIFFUSION_TRAIN_API = import.meta.env.VITE_DIFFUSION_TRAIN_API_URL; const STREAMLIT_API = import.meta.env.VITE_STREAMLIT_API_URL; +const INFERENCE_LLAMA_API = import.meta.env.VITE_INFERENCE_LLAMA_API_URL; +const INFERENCE_DIFFUSION_API = import.meta.env + .VITE_INFERENCE_DIFFUSION_API_URL; // Model export const createModel = async (args) => { @@ -428,6 +433,108 @@ export const manageStreamlit = async ({ return res.status === 200; }; +export const createFMInference = async (type, args) => { + const res = await axios + .post(`${DB_API}/inferences`, { + user: args.user, + name: args.name, + model: args.model, + model_type: args.model_type, + type: args.type + }) + .catch((err) => err); + + if (!res?.data) { + console.error(res); + return false; + } + + const { Item } = res.data.inference; + + if (type === 'llama') { + const llama = await axios + .post(`${INFERENCE_LLAMA_API}`, { + uid: Item.uid, + user: args.user, + action: 'create', + model: args.model_detail + }) + .catch((err) => err); + + if (llama.status !== 200) { + await axios.delete(`${DB_API}/inferences/${Item.uid}`); + return false; + } + + await createLog({ + user: args.user, + name: args.name, + kind_of_job: 'inference', + job: 'Endpoint (Llama) Created' + }); + } else if (type === 'diffusion') { + const diffusion = await axios + .post(`${INFERENCE_DIFFUSION_API}`, { + uid: Item.uid, + user: args.user, + action: 'create', + model: args.model_detail + }) + .catch((err) => err); + + if (diffusion.status !== 200) { + await axios.delete(`${DB_API}/inferences/${Item.uid}`); + return false; + } + + await createLog({ + user: args.user, + name: args.name, + kind_of_job: 'inference', + job: 'Endpoint (Diffusion) Created' + }); + } + return Item; +}; + +export const deleteFMInference = async (type, args) => { + if (type === 'llama') { + const llama = await axios + .post(`${INFERENCE_LLAMA_API}`, { + uid: args.uid, + user: args.user, + action: 'delete' + }) + .catch((err) => err); + + await createLog({ + user: args.user, + name: args.name, + kind_of_job: 'inference', + job: 'Endpoint (Llama) Deleted' + }); + + return llama.status === 200; + } else if (type === 'diffusion') { + const diffusion = await axios + .post(`${INFERENCE_DIFFUSION_API}`, { + uid: args.uid, + user: args.user, + action: 'delete' + }) + .catch((err) => err); + + await createLog({ + user: args.user, + name: args.name, + kind_of_job: 'inference', + job: 'Endpoint (Diffusion) Deleted' + }); + + return diffusion.status === 200; + } +}; + // Upload Files (Model / Data) export const uploadS3 = async (upload_type, user_uid, uid, file) => { const res = await axios @@ -532,7 +639,6 @@ export const uploadS3Multipart = async (upload_type, user_uid, uid, file) => { }; // Logs - export const getLogs = async (user_uid) => { const res = await axios .get(`${DB_API}/logs`, { diff --git a/frontend/sskai-console/src/pages/Inference/index.jsx b/frontend/sskai-console/src/pages/Inference/index.jsx index d8fe052609..4c3c15a57d 100644 --- a/frontend/sskai-console/src/pages/Inference/index.jsx +++ b/frontend/sskai-console/src/pages/Inference/index.jsx @@ -22,8 +22,10 @@ import { } from 'antd'; import { useEffect, useState } from 'react'; import { + createFMInference, createServerlessInference, createSpotInference, + deleteFMInference, deleteServerlessInference, deleteSpotInference, getInferences, @@ -234,9 +236,11 @@ export default function Inference(props) { } }; const endpoint = - inferenceType === 'Spot' - ? await createSpotInference(args) - : await createServerlessInference(args); + inferenceType === 'Serverless' + ? await createServerlessInference(args) + : selectedModel.type === 'user' + ? await createSpotInference(args) + : await createFMInference(selectedModel.type, args); setIsCreateLoading(false); if (!endpoint) @@ -256,18 +260,24 @@ export default function Inference(props) { const target = selectedDetail[0]; if (!target) return; target?.streamlit_url && (await handleStreamlit('delete')); - target.type === 'Spot' - ? await deleteSpotInference({ - uid: target.uid, - user: target.user, - name: target.name - }) - : await deleteServerlessInference({ + target.type === 'Serverless' + ? await deleteServerlessInference({ uid: target.uid, user: target.user, model: target.model, name: target.name - }); + }) + : target.model_type === 'user' + ? await deleteSpotInference({ + uid: target.uid, + user: target.user, + name: target.name + }) + : await deleteFMInference(target.model_type, { + uid: target.uid, + user: target.user, + name: target.name + }); await fetchData(); messageApi.open({ type: 'success', @@ -408,11 +418,7 @@ export default function Inference(props) {