model fixes

This commit is contained in:
AndzejsP 2023-06-23 13:00:14 +03:00
parent 590664bc1a
commit 74c0669f38
3 changed files with 211 additions and 150 deletions

View File

@ -1,7 +1,7 @@
<template>
<div class=" items-start p-4 hover:bg-primary-light rounded-lg mb-2 shadow-lg border-2 cursor-pointer select-none"
@click.stop="toggleSelected" :class="selected ? ' border-primary-light' : 'border-transparent'"
:title="!binding.installed ? 'Not installed' : ''">
:title="!binding.installed ? 'Not installed' : binding.name">
<div :class="!binding.installed ? 'opacity-50' : ''">

View File

@ -1,106 +1,201 @@
<template>
<div
class="relative items-start p-4 hover:bg-primary-light rounded-lg mb-2 shadow-lg border-2 cursor-pointer select-none"
@click.stop="toggleSelected" :class="selected ? ' border-primary-light' : 'border-transparent'" :title="title">
<div class="flex items-center p-4 hover:bg-primary-light rounded-lg mb-2 shadow-lg border-2 cursor-pointer active:opacity-80 duration-75 "
@click.stop="toggleSelected" :class="selected ? ' border-primary-light' : 'border-transparent'">
<div class="flex-1" v-if="model.isCustomModel">
<div class="flex gap-3 items-center">
<div class="flex flex-row" v-if="model.isCustomModel">
<div class="flex gap-3 items-center grow">
<img :src="getImgUrl()" @error="defaultImg($event)" class="w-10 h-10 rounded-lg object-fill">
<h3 class="font-bold font-large text-lg">
<h3 class="font-bold font-large text-lg truncate ">
{{ title }}
</h3>
</div>
<button type="button" title="Custom model / local model"
class="font-medium rounded-lg text-sm p-2 text-center inline-flex items-center " @click.stop="">
<i data-feather="box" class="w-5"></i>
<span class="sr-only">Custom model / local model</span>
</button>
<button
class=" hover:text-red-600 duration-75 active:scale-90 font-medium rounded-lg text-sm p-2 text-center inline-flex items-center "
title="Delete file from disk" type="button" @click.stop="">
<i data-feather="trash" class="w-5"></i>
</button>
</div>
<div
class="absolute z-10 -m-4 p-5 shadow-md text-center rounded-lg w-full h-full bg-bg-light-tone-panel dark:bg-bg-dark-tone-panel bg-opacity-70 dark:bg-opacity-70 flex justify-center items-center">
<!-- DOWNLOAD MODEL PANEL SPINNER -->
<div class="relative flex flex-col items-center justify-center flex-grow h-full">
<div role="status" class=" justify-center ">
<!-- SPINNER -->
<svg aria-hidden="true" class="w-24 h-24 mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor" />
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill" />
</svg>
<span class="sr-only">Loading...</span>
</div>
<div class="relative flex flex-row flex-grow items-center w-full h-full bottom-0">
<!-- PROGRESS BAR -->
<div class="w-full bg-bg-light-tone-panel dark:bg-bg-dark-tone-panel rounded-lg p-2">
<div class="flex justify-between mb-1">
<span class="text-base font-medium text-blue-700 dark:text-white">Downloading</span>
<span class="text-sm font-medium text-blue-700 dark:text-white">45%</span>
</div>
<div class="w-full bg-gray-200 rounded-full h-2.5 dark:bg-gray-700">
<div class="bg-blue-600 h-2.5 rounded-full" style="width: 45%"></div>
</div>
</div>
</div>
<div class="flex flex-grow">
<!-- CANCEL BUTTON -->
<div class="flex flex-row flex-grow gap-3">
<div class="p-2 text-center grow">
<!-- <button @click.stop="hide(true)" type="button"
class="mr-2 text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm sm:w-auto px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">
{{ ConfirmButtonText }}
</button> -->
<button @click.stop="" type="button" title="Cancel download"
class="text-gray-500 bg-white hover:bg-gray-100 focus:ring-4 focus:outline-none focus:ring-gray-200 rounded-lg border border-gray-200 text-sm font-medium px-5 py-2.5 hover:text-gray-900 focus:z-10 dark:bg-gray-700 dark:text-gray-300 dark:border-gray-500 dark:hover:text-white dark:hover:bg-gray-600 dark:focus:ring-gray-600">
Cancel
</button>
</div>
</div>
</div>
</div>
</div>
<div class="flex-1" v-if="!model.isCustomModel">
<div class="flex flex-row gap-3 items-center ">
<img ref="imgElement" :src="getImgUrl()" @error="defaultImg($event)" class="w-10 h-10 rounded-lg object-fill" :class="linkNotValid ? 'grayscale':''">
<h3 class="font-bold font-large text-lg">
<div v-if="!model.isCustomModel" :class="!model.isInstalled ? 'opacity-50' : ''">
<div class="flex flex-row items-center gap-3 ">
<img ref="imgElement" :src="getImgUrl()" @error="defaultImg($event)" class="w-10 h-10 rounded-lg object-fill"
:class="linkNotValid ? 'grayscale' : ''">
<h3 class="font-bold font-large text-lg truncate">
{{ title }}
</h3>
<div class="flex-grow">
<div class="grow">
<!-- EMPTY SPACE FILLER -->
</div>
</div>
<div class="flex flex-shrink-0 items-center ">
<i data-feather="download" class="w-5 m-1" ></i>
<b>Manual download:&nbsp;</b>
<a :href="path" @click.stop class="flex items-center hover:text-secondary duration-75 active:scale-90"
title="Download this manually (faster) and put it in the models/<your binding> folder under your home directory/Documents/lollms folder then refresh">
{{ title }}
</a>
</div>
<div class="flex flex-shrink-0 items-center">
<div class="flex flex-shrink-0 items-center" :class="linkNotValid? 'text-red-600':''">
<i data-feather="file" class="w-5 m-1"></i>
<b>File size:&nbsp;</b>
{{ fileSize }}
</div>
</div>
<div class="flex flex-shrink-0 items-center">
<i data-feather="key" class="w-5 m-1"></i>
<b>License:&nbsp;</b>
{{ license }}
</div>
<div class="flex flex-shrink-0 items-center">
<i data-feather="user" class="w-5 m-1"></i>
<b>Owner:&nbsp;</b>
<a :href="owner_link" target="_blank" rel="noopener noreferrer" @click.stop class="flex hover:text-secondary duration-75 active:scale-90"
title="Owner's profile">
{{ owner }}
</a>
</div>
<div class="flex items-center">
<i data-feather="info" class="w-5 m-1"></i>
<b>Description:&nbsp;</b><br>
</div>
<p class="mx-1 opacity-80">{{ description }}</p>
</div>
<div class="flex flex-row flex-shrink-0 items-center" >
<button class="text-lg hover:text-secondary duration-75 active:scale-90 p-2"
<!-- ADVANCED OPTIONS -->
<div class="flex-none gap-1">
<button v-if="!model.isInstalled" type="button" title="Not installed"
class="hover:text-red-600 duration-75 font-medium rounded-lg text-sm p-2 text-center inline-flex items-center "
@click.stop="">
<i data-feather="slash" class="w-5"></i>
<span class="sr-only">Not installed</span>
</button>
<button v-if="!model.isInstalled" type="button" title="Click to install model"
class="hover:text-secondary duration-75 active:scale-90 font-medium rounded-lg text-sm p-2 text-center inline-flex items-center "
@click.stop="">
<i data-feather="plus-square" class="w-5"></i>
<span class="sr-only">Install</span>
</button>
<button v-if="model.isInstalled"
class=" hover:text-red-600 duration-75 active:scale-90 font-medium rounded-lg text-sm p-2 text-center inline-flex items-center "
title="Delete file from disk" type="button" @click.stop="">
<i data-feather="trash" class="w-5"></i>
</button>
<button
class="hover:text-secondary duration-75 active:scale-90 font-medium rounded-lg text-sm p-2 text-center inline-flex items-center "
title="Copy model info to clipboard" @click.stop="toggleCopy()">
<i data-feather="clipboard"></i>
</button>
<button v-if="model_type !== 'api'" class="px-4 py-2 rounded-md text-white font-bold transition-colors duration-300"
:class="[isInstalled ? 'bg-red-500 hover:bg-red-600' : linkNotValid ? 'bg-gray-500 hover:bg-gray-600' : 'bg-green-500 hover:bg-green-600']"
:disabled="installing || uninstalling" @click.stop="toggleInstall">
<template v-if="installing">
<div class="flex items-center space-x-2">
<div class="h-2 w-20 bg-gray-300 rounded">
<div :style="{ width: progress + '%' }" class="h-full bg-red-500 rounded"></div>
</div>
<span>Installing...{{ Math.floor(progress) }}%</span>
</div>
</template>
<template v-else-if="uninstalling">
<div class="flex items-center space-x-2">
<div class="h-2 w-20 bg-gray-300 rounded">
<div :style="{ width: progress + '%' }" class="h-full bg-green-500"></div>
</div>
<span>Uninstalling...</span>
</div>
</template>
<template v-else>
{{ isInstalled ? model.isCustomModel ? 'Delete' : 'Uninstall' : linkNotValid ? 'Link is not valid':'Install' }}
</template>
</button>
<i data-feather="clipboard" class="w-5"></i>
</button>
<!-- <button v-if="selected" type="button" title="Settings"
class="hover:text-secondary duration-75 active:scale-90 font-medium rounded-lg text-sm p-2 text-center inline-flex items-center "
@click.stop="toggleSettings">
<i data-feather="sliders" class="w-5"></i>
<span class="sr-only">Settings</span>
</button> -->
<!-- - NOT IMPLEMENTED -->
<!--
<button type="button" title="Help - Not implemented"
class="hover:text-secondary duration-75 active:scale-90 font-medium rounded-lg text-sm p-2 text-center inline-flex items-center " @click.stop="">
<i data-feather="help-circle" class="w-5"></i>
<span class="sr-only">Help</span>
</button> -->
</div>
</div>
<div class="" :title="!model.isInstalled ? 'Not installed' : title">
<div class="">
<div class="flex flex-row items-center ">
<div v-if="linkNotValid" class="text-base text-red-600 flex items-center mt-1 ">
<i data-feather="alert-triangle" class="flex-shrink-0 mx-1"></i>
Link is not valid
</div>
</div>
<div class="flex flex-row items-center ">
<i data-feather="download" class="w-5 m-1 flex-shrink-0"></i>
<b>Manual download:&nbsp;</b>
<a :href="path" @click.stop
class="m-1 flex items-center hover:text-secondary duration-75 active:scale-90 truncate"
:title="linkNotValid ? 'Link is not valid' : 'Download this manually (faster) and put it in the models/<current binding> folder then refresh'">
Click here to download
</a>
<button
class="hover:text-secondary duration-75 active:scale-90 font-medium rounded-lg text-sm p-2 text-center inline-flex items-center "
title="Copy link to clipboard" @click.stop="toggleCopyLink()">
<i data-feather="copy" class="w-5"></i>
</button>
</div>
<div class="flex items-center">
<div class="flex flex-shrink-0 items-center" :class="linkNotValid ? 'text-red-600' : ''">
<i data-feather="file" class="w-5 m-1"></i>
<b>File size:&nbsp;</b>
{{ fileSize }}
</div>
</div>
<div class="flex items-center">
<i data-feather="key" class="w-5 m-1"></i>
<b>License:&nbsp;</b>
{{ license }}
</div>
<div class="flex items-center">
<i data-feather="user" class="w-5 m-1"></i>
<b>Owner:&nbsp;</b>
<a :href="owner_link" target="_blank" rel="noopener noreferrer" @click.stop
class="flex hover:text-secondary duration-75 active:scale-90" title="Owner's profile">
{{ owner }}
</a>
</div>
</div>
<div class="flex items-center">
<i data-feather="info" class="w-5 m-1"></i>
<b>Description:&nbsp;</b><br>
</div>
<p class="mx-1 opacity-80 line-clamp-3" :title="description">{{ description }}</p>
</div>
</div>
</div>
</template>
<script>
import filesize from '../plugins/filesize'
import axios from "axios";
@ -122,6 +217,7 @@ export default {
onUninstall: Function,
onSelected: Function,
onCopy: Function,
onCopyLink: Function,
selected: Boolean,
model: Object,
model_type: String
@ -133,7 +229,7 @@ export default {
uninstalling: false,
failedToLoad: false,
fileSize: '',
linkNotValid:false,
linkNotValid: false,
};
},
async mounted() {
@ -146,17 +242,17 @@ export default {
})
},
methods: {
computedFileSize(size){
return filesize(size)
},
computedFileSize(size) {
return filesize(size)
},
async getFileSize(url) {
//console.log(this.model_type);
if(this.model_type!="api"){
if (this.model_type != "api") {
try {
const res = await axios.head(url)
//console.log("addddd",url, res.headers)
if (res) {
if (res.headers["content-length"]) {
return this.computedFileSize(res.headers["content-length"])
}
@ -192,12 +288,12 @@ export default {
// }
} catch (error) {
console.log(error.message,'getFileSize')
this.linkNotValid=true
} catch (error) {
console.log(error.message, 'getFileSize')
this.linkNotValid = true
return 'Could not be determined'
}
}
}
@ -228,9 +324,13 @@ export default {
this.onSelected(this)
},
toggleCopy() {
this.onCopy(this)
},
toggleCopyLink() {
this.onCopyLink(this)
//navigator.clipboard.writeText(this.path)
},
handleSelection() {
if (this.isInstalled && !this.selected) {
this.onSelected(this);
@ -238,17 +338,17 @@ export default {
},
copyContentToClipboard() {
console.log('asdasdas')
this.$emit('copy', 'this.message.content')
this.$emit('copy', 'this.message.content')
},
},
},
watch:{
linkNotValid(){
watch: {
linkNotValid() {
nextTick(() => {
feather.replace()
feather.replace()
})
})
}
}
};

View File

@ -441,57 +441,13 @@
<div :class="{ 'hidden': mzc_collapsed }" class="flex flex-col mb-2 px-3 pb-0">
<div class="mb-2" v-if="configFile.binding_name">
<!-- <div >
<label for="model" class="block ml-2 mb-2 text-sm font-medium text-gray-900 dark:text-white">
Add models:
</label>
<div class="p-2 ">
<form>
<div class="mb-3">
<label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
for="file_input">Select
files</label>
<input
class="block w-full text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-50 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400"
id="multiple_files" type="file" multiple>
</div>
<button type="submit"
class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Upload</button>
</form>
</div>
<div class="p-2 ">
<form>
<div class="mb-3">
<label for="email"
class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Model
URL</label>
<input type="email" id="email"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder="url" required>
</div>
<button type="submit"
class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Download</button>
</form>
</div>
</div> -->
</div>
<div v-if="models.length > 0" class="mb-2">
<label for="model" class="block ml-2 mb-2 text-sm font-medium text-gray-900 dark:text-white">
Models: ({{ models.length }})
</label>
<div class="overflow-y-auto no-scrollbar p-2 pb-0 " :class="mzl_collapsed ? '' : 'max-h-96'">
<div class="overflow-y-auto no-scrollbar p-2 pb-0 grid lg:grid-cols-3 md:grid-cols-2 gap-4" :class="mzl_collapsed ? '' : 'max-h-96'">
<TransitionGroup name="list">
<model-entry ref="modelZoo" v-for="(model, index) in models"
:key="'index-' + index + '-' + model.title" :title="model.title" :icon="model.icon"
@ -499,7 +455,7 @@
:license="model.license" :description="model.description"
:is-installed="model.isInstalled" :on-install="onInstall" :on-uninstall="onUninstall"
:on-selected="onSelected" :selected="model.title === configFile.model_name"
:model="model" :model_type="model.model_type" :on-copy="onCopy" />
:model="model" :model_type="model.model_type" :on-copy="onCopy" :on-copy-link="onCopyLink" />
</TransitionGroup>
</div>
</div>
@ -1253,6 +1209,11 @@ export default {
this.$refs.toast.showToast("Copied model info to clipboard!", 4, true)
navigator.clipboard.writeText(content.trim());
},
onCopyLink(modelEntry) {
this.$refs.toast.showToast("Copied link to clipboard!", 4, true)
navigator.clipboard.writeText(modelEntry.path);
},
// Model installation