Browse Source

change download model

master
godo 7 months ago
parent
commit
77b19beab2
  1. 7
      frontend/src/assets/list.scss
  2. 50
      frontend/src/components/ai/aimodel.vue
  3. 95
      frontend/src/stores/model.ts
  4. 2
      godo/model/data.go

7
frontend/src/assets/list.scss

@ -54,7 +54,12 @@ $shadow-color: rgba(0, 0, 0, 0.1); // 阴影颜色
margin-left: 24px;
margin-right: 24px; // 增加外边距
}
.ml-10{
margin-left: 10px;
}
.mr-10{
margin-right: 10px;
}
.font-weight-bold {
font-weight: bold;
font-size: 18px; // 增大字体大小

50
frontend/src/components/ai/aimodel.vue

@ -18,10 +18,6 @@ const labelId = ref(0);
const searchKey = ref("");
const currentCate = ref("all");
const help_label = ref();
const help_adddown = ref();
const help_addlabel = ref();
const help_showdown = ref();
const showDetail = ref(false);
const detailModel = ref("")
let downloadAbort:any = {};
@ -40,15 +36,17 @@ function downAddUpdate(val:any) {
}
async function downLabel(modelData:any, labelData:any) {
labelData = toRaw(labelData);
modelData = toRaw(modelData);
//console.log(modelData, labelData)
const saveData = {
model: modelData.model,
label: labelData.name,
action: labelData.action,
engine: labelData.engine,
url: modelData.url ?? [],
from: modelData.from ? modelData.from : labelData.from,
engine: modelData.info.engine,
url: modelData.info.url ?? [],
from: modelData.info.from,
type: modelData.type ?? "",
file_name: modelData.file_name ?? "",
file_name: modelData.info.file_name ?? "",
//options: modelData.options ?? {},
params: modelData.params ?? {},
info: modelData.info ?? {},
@ -66,7 +64,7 @@ async function saveBox(modelData: any) {
async function download(saveData:any) {
saveData = toRaw(saveData);
saveData.info = toRaw(saveData.info);
saveData.url = toRaw(saveData.url);
//saveData.url = toRaw(saveData.url);
saveData.params = toRaw(saveData.params);
downAdd.value = false;
downLeft.value = true;
@ -76,7 +74,7 @@ async function download(saveData:any) {
return;
}
//console.log(saveData);
const downUrl = config.modelDownApi;
const downUrl = config.apiUrl + "/ai/download";
try {
const completion = await fetch(downUrl, {
@ -126,6 +124,7 @@ async function handleDown(modelData:any, completion:any) {
const rawjson = new TextDecoder().decode(value);
//console.log(rawjson);
const msg = modelStore.parseMsg(rawjson);
//console.log(msg)
if(msg.message && msg.code) {
notifyError(msg.message);
break;
@ -134,9 +133,14 @@ async function handleDown(modelData:any, completion:any) {
continue;
}
modelData.status = msg.status;
if (msg.total && msg.completed && msg.total > 0) {
if(msg.total == msg.completed){
msg.status = "success"
}else{
modelData.isLoading = 1;
modelData.progress = Math.ceil((msg.completed / msg.total) * 100);
}
} else {
modelData.progress = 0;
}
@ -165,13 +169,9 @@ async function deleteModel(modelData: any) {
//return
const postData = {
method: "POST",
body: JSON.stringify({
url: modelData.url,
model: modelData.model,
engine: modelData.engine,
}),
body: JSON.stringify(modelData.info),
};
const delUrl = config.modelDeleteApi;
const delUrl = config.apiUrl + "/ai/delete";
const completion = await fetch(delUrl, postData);
if (completion.status === 404) {
notifyError(completion.statusText);
@ -246,7 +246,7 @@ function showModel(model: string) {
<div class="card-header">
<span>{{ val.model }}</span>
</div>
<div class="text item" v-if="val.progress && val.progress > 0">
<div class="text item" v-if="val.progress && val.isLoading > 0">
<el-progress
:text-inside="true"
:stroke-width="15"
@ -254,14 +254,14 @@ function showModel(model: string) {
/>
</div>
<div class="drawer-model-actions" style="margin-top: 10px">
<el-tag size="small">{{ val.status }}</el-tag>
<el-tag size="small" v-if="val.isLoading > 0">{{ val.status }}</el-tag>
<el-icon :size="18" color="red" @click="cancelDownload(val.model)">
<Delete />
</el-icon>
<el-icon
:size="18"
color="blue"
v-if="val.progress > 0 && val.isLoading < 1 && val.status != 'success'"
v-if="val.isLoading < 1 && val.status != 'success'"
@click="download(toRaw(val))"
>
<VideoPlay />
@ -310,15 +310,19 @@ function showModel(model: string) {
@click.stop="downLeft = !downLeft"
icon="Menu"
circle
ref="help_showdown"
/>
<el-button @click.stop="downAdd = true" icon="Plus" circle ref="help_adddown" />
<el-button @click.stop="downAdd = true" icon="Plus" circle />
<el-button
@click.stop="labelShow(0)"
icon="CollectionTag"
circle
ref="help_addlabel"
/>
<el-button
@click.stop="modelStore.refreshOllama"
icon="RefreshRight"
circle
/>
</template>
<template #extra>
<el-space class="mr-10">
@ -334,7 +338,7 @@ function showModel(model: string) {
</el-page-header>
<div class="flex-fill ml-10 mr-10">
<el-tabs v-model="currentCate" @tab-click="showCate" ref="help_label">
<el-tabs v-model="currentCate" @tab-click="showCate">
<el-tab-pane :label="t('model.all')" name="all" />
<el-tab-pane
:label="t('model.' + item)"

95
frontend/src/stores/model.ts

@ -5,8 +5,8 @@ import { aiLabels } from "./labels/index.ts"
const modelEngines = [
{
name: "ollama",
cpp:"llama.cpp",
needQuant : true
cpp: "llama.cpp",
needQuant: true
},
{
name: "sd",
@ -46,8 +46,8 @@ export const useModelStore = defineStore('modelStore', () => {
const modelList: any = ref([])
const downList: any = ref([])
const chatConfig: any = ref({
chat : {
key:"chat",
chat: {
key: "chat",
contextLength: 10,
num_keep: 5, //保留多少个最有可能的预测结果。这与top_k一起使用,决定模型在生成下一个词时考虑的词汇范围。
num_predict: 3, //生成多少个预测结果
@ -56,23 +56,23 @@ export const useModelStore = defineStore('modelStore', () => {
temperature: 0.7, //影响生成的随机性。较低的温度产生更保守的输出,较高的温度产生更随机的输出。
},
translation: {
key:"translation",
key: "translation",
num_keep: 5,
num_predict: 1,
top_k: 40,
top_p: 0.95,
temperature: 0.2,
},
creation:{
key:"creation",
creation: {
key: "creation",
num_keep: 3,
num_predict: 1,
top_k: 40,
top_p: 0.95,
temperature: 0.2,
},
knowledge:{
key:"knowledge",
knowledge: {
key: "knowledge",
contextLength: 10,
num_keep: 5,
num_predict: 1,
@ -80,8 +80,8 @@ export const useModelStore = defineStore('modelStore', () => {
top_p: 0.95,
temperature: 0.2,
},
spoken:{
key:"spoken",
spoken: {
key: "spoken",
contextLength: 10,
num_keep: 5,
num_predict: 1,
@ -89,7 +89,7 @@ export const useModelStore = defineStore('modelStore', () => {
top_p: 0.95,
temperature: 0.2,
}
})
})
async function getLabelCate(cateName: string) {
const list = await getLabelList()
@ -145,31 +145,45 @@ export const useModelStore = defineStore('modelStore', () => {
downList.value[index].isLoading = 0
})
}
async function setCurrentModel(action:string, model:string) {
async function setCurrentModel(action: string, model: string) {
await db.modify("modelslist", "action", action, { isdef: 0 })
return await db.modify("modelslist", "model", model, { isdef: 1 })
}
function getCurrentModelList(modelList: any, action:string){
function getCurrentModelList(modelList: any, action: string) {
return modelList.filter((d: any) => d.action == action)
}
async function addDownList(data: any) {
console.log(data);
//modelList.value.unshift(data)
// const has = modelList.value.find((d: any) => d.model == data.model)
// //console.log(has)
// if (!has) {
// //data = toRaw(data)
// const save = await getBaseModelInfo(data.model)
// //console.log(save)
// if (save) {
// modelList.value.unshift(save)
// return await db.addOne("modelslist", save)
// } else {
// console.log("not get model" + data.model)
// }
modelList.value.unshift(data)
const has = modelList.value.find((d: any) => d.model == data.model)
//console.log(has)
if (!has) {
//data = toRaw(data)
const save = await getBaseModelInfo(data.model)
//console.log(save)
if (save) {
//modelList.value.unshift(save)
return await db.addOne("modelslist", save)
} else {
console.log("not get model" + data.model)
}
}
}
async function getBaseModelInfo(model: string) {
const baseModel = await db.get("modelslist", { model: model })
if (baseModel) {
return baseModel
}
const modelInfo = await db.get("modelslist", { model: model.split(":")[0] })
if (modelInfo) {
return modelInfo
}
return null
}
async function refreshOllama() {
// }
}
async function deleteModelList(data: any) {
//console.log(data)
@ -221,13 +235,13 @@ export const useModelStore = defineStore('modelStore', () => {
}
}
}
function parseJson(str: string) {
function parseJson(str: string): any {
try {
return JSON.parse(str);
} catch (e) {
return undefined;
}
}
}
function parseMsg(str: string) {
const nres = { status: "" }
try {
@ -238,20 +252,24 @@ export const useModelStore = defineStore('modelStore', () => {
const raw: any = str.split("\n")
if (raw.length < 1) return nres
// deno-lint-ignore no-explicit-any
const rt: any = raw.filter((d: any) => d.trim() != "")
const rt: string[] = raw.filter((d: string) => d.trim() !== "");
//console.log(rt)
if (rt.length > 0) {
let msg = parseJson(rt.pop())
let res: any[] = [];
rt.forEach((d: string) => {
const msg = parseJson(d);
if (msg) {
return msg
} else {
msg = parseJson(rt.pop())
return msg
res.push(msg);
}
//return JSON.parse(rt.pop())
});
if (res.length > 0) {
return res[res.length - 1]
} else {
return nres
}
} else {
return nres;
}
} catch (error) {
console.log(error);
return nres
@ -288,7 +306,8 @@ export const useModelStore = defineStore('modelStore', () => {
initModel,
setCurrentModel,
getCurrentModelList,
parseMsg
parseMsg,
refreshOllama
}
}, {

2
godo/model/data.go

@ -19,7 +19,7 @@ func GetConfigFile() (string, error) {
if !libs.PathExists(modelDir) {
os.MkdirAll(modelDir, 0755)
}
configFile := filepath.Join(modelDir, "model.json")
configFile := filepath.Join(modelDir, "aimodel.json")
if !libs.PathExists(configFile) {
// 如果文件不存在,则创建一个空的配置文件
err := os.WriteFile(configFile, []byte("[]"), 0644)

Loading…
Cancel
Save