This commit is contained in:
zyxucp
2024-09-29 10:52:27 +08:00
parent 5e3ff74eaa
commit 0df8c74ec2
13 changed files with 1 additions and 569 deletions

View File

@@ -25,8 +25,6 @@ namespace AntSK.Domain.Domain.Model.Enum
BgeEmbedding = 7,
[Display(Name = "Bge Rerank")]
BgeRerank = 8,
[Display(Name = "StableDiffusion")]
StableDiffusion = 9,
[Display(Name = "Ollama")]
Ollama = 10,
@@ -44,7 +42,6 @@ namespace AntSK.Domain.Domain.Model.Enum
{
Chat = 1,
Embedding = 2,
Image=3,
Rerank=4
}
}

View File

@@ -61,18 +61,6 @@
<span>更发散</span>
</FormItem>
}
else
{
<FormItem Label="图片模型" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
<Select DataSource="@_imageList"
@bind-Value="@context.ImageModelID"
ValueProperty="c=>c.Id"
LabelProperty="c=>'【'+c.AIType.ToString()+'】'+c.ModelDescription">
</Select>
<Button Type="@ButtonType.Link" OnClick="NavigateModelList">去创建</Button>
</FormItem>
}
@if (@context.Type == AppType.chat.ToString())
{
<FormItem Label="API插件列表" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">

View File

@@ -48,7 +48,6 @@ namespace AntSK.Pages.AppPage
private List<AIModels> _chatList;
private List<AIModels> _embedingList;
private List<AIModels> _rerankList;
private List<AIModels> _imageList;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
@@ -58,7 +57,7 @@ namespace AntSK.Pages.AppPage
_chatList = models.Where(p => p.AIModelType == AIModelType.Chat).ToList();
_embedingList = models.Where(p => p.AIModelType == AIModelType.Embedding).ToList();
_rerankList = models.Where(p => p.AIModelType == AIModelType.Rerank).ToList();
_imageList = models.Where(p => p.AIModelType == AIModelType.Image).ToList();
_functionService.SearchMarkedMethods();
foreach (var func in _functionService.Functions)

View File

@@ -29,7 +29,6 @@
<Radio RadioButton Value="@(AIModelType.Chat)">会话模型</Radio>
<Radio RadioButton Value="@(AIModelType.Embedding)">向量模型</Radio>
<Radio RadioButton Value="@(AIModelType.Rerank)">Rerank重排模型</Radio>
<Radio RadioButton Value="@(AIModelType.Image)">图片模型</Radio>
</RadioGroup>
</FormItem>
@@ -56,10 +55,6 @@
{
<Radio RadioButton Value="@(AIType.BgeRerank)">BgeRerank</Radio>
}
else if (context.AIModelType == AIModelType.Image)
{
<Radio RadioButton Value="@(AIType.StableDiffusion)">StableDiffusion</Radio>
}
</RadioGroup>
</FormItem>
@@ -119,15 +114,6 @@
<Input Placeholder="请输入模型名称" @bind-Value="@context.ModelName" AutoComplete="false" />
</FormItem>
}
@if (context.AIType == AIType.StableDiffusion)
{
<FormItem Label="模型路径" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
<InputGroup>
<AutoComplete Options="_modelFiles" Placeholder="请输入模型路径" @bind-Value="@context.ModelName" />
<Button OnClick="()=>_downloadModalVisible=true" Style="margin-top:5px">从Haggingface下载</Button>
</InputGroup>
</FormItem>
}
@if (context.AIType == AIType.LLamaFactory)
{
<FormItem Label="模型名称" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">

View File

@@ -21,8 +21,6 @@ namespace AntSK.Pages.Setting.AIModel
{
[Parameter]
public string ModelId { get; set; }
[Parameter]
public string ModelPath { get; set; }
[Inject] protected IAIModels_Repositories _aimodels_Repositories { get; set; }
[Inject] protected MessageService? Message { get; set; }
[Inject] public HttpClient HttpClient { get; set; }
@@ -94,27 +92,6 @@ namespace AntSK.Pages.Setting.AIModel
{
llamaFactoryIsStart = llamaFactoryDic.Value == "false" ? false : true;
}
//目前只支持gguf的 所以筛选一下
_modelFiles = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), FileDirOption.DirectoryPath)).Where(p => p.Contains(".gguf") || p.Contains(".ckpt") || p.Contains(".safetensors")).ToArray();
if (!string.IsNullOrEmpty(ModelPath))
{
string extension = Path.GetExtension(ModelPath);
switch (extension)
{
case ".safetensors":
case ".ckpt":
_aiModel.AIType = AIType.StableDiffusion;
break;
}
//下载页跳入
_downloadModalVisible = true;
_downloadUrl = $"https://hf-mirror.com{ModelPath.Replace("---", "/")}";
}
}
catch (System.Exception ex)
{
@@ -461,9 +438,6 @@ namespace AntSK.Pages.Setting.AIModel
_aiModel.EndPoint = "http://localhost:11434/";
_aiModel.AIModelType = AIModelType.Embedding;
break;
case AIType.StableDiffusion:
_aiModel.AIModelType = AIModelType.Image;
break;
case AIType.Mock:
_aiModel.AIModelType = AIModelType.Chat;
break;
@@ -494,9 +468,6 @@ namespace AntSK.Pages.Setting.AIModel
case AIModelType.Rerank:
_aiModel.AIType = AIType.BgeRerank;
break;
case AIModelType.Image:
_aiModel.AIType = AIType.StableDiffusion;
break;
}
}
}

View File

@@ -1,71 +0,0 @@
@namespace AntSK.Pages.Setting.AIModel
@page "/modelmanager/modeldown"
@using AntSK.Services.Auth
@inherits AuthComponentBase
@using Microsoft.AspNetCore.Authorization
@using AntSK.Domain.Domain.Model.hfmirror
@attribute [Authorize(Roles = "AntSKAdmin")]
<div>
<PageContainer Title="模型列表">
<Content>
<RadioGroup @bind-Value="@_modelType" OnChange="OnModelTypeChange" TValue="string" ButtonStyle="@RadioButtonStyle.Solid">
<Radio RadioButton Value="@("ckpt")">StableDiffusion2(ckpt)</Radio>
<Radio RadioButton Value="@("safetensors")">StableDiffusion(safetensors)</Radio>
</RadioGroup>
<div style="text-align: center;">
<Search Placeholder="输入回车"
EnterButton="@("搜索")"
Size="large"
Style="max-width: 522px; width: 100%;"
OnSearch="Search" />
</div>
</Content>
<ChildContent>
<div class="filterCardList">
<Spin Tip="加载中..." Spinning="@(loaddding)">
<AntList TItem="HfModels"
Grid="LayoutModel._listGridType"
DataSource="_modelList">
<ListItem NoFlex>
<Card Hoverable
BodyStyle="padding-bottom: 20px;"
Actions="new[] {
down(()=> Down(context.Id))
}">
<CardMeta>
<TitleTemplate>
@context.Id
</TitleTemplate>
<AvatarTemplate>
<Avatar Size="small" Src="@context.AuthorData.AvatarUrl" />
</AvatarTemplate>
</CardMeta>
<div class="cardItemContent">
<div class="cardInfo">
<div>
<p>Downloads</p>
<p>@context.Downloads.ToString("0,0")</p>
</div>
<div>
<p>Likes</p>
<p>@context.Likes.ToString("0,0")</p>
</div>
</div>
</div>
</Card>
</ListItem>
</AntList>
</Spin>
</div>
</ChildContent>
</PageContainer>
</div>
@code
{
RenderFragment down(Action clickAction) =>@<a key="down" @onclick="@clickAction">下载</a>;
}

View File

@@ -1,82 +0,0 @@
using AntSK.Domain.Domain.Model.hfmirror;
using AntSK.Domain.Utils;
using AntSK.Models;
using Microsoft.AspNetCore.Components;
using Newtonsoft.Json;
using RestSharp;
namespace AntSK.Pages.Setting.AIModel
{
public partial class ModelDown
{
private readonly ListFormModel _model = new ListFormModel();
private readonly IList<string> _selectCategories = new List<string>();
private List<HfModels> _modelList = new List<HfModels>();
private string _modelType="gguf";
private bool loaddding = false;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
InitData("");
}
private async Task InitData(string searchKey)
{
loaddding = true;
if (_modelType.Contains("safetensors"))
{
_modelList.Clear();
var param = searchKey.ConvertToString().Split(" ");
string[] lines = File.ReadAllLines(Path.Combine(AppContext.BaseDirectory, "StableDiffusionModelList.txt"));
foreach (string line in lines)
{
string urlBase = $"https://hf-mirror.com/models-json?sort=trending&search={line}";
if (param.Count() > 0)
{
urlBase += "+" + string.Join("+", param);
}
RestClient client = new RestClient();
RestRequest request = new RestRequest(urlBase, Method.Get);
var response = await client.ExecuteAsync(request);
var model = JsonConvert.DeserializeObject<HfModel>(response.Content);
_modelList.AddRange(model.models);
}
}
else
{
var param = searchKey.ConvertToString().Split(" ");
string urlBase = $"https://hf-mirror.com/models-json?sort=trending&search={_modelType}";
if (param.Count() > 0)
{
urlBase += "+" + string.Join("+", param);
}
RestClient client = new RestClient();
RestRequest request = new RestRequest(urlBase, Method.Get);
var response = await client.ExecuteAsync(request);
var model = JsonConvert.DeserializeObject<HfModel>(response.Content);
_modelList = model.models;
}
loaddding = false;
InvokeAsync(StateHasChanged);
}
private async Task Search(string searchKey)
{
InitData(searchKey);
}
private void Down(string modelPath)
{
NavigationManager.NavigateTo($"/modelmanager/modeldown/detail/{modelPath}");
}
private void OnModelTypeChange(string value)
{
InitData("");
}
}
}

View File

@@ -1,46 +0,0 @@
/* stylelint-disable at-rule-empty-line-before,at-rule-name-space-after,at-rule-no-unknown */
/* stylelint-disable no-duplicate-selectors */
/* stylelint-disable */
/* stylelint-disable declaration-bang-space-before,no-duplicate-selectors,string-no-newline */
.filterCardList .ant-card-meta-content {
margin-top: 0;
}
.filterCardList .ant-card-meta-avatar {
font-size: 0;
}
.filterCardList .ant-list .ant-list-item-content-single {
max-width: 100%;
}
.filterCardList .cardInfo {
margin-top: 16px;
margin-left: 40px;
zoom: 1;
}
.filterCardList .cardInfo::before,
.filterCardList .cardInfo::after {
display: table;
content: ' ';
}
.filterCardList .cardInfo::after {
clear: both;
height: 0;
font-size: 0;
visibility: hidden;
}
.filterCardList .cardInfo > div {
position: relative;
float: left;
width: 50%;
text-align: left;
}
.filterCardList .cardInfo > div p {
margin: 0;
font-size: 24px;
line-height: 32px;
}
.filterCardList .cardInfo > div p:first-child {
margin-bottom: 4px;
color: rgba(0, 0, 0, 0.45);
font-size: 12px;
line-height: 20px;
}

View File

@@ -1,55 +0,0 @@
@namespace AntSK.Pages.Setting.AIModel
@page "/modelmanager/modeldown/detail/{ModelName}/{ModelPath}"
@using AntSK.Services.Auth
@inherits AuthComponentBase
@using Microsoft.AspNetCore.Authorization
@using AntSK.Domain.Domain.Model.hfmirror;
using AntSK.Domain.Domain.Model.hfmirror
@attribute [Authorize(Roles = "AntSKAdmin")]
<div>
<PageContainer Title="模型下载">
<ChildContent>
<div class="standardList">
<Card Class="listCard"
Title="模型列表"
Style="margin-top: 24px;"
BodyStyle="padding: 0 32px 40px 32px">
<Extra>
</Extra>
<ChildContent>
<AntList TItem="HfModelDetail"
DataSource="modelList"
ItemLayout="ListItemLayout.Horizontal">
<ListItem Actions="new[] {
down(()=> Down(context.Path))
}" Style="width:100%">
<div class="listContent" style="width:100%">
<div class="listContentItem" style="width:20%">
<b>名称</b>
<p>@context.Name</p>
</div>
<div class="listContentItem" style="width:20%">
<b>文件大小</b>
<p>@context.Size</p>
</div>
<div class="listContentItem" style="width:20%">
<b>更新时间</b>
<p>@context.Time</p>
</div>
</div>
</ListItem>
</AntList>
</ChildContent>
</Card>
</div>
</ChildContent>
</PageContainer>
</div>
@code
{
RenderFragment down(Action clickAction) =>@<a key="down" @onclick="@clickAction">下载</a>;
}

View File

@@ -1,56 +0,0 @@
using AntSK.Domain.Domain.Model.hfmirror;
using DocumentFormat.OpenXml.EMMA;
using DocumentFormat.OpenXml.Spreadsheet;
using HtmlAgilityPack;
using Microsoft.AspNetCore.Components;
using RestSharp;
namespace AntSK.Pages.Setting.AIModel
{
public partial class ModelDownDetail
{
[Parameter]
public string ModelName { get; set; }
[Parameter]
public string ModelPath { get; set; }
List<HfModelDetail> modelList = new List<HfModelDetail>();
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
InitData();
}
private void InitData()
{
string urlBase = $"https://hf-mirror.com/{ModelName}/{ModelPath}/tree/main";
RestClient client = new RestClient();
RestRequest request = new RestRequest(urlBase, Method.Get);
var response = client.Execute(request);
var htmlDocument = new HtmlDocument();
htmlDocument.LoadHtml(response.Content);
foreach (var listItem in htmlDocument.DocumentNode.SelectNodes("//li[contains(@class,'grid')]"))
{
var modelNameNode = listItem.SelectSingleNode(".//span[contains(@class,'truncate')]");
var fileSizeNode = listItem.SelectSingleNode(".//a[contains(@class,'text-[0.8rem]')]");
var downloadNode = listItem.SelectSingleNode(".//a[@title='Download file']");
var timeNode = listItem.SelectSingleNode(".//time");
var modelName = modelNameNode?.InnerText.Trim();
var fileSizeInfo = fileSizeNode?.InnerText.Trim().Split(' ');
var fileSize = fileSizeInfo?.Length > 1 ? fileSizeInfo[fileSizeInfo.Length - 2] : null;
var downloadUrl = downloadNode?.GetAttributeValue("href", null)?.Trim();
var time= timeNode?.InnerText.Trim();
modelList.Add(new HfModelDetail() { Name = modelName, Size = string.Join(" ",fileSizeInfo), Path = downloadUrl,Time=time });
}
}
private void Down(string path)
{
NavigationManager.NavigateTo($"/modelmanager/model/addbypath/{path.Replace("?download=true", "").Replace("/", "---")}");
}
}
}

View File

@@ -1,186 +0,0 @@
/* stylelint-disable at-rule-empty-line-before,at-rule-name-space-after,at-rule-no-unknown */
/* stylelint-disable no-duplicate-selectors */
/* stylelint-disable */
/* stylelint-disable declaration-bang-space-before,no-duplicate-selectors,string-no-newline */
.standardList .ant-card-head {
border-bottom: none;
}
.standardList .ant-card-head-title {
padding: 24px 0;
line-height: 32px;
}
.standardList .ant-card-extra {
padding: 24px 0;
}
.standardList .ant-list-pagination {
margin-top: 24px;
text-align: right;
}
.standardList .ant-avatar-lg {
width: 48px;
height: 48px;
line-height: 48px;
}
.standardList .headerInfo {
position: relative;
text-align: center;
}
.standardList .headerInfo > span {
display: inline-block;
margin-bottom: 4px;
color: rgba(0, 0, 0, 0.45);
font-size: 14px;
line-height: 22px;
}
.standardList .headerInfo > p {
margin: 0;
color: rgba(0, 0, 0, 0.85);
font-size: 24px;
line-height: 32px;
}
.standardList .headerInfo > em {
position: absolute;
top: 0;
right: 0;
width: 1px;
height: 56px;
background-color: #f0f0f0;
}
.standardList .listContent {
font-size: 0;
}
.standardList .listContent .listContentItem {
display: inline-block;
margin-left: 40px;
color: rgba(0, 0, 0, 0.45);
font-size: 14px;
vertical-align: middle;
}
.standardList .listContent .listContentItem > span {
line-height: 20px;
}
.standardList .listContent .listContentItem > p {
margin-top: 4px;
margin-bottom: 0;
line-height: 22px;
}
.standardList .extraContentSearch {
width: 272px;
margin-left: 16px;
}
@media screen and (max-width: 480px) {
.standardList .ant-list-item-content {
display: block;
flex: none;
width: 100%;
}
.standardList .ant-list-item-action {
margin-left: 0;
}
.standardList .listContent {
margin-left: 0;
}
.standardList .listContent > div {
margin-left: 0;
}
.standardList .listCard .ant-card-head-title {
overflow: visible;
}
}
@media screen and (max-width: 576px) {
.standardList .extraContentSearch {
width: 100%;
margin-left: 0;
}
.standardList .headerInfo {
margin-bottom: 16px;
}
.standardList .headerInfo > em {
display: none;
}
}
@media screen and (max-width: 768px) {
.standardList .listContent > div {
display: block;
}
.standardList .listContent > div:last-child {
top: 0;
width: 100%;
}
.listCard .ant-radio-group {
display: block;
margin-bottom: 8px;
}
}
@media screen and (max-width: 992px) and (min-width: 768px) {
.standardList .listContent > div {
display: block;
}
.standardList .listContent > div:last-child {
top: 0;
width: 100%;
}
}
@media screen and (max-width: 1200px) {
.standardList .listContent > div {
margin-left: 24px;
}
.standardList .listContent > div:last-child {
top: 0;
}
}
@media screen and (max-width: 1400px) {
.standardList .listContent {
text-align: right;
}
.standardList .listContent > div:last-child {
top: 0;
}
}
.standardListForm .ant-form-item {
margin-bottom: 12px;
}
.standardListForm .ant-form-item:last-child {
margin-bottom: 32px;
padding-top: 4px;
}
.formResult {
width: 100%;
}
.formResult [class^='title'] {
margin-bottom: 8px;
}

View File

@@ -74,10 +74,6 @@
{
<Tag Color="@PresetColor.GeekBlue.ToString()">BgeRerank</Tag>
}
else if (context.AIType == AIType.StableDiffusion)
{
<Tag Color="@PresetColor.Magenta.ToString()">StableDiffusion</Tag>
}
else if (context.AIType == AIType.Ollama || context.AIType == AIType.OllamaEmbedding)
{
<Tag Color="@PresetColor.Pink.ToString()">Ollama</Tag>
@@ -97,10 +93,6 @@
{
<Tag Color="@PresetColor.Green.ToString()">向量模型</Tag>
}
else if (context.AIModelType == AIModelType.Image)
{
<Tag Color="@PresetColor.Lime.ToString()">图片模型</Tag>
}
else if (context.AIModelType == AIModelType.Rerank)
{
<Tag Color="@PresetColor.GeekBlue.ToString()">Rerank重排模型</Tag>

View File

@@ -45,11 +45,6 @@
"path": "/modelmanager/modellist",
"name": "模型管理",
"key": "modelmanager.modellist"
},
{
"path": "/modelmanager/modeldown",
"name": "作图模型下载",
"key": "modelmanager.modeldown"
}
]
},