1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-03-01 03:24:14 +08:00

fix: Optimized ollama model status display (#7899)

This commit is contained in:
ssongliu 2025-02-18 17:06:20 +08:00 committed by GitHub
parent 96eefab36f
commit 33e5c9230f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 29 additions and 9 deletions

View File

@ -3,13 +3,14 @@ package service
import (
"context"
"fmt"
"github.com/1Panel-dev/1Panel/backend/utils/common"
"io"
"os"
"os/exec"
"path"
"strings"
"github.com/1Panel-dev/1Panel/backend/utils/common"
"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/model"
@ -152,10 +153,12 @@ func (u *AIToolService) Delete(req dto.ForceDelete) error {
return err
}
for _, item := range ollamaList {
if item.Status != constant.StatusDeleted {
stdout, err := cmd.Execf("docker exec %s ollama rm %s", containerName, item.Name)
if err != nil && !req.ForceDelete {
return fmt.Errorf("handle ollama rm %s failed, stdout: %s, err: %v", item.Name, stdout, err)
}
}
_ = aiRepo.Delete(commonRepo.WithByID(item.ID))
logItem := path.Join(global.CONF.System.DataDir, "log", "AITools", item.Name)
_ = os.Remove(logItem)

View File

@ -7,6 +7,7 @@ const (
StatusSuccess = "Success"
StatusFailed = "Failed"
StatusDeleted = "Deleted"
StatusCanceled = "Canceled"
StatusUploading = "Uploading"
StatusEnable = "Enable"
StatusDisable = "Disable"

View File

@ -87,6 +87,7 @@ func Init() {
handleUserInfo(global.CONF.System.ChangeUserInfo, settingRepo)
handleCronjobStatus()
handleOllamaModelStatus()
handleSnapStatus()
loadLocalDir()
initDir()
@ -150,6 +151,11 @@ func handleSnapStatus() {
}
}
func handleOllamaModelStatus() {
message := "the task was interrupted due to the restart of the 1panel service"
_ = global.DB.Model(&model.OllamaModel{}).Where("status = ?", constant.StatusWaiting).Updates(map[string]interface{}{"status": constant.StatusCanceled, "message": message}).Error
}
func handleCronjobStatus() {
var jobRecords []model.JobRecords
_ = global.DB.Where("status = ?", constant.StatusWaiting).Find(&jobRecords).Error

View File

@ -178,7 +178,7 @@ const getContent = async (pre: boolean) => {
.replace(/\\u(\w{4})/g, function (match, grp) {
return String.fromCharCode(parseInt(grp, 16));
})
.replace(/\x1b\[[0-9;]*[A-Za-z?](?!\d)/g, ''),
.replace(/\x1B\[[0-?9;]*[mKhlGA]/g, ''),
);
const newLogs = res.data.lines;
if (newLogs.length === readReq.pageSize && readReq.page < res.data.total) {

View File

@ -79,7 +79,7 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
await createOllamaModel(itemName);
drawerVisible.value = false;
emit('search');
emit('log', itemName);
emit('log', { logFileExist: true, name: itemName, from: 'local' });
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
});
};

View File

@ -37,7 +37,7 @@
<el-button @click="handleClose()" :disabled="loading">
{{ $t('commons.button.cancel') }}
</el-button>
<el-button type="primary" @click="onConfirm" :disabled="loading">
<el-button type="primary" @click="onConfirm" :disabled="loading || checkedItems.length === 0">
{{ $t('commons.button.confirm') }}
</el-button>
</span>

View File

@ -20,6 +20,13 @@
ref="appStatusRef"
></AppStatus>
</template>
<template #prompt>
<el-alert type="info" :closable="false">
<template #title>
<span>{{ $t('runtime.systemRestartHelper') }}</span>
</template>
</el-alert>
</template>
<template #toolbar v-if="modelInfo.isExist">
<div class="flex justify-between gap-2 flex-wrap sm:flex-row">
<div class="flex flex-wrap gap-3">
@ -84,6 +91,9 @@
<el-tag v-if="row.status === 'Deleted'" type="info">
{{ $t('database.isDelete') }}
</el-tag>
<el-tag v-if="row.status === 'Cancel'" type="danger">
{{ $t('commons.status.systemrestart') }}
</el-tag>
<el-tag v-if="row.status === 'Failed'" type="danger">
{{ $t('commons.status.failed') }}
</el-tag>
@ -379,7 +389,7 @@ const onDelete = async (row: AI.OllamaModelInfo) => {
});
};
const onLoadLog = (row: AI.OllamaModelInfo) => {
const onLoadLog = (row: any) => {
if (row.from === 'remote') {
MsgInfo(i18n.global.t('ai_tools.model.from_remote'));
return;
@ -407,7 +417,7 @@ const buttons = [
onDelete(row);
},
disabled: (row: any) => {
return row.status !== 'Success';
return row.status !== 'Success' && row.status !== 'Deleted';
},
},
];