lollms-webui/web/src/components/ModelEntry.vue

256 lines
7.8 KiB
Vue
Raw Normal View History

2023-05-10 23:33:08 +02:00
<template>
2023-06-08 17:58:02 +03:00
<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'">
2023-05-25 21:12:39 +03:00
<div class="flex-1" v-if="model.isCustomModel">
<div class="flex gap-3 items-center">
<img :src="getImgUrl()" @error="defaultImg($event)" class="w-10 h-10 rounded-lg object-fill">
<h3 class="font-bold font-large text-lg">
{{ title }}
</h3>
</div>
2023-06-08 17:58:02 +03:00
</div>
<div class="flex-1" v-if="!model.isCustomModel">
2023-06-08 17:58:02 +03:00
<div class="flex flex-row gap-3 items-center ">
2023-06-01 13:07:54 +03:00
<img ref="imgElement" :src="getImgUrl()" @error="defaultImg($event)" class="w-10 h-10 rounded-lg object-fill" :class="linkNotValid ? 'grayscale':''">
2023-05-25 21:12:39 +03:00
<h3 class="font-bold font-large text-lg">
{{ title }}
</h3>
2023-06-08 17:58:02 +03:00
<div class="flex-grow">
</div>
2023-05-25 21:12:39 +03:00
</div>
2023-05-27 17:30:29 +03:00
<div class="flex flex-shrink-0 items-center ">
<i data-feather="download" class="w-5 m-1" ></i>
2023-05-25 21:12:39 +03:00
<b>Manual download:&nbsp;</b>
2023-05-27 17:30:29 +03:00
2023-05-27 15:52:50 +03:00
<a :href="path" @click.stop class="flex items-center hover:text-secondary duration-75 active:scale-90"
2023-06-10 01:37:50 +02:00
title="Download this manually (faster) and put it in the models/<your binding> folder under your home directory/Documents/lollms folder then refresh">
2023-05-27 15:52:50 +03:00
2023-05-27 17:30:29 +03:00
2023-05-25 21:12:39 +03:00
{{ title }}
2023-05-27 15:52:50 +03:00
2023-05-25 21:12:39 +03:00
</a>
</div>
2023-05-27 17:30:29 +03:00
<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>
2023-05-27 15:52:50 +03:00
<b>File size:&nbsp;</b>
2023-05-27 17:30:29 +03:00
2023-05-27 15:52:50 +03:00
{{ fileSize }}
</div>
</div>
2023-05-27 17:30:29 +03:00
<div class="flex flex-shrink-0 items-center">
<i data-feather="key" class="w-5 m-1"></i>
2023-05-25 21:12:39 +03:00
<b>License:&nbsp;</b>
{{ license }}
</div>
2023-05-27 17:30:29 +03:00
<div class="flex flex-shrink-0 items-center">
<i data-feather="user" class="w-5 m-1"></i>
2023-05-25 21:12:39 +03:00
<b>Owner:&nbsp;</b>
2023-05-27 15:52:50 +03:00
<a :href="owner_link" target="_blank" rel="noopener noreferrer" @click.stop class="flex hover:text-secondary duration-75 active:scale-90"
2023-05-25 21:12:39 +03:00
title="Owner's profile">
2023-05-27 17:30:29 +03:00
2023-05-25 21:12:39 +03:00
{{ owner }}
</a>
</div>
2023-05-27 17:30:29 +03:00
<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>
2023-05-25 21:12:39 +03:00
</div>
2023-06-08 17:58:02 +03:00
<div class="flex flex-row flex-shrink-0 items-center" >
<button class="text-lg hover:text-secondary duration-75 active:scale-90 p-2"
title="Copy model info to clipboard" @click.stop="toggleCopy()">
<i data-feather="clipboard"></i>
</button>
2023-05-30 00:37:09 +02:00
<button v-if="model_type !== 'api'" class="px-4 py-2 rounded-md text-white font-bold transition-colors duration-300"
2023-05-27 15:52:50 +03:00
:class="[isInstalled ? 'bg-red-500 hover:bg-red-600' : linkNotValid ? 'bg-gray-500 hover:bg-gray-600' : 'bg-green-500 hover:bg-green-600']"
2023-05-25 21:12:39 +03:00
: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>
2023-05-14 00:24:26 +02:00
</div>
2023-05-25 21:12:39 +03:00
<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>
2023-05-14 00:24:26 +02:00
</div>
2023-05-25 21:12:39 +03:00
<span>Uninstalling...</span>
</div>
</template>
<template v-else>
2023-05-27 15:52:50 +03:00
{{ isInstalled ? model.isCustomModel ? 'Delete' : 'Uninstall' : linkNotValid ? 'Link is not valid':'Install' }}
2023-05-25 21:12:39 +03:00
</template>
</button>
2023-05-30 00:37:09 +02:00
2023-05-25 21:12:39 +03:00
</div>
2023-05-11 15:09:35 +02:00
</div>
2023-06-08 17:58:02 +03:00
2023-05-11 15:09:35 +02:00
</template>
<script>
2023-05-29 13:38:02 +03:00
import filesize from '../plugins/filesize'
2023-05-27 15:52:50 +03:00
import axios from "axios";
2023-05-19 17:33:31 +03:00
import { nextTick } from 'vue'
import feather from 'feather-icons'
2023-05-25 18:14:13 +03:00
import defaultImgPlaceholder from "../assets/default_model.png"
const bUrl = import.meta.env.VITE_GPT4ALL_API_BASEURL
2023-05-11 15:09:35 +02:00
export default {
props: {
title: String,
icon: String,
path: String,
owner: String,
2023-05-21 22:46:02 +02:00
owner_link: String,
license: String,
2023-05-11 15:09:35 +02:00
description: String,
isInstalled: Boolean,
2023-05-11 21:36:52 +02:00
onInstall: Function,
onUninstall: Function,
2023-05-11 22:27:23 +02:00
onSelected: Function,
2023-06-08 17:58:02 +03:00
onCopy: Function,
selected: Boolean,
2023-05-30 00:37:09 +02:00
model: Object,
model_type: String
2023-05-11 21:36:52 +02:00
},
data() {
return {
2023-05-14 13:33:45 +02:00
progress: 0,
2023-05-11 21:36:52 +02:00
installing: false,
2023-05-24 17:44:28 +03:00
uninstalling: false,
2023-05-27 15:52:50 +03:00
failedToLoad: false,
fileSize: '',
linkNotValid:false,
2023-05-11 21:36:52 +02:00
};
2023-05-11 15:09:35 +02:00
},
2023-05-27 15:52:50 +03:00
async mounted() {
this.fileSize = await this.getFileSize(this.model.path)
//console.log('model path', this.model.path)
2023-05-19 17:33:31 +03:00
nextTick(() => {
feather.replace()
})
},
2023-05-11 15:09:35 +02:00
methods: {
2023-05-29 13:38:02 +03:00
computedFileSize(size){
return filesize(size)
},
2023-05-27 15:52:50 +03:00
async getFileSize(url) {
2023-06-07 17:16:22 +03:00
//console.log(this.model_type);
2023-05-30 00:37:09 +02:00
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"])
}
if (this.model.filesize) {
return this.computedFileSize(this.model.filesize)
}
return 'Could not be determined'
2023-05-27 15:52:50 +03:00
}
if (this.model.filesize) {
2023-05-30 00:37:09 +02:00
2023-05-29 13:38:02 +03:00
return this.computedFileSize(this.model.filesize)
2023-05-27 15:52:50 +03:00
}
return 'Could not be determined'
2023-05-30 00:37:09 +02:00
// Example response
// {
// date: 'Tue, 03 Apr 2018 14:29:32 GMT',
// 'content-type': 'application/javascript; charset=utf-8',
// 'content-length': '9068',
// connection: 'close',
// 'last-modified': 'Wed, 28 Feb 2018 04:16:30 GMT',
// etag: '"5a962d1e-236c"',
// expires: 'Sun, 24 Mar 2019 14:29:32 GMT',
// 'cache-control': 'public, max-age=30672000',
// 'access-control-allow-origin': '*',
// 'cf-cache-status': 'HIT',
// 'accept-ranges': 'bytes',
// 'strict-transport-security': 'max-age=15780000; includeSubDomains',
// 'expect-ct': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
// server: 'cloudflare',
// 'cf-ray': '405c3a5cba7a68ba-CDG'
// }
} catch (error) {
console.log(error.message,'getFileSize')
this.linkNotValid=true
return 'Could not be determined'
}
2023-05-27 15:52:50 +03:00
}
2023-05-30 00:37:09 +02:00
2023-05-27 15:52:50 +03:00
},
2023-05-25 18:14:13 +03:00
getImgUrl() {
2023-05-25 21:12:39 +03:00
if (this.icon === '/images/default_model.png') {
2023-05-25 18:14:13 +03:00
return defaultImgPlaceholder
}
2023-05-25 21:12:39 +03:00
2023-05-25 18:14:13 +03:00
return this.icon
},
defaultImg(event) {
event.target.src = defaultImgPlaceholder
},
2023-05-11 15:09:35 +02:00
toggleInstall() {
2023-05-11 21:36:52 +02:00
if (this.isInstalled) {
this.uninstalling = true;
// Simulate uninstallation delay (replace this with your WebSocket logic)
this.onUninstall(this);
} else {
this.installing = true;
this.onInstall(this);
}
2023-05-10 23:33:08 +02:00
},
toggleSelected() {
2023-05-19 17:33:31 +03:00
this.onSelected(this)
},
2023-06-08 17:58:02 +03:00
toggleCopy() {
this.onCopy(this)
},
2023-05-11 15:09:35 +02:00
handleSelection() {
2023-05-11 21:36:52 +02:00
if (this.isInstalled && !this.selected) {
2023-05-14 00:24:26 +02:00
this.onSelected(this);
2023-05-11 15:09:35 +02:00
}
2023-06-08 17:58:02 +03:00
},
copyContentToClipboard() {
console.log('asdasdas')
this.$emit('copy', 'this.message.content')
},
2023-05-27 15:52:50 +03:00
},
watch:{
linkNotValid(){
nextTick(() => {
feather.replace()
})
}
2023-05-11 15:09:35 +02:00
}
};
</script>