forked from intel/AI-Playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from TNG/Feat/26--LLM_download_from_dropdown_ba…
…ckup Feat/26 llm download from dropdown backup
- Loading branch information
Showing
12 changed files
with
267 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<template> | ||
<div class="dialog-container z-10"> | ||
<div class="dialog-mask absolute left-0 top-0 w-full h-full bg-black/55 flex justify-center items-center"> | ||
<div | ||
class="py-10 px-20 w-500px flex flex-col items-center justify-center bg-gray-600 rounded-3xl gap-6 text-white" | ||
:class="{ 'animate-scale-in': animate }"> | ||
<p v-html="i18nState.REQUEST_LLM_MODEL_NAME"></p> | ||
<Input :placeholder="languages.COM_LLM_HF_PROMPT" v-model="modelRequest" @keyup.enter="addModel"></Input> | ||
<p v-show="addModelError" style="color: #F44336;">{{ addModelErrorMessage }}</p> | ||
<div class="flex justify-center items-center gap-9"> | ||
<button @click="closeAdd" class="bg-color-control-bg py-1 px-4 rounded">{{ i18nState.COM_CLOSE }}</button> | ||
<button @click="addModel" class="bg-color-control-bg py-1 px-4 rounded">{{ i18nState.COM_ADD }}</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
import { Input } from '@/components/ui/input' | ||
import { useGlobalSetup } from '@/assets/js/store/globalSetup'; | ||
import { useI18N } from '@/assets/js/store/i18n'; | ||
import { useModels, userModels } from '@/assets/js/store/models'; | ||
const i18nState = useI18N().state; | ||
const globalSetup = useGlobalSetup(); | ||
const models = useModels(); | ||
const modelRequest = ref(""); | ||
const addModelErrorMessage = ref("") | ||
const addModelError = ref(false); | ||
const animate = ref(false); | ||
const emits = defineEmits<{ | ||
(e: "close"): void, | ||
(e: "callCheckModel"): void, | ||
(e: "showWarning", warning: string, func: () => void): void | ||
}>(); | ||
function onShow() { | ||
animate.value = true; | ||
} | ||
async function addModel() { | ||
const previousModel = globalSetup.modelSettings.llm_model | ||
const isInModels = models.models.some((model) => model.name === modelRequest.value) | ||
const cancelAndShowWarning = (text: string) => { | ||
globalSetup.modelSettings.llm_model = previousModel; | ||
addModelErrorMessage.value = text; | ||
addModelError.value = true; | ||
} | ||
if (isInModels) { | ||
cancelAndShowWarning(i18nState.ERROR_ALREADY_IN_MODELS); | ||
return; | ||
} | ||
const urlExists = await checkIfUrlExists(modelRequest.value); | ||
if (!urlExists) { | ||
cancelAndShowWarning(i18nState.ERROR_REPO_NOT_EXISTS); | ||
return; | ||
} | ||
addModelError.value = false; | ||
const isLlm = await isLLM(modelRequest.value); | ||
const downloadNewModel = async () => { | ||
await registerModel(); | ||
emits("callCheckModel"); | ||
closeAdd(); | ||
}; | ||
if (!isLlm) { | ||
emits("showWarning", i18nState.WARNING_MODEL_TYPE_WRONG, downloadNewModel); | ||
} else { | ||
downloadNewModel(); | ||
} | ||
} | ||
async function registerModel() { | ||
userModels.push({ name: modelRequest.value, type: 'llm', downloaded: false }) | ||
await models.refreshModels() | ||
globalSetup.modelSettings.llm_model = modelRequest.value; | ||
} | ||
async function checkIfUrlExists(repo_id: string) { | ||
const response = await fetch(`${globalSetup.apiHost}/api/checkHFRepoExists?repo_id=${repo_id}`) | ||
const data = await response.json() | ||
return data.exists; | ||
} | ||
async function isLLM(repo_id: string) { | ||
const response = await fetch(`${globalSetup.apiHost}/api/isLLM?repo_id=${repo_id}`) | ||
const data = await response.json() | ||
return data.isllm | ||
} | ||
function closeAdd() { | ||
addModelErrorMessage.value = ""; | ||
addModelError.value = false; | ||
modelRequest.value = ""; | ||
emits("close"); | ||
} | ||
defineExpose({ onShow }); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<template> | ||
<div class="dialog-container z-10"> | ||
<div class="dialog-mask absolute left-0 top-0 w-full h-full bg-black/55 flex justify-center items-center"> | ||
<div class="py-10 px-20 w-500px flex flex-col items-center justify-center bg-gray-600 rounded-3xl gap-6 text-white" | ||
:class="{ 'animate-scale-in': animate }"> | ||
<p v-html= "warningMessage"></p> | ||
<div class="flex justify-center items-center gap-9"> | ||
<button @click="cancelConfirm" class="bg-color-control-bg py-1 px-4 rounded">{{i18nState.COM_CANCEL}}</button> | ||
<button @click="confirmAdd" class="bg-color-control-bg py-1 px-4 rounded">{{i18nState.COM_CONFIRM}}</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
import { useI18N } from '@/assets/js/store/i18n.ts'; | ||
const i18nState = useI18N().state; | ||
const confirmFunction = ref(() => {}) | ||
const warningMessage = ref("") | ||
const animate = ref(false); | ||
const emits = defineEmits<{ | ||
(e: "close"): void | ||
}>(); | ||
async function confirmAdd() { | ||
confirmFunction.value() | ||
emits("close"); | ||
} | ||
function cancelConfirm() { | ||
emits("close"); | ||
} | ||
function onShow(){ | ||
animate.value = true | ||
} | ||
defineExpose({warningMessage, confirmFunction, onShow }); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.