add 增加记录llamafactory是否启动的状态

This commit is contained in:
zeyu xu
2024-03-23 12:20:56 +08:00
parent 56b62cff2a
commit f61cbe9780
8 changed files with 112 additions and 22 deletions

View File

@@ -1,4 +1,5 @@
using AntSK.Domain.Domain.Service;
using AntSK.Domain.Domain.Model.Constant;
using AntSK.Domain.Domain.Service;
using AntSK.Domain.Repositories;
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
using Microsoft.AspNetCore.Builder;
@@ -53,7 +54,26 @@ namespace AntSK.Domain.Common.DependencyInjection
return app;
}
public static WebApplication InitDbData(this WebApplication app)
{
using (var scope = app.Services.CreateScope())
{
// 初始化字典
var _dic_Repository = scope.ServiceProvider.GetRequiredService<IDics_Repositories>();
var llamafactoryStart = _dic_Repository.GetFirst(p => p.Type == LLamaFactoryConstantcs.LLamaFactorDic && p.Key == LLamaFactoryConstantcs.IsStartKey);
if (llamafactoryStart==null)
{
llamafactoryStart = new Dics();
llamafactoryStart.Id=Guid.NewGuid().ToString();
llamafactoryStart.Type = LLamaFactoryConstantcs.LLamaFactorDic;
llamafactoryStart.Key = LLamaFactoryConstantcs.IsStartKey;
llamafactoryStart.Value = "false";
_dic_Repository.Insert(llamafactoryStart);
}
}
return app;
}
/// <summary>
/// 加载数据库的插件
/// </summary>

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntSK.Domain.Domain.Model.Constant
{
public class LLamaFactoryConstantcs
{
public const string LLamaFactorDic = "llamafactory";
public const string IsStartKey = "isstart";
}
}

View File

@@ -0,0 +1,16 @@
using AntSK.Domain.Domain.Model.Enum;
using SqlSugar;
using System.ComponentModel.DataAnnotations;
namespace AntSK.Domain.Repositories
{
[SugarTable("Dics")]
public partial class Dics
{
[SugarColumn(IsPrimaryKey = true)]
public string Id { get; set; }
public string Type { get; set; }
public string Key { get; set; }
public string Value { get; set; }
}
}

View File

@@ -0,0 +1,11 @@

using AntSK.Domain.Common.DependencyInjection;
using AntSK.Domain.Repositories.Base;
namespace AntSK.Domain.Repositories
{
[ServiceDescription(typeof(IDics_Repositories), ServiceLifetime.Scoped)]
public class Dics_Repositories : Repository<Dics>, IDics_Repositories
{
}
}

View File

@@ -0,0 +1,8 @@
using AntSK.Domain.Repositories.Base;
namespace AntSK.Domain.Repositories
{
public interface IDics_Repositories : IRepository<Dics>
{
}
}

View File

@@ -111,14 +111,19 @@
</InputGroup>
</FormItem>
<FormItem Label="请求地址" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
<Input Placeholder="http://localhost:8080/" @bind-Value="@context.EndPoint" />
<Input Placeholder="http://localhost:8080/" @bind-Value="@context.EndPoint" />
</FormItem>
<FormItem Label="llama factory服务" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
<InputGroup>
<Button Type="primary" OnClick="HandleStartService" Disabled="@(llamaFactoryIsStart)">启动</Button>
<Button OnClick="HandleStopService" Disabled="@(!llamaFactoryIsStart)">停止</Button>
@if (!llamaFactoryIsStart)
{
<Button Type="primary" OnClick="HandleStartService" Disabled="@(llamaFactoryIsStart)">启动</Button>
}
else
{
<Button OnClick="HandleStopService" Disabled="@(!llamaFactoryIsStart)">停止</Button>
}
</InputGroup>
</FormItem>
}
@if (context.AIType == AIType.Mock)
@@ -156,7 +161,7 @@
</Modal>
<Modal Visible="_logModalVisible" Footer="null" Closable Title="日志输出" OnCancel="OnCancelLog" DestroyOnClose Width="1000">
<BlazorTerminal @ref="blazorTerminal" Style="height:600px;" ></BlazorTerminal>
<BlazorTerminal @ref="blazorTerminal" Style="height:600px;"></BlazorTerminal>
</Modal>

View File

@@ -1,6 +1,7 @@
using AntDesign;
using AntDesign.ProLayout;
using AntSK.Domain.Domain.Interface;
using AntSK.Domain.Domain.Model.Constant;
using AntSK.Domain.Domain.Model.Enum;
using AntSK.Domain.Domain.Service;
using AntSK.Domain.Options;
@@ -26,31 +27,34 @@ namespace AntSK.Pages.Setting.AIModel
[Inject] protected ILLamaFactoryService _ILLamaFactoryService { get; set; }
[Inject] protected IDics_Repositories _IDics_Repositories { get; set; }
private AIModels _aiModel = new AIModels();
//llamasharp download
private string _downloadUrl;
private bool _downloadModalVisible;
private bool _logModalVisible;
private bool _isComplete;
private double _downloadProgress;
private bool _downloadFinished;
private bool _downloadStarted;
IDownload _download;
private IDownload _download;
private Modal _modal;
private string[] _modelFiles;
string[] _modelFiles;
IEnumerable<string> _menuKeys;
//menu
private IEnumerable<string> _menuKeys;
private List<MenuDataItem> menuList = new List<MenuDataItem>();
//llamafactory
private List<LLamaModel> modelList=new List<LLamaModel>();
bool llamaFactoryIsStart = false;
private bool llamaFactoryIsStart = false;
private Dics llamaFactoryDic= new Dics();
//日志输出
private BlazorTerminal blazorTerminal = new BlazorTerminal();
private TerminalParagraph para;
private bool _logModalVisible;
protected override async Task OnInitializedAsync()
{
@@ -71,8 +75,13 @@ namespace AntSK.Pages.Setting.AIModel
_downloadUrl = $"https://hf-mirror.com{ModelPath.Replace("---","/")}";
}
modelList = _ILLamaFactoryService.GetLLamaFactoryModels();
llamaFactoryDic = await _IDics_Repositories.GetFirstAsync(p => p.Type == LLamaFactoryConstantcs.LLamaFactorDic && p.Key == LLamaFactoryConstantcs.IsStartKey);
if (llamaFactoryDic != null)
{
llamaFactoryIsStart= llamaFactoryDic.Value== "false" ? false:true;
}
}
catch
{
@@ -211,9 +220,20 @@ namespace AntSK.Pages.Setting.AIModel
}
llamaFactoryIsStart = true;
_logModalVisible = true;
llamaFactoryDic.Value = "true";
_IDics_Repositories.Update(llamaFactoryDic);
_ILLamaFactoryService.LogMessageReceived += CmdLogHandler;
_ILLamaFactoryService.StartLLamaFactory(_aiModel.ModelName, "default");
}
private void HandleStopService()
{
llamaFactoryIsStart = false;
llamaFactoryDic.Value = "false";
_IDics_Repositories.Update(llamaFactoryDic);
_ILLamaFactoryService.KillProcess();
}
private async Task CmdLogHandler(string message)
{
await InvokeAsync(() =>
@@ -225,12 +245,7 @@ namespace AntSK.Pages.Setting.AIModel
/// <summary>
/// 停止服务
/// </summary>
private void HandleStopService()
{
llamaFactoryIsStart = false;
_ILLamaFactoryService.KillProcess();
}
private void OnCancelLog() {
_logModalVisible = false;
}

View File

@@ -91,6 +91,7 @@ app.UseStaticFiles();
//扩展初始化实现
app.CodeFirst();
app.LoadFun();
app.InitDbData();
app.UseRouting();