Compare commits

...

41 Commits
0.4.2 ... 0.4.4

Author SHA1 Message Date
zyxucp
531b4473e8 Merge pull request #98 from AIDotNet/feature_nuget
Feature nuget
2024-08-05 11:31:09 +08:00
zyxucp
aefd0d2775 update 2024-08-05 11:30:52 +08:00
zyxucp
960468edf0 update nuget 2024-08-05 11:16:32 +08:00
zyxucp
07ad1f58b5 update sk nuget 2024-08-05 11:03:51 +08:00
zyxucp
095428be50 add llama3 2024-08-05 10:52:51 +08:00
zyxucp
87fc8911fa Merge pull request #97 from AIDotNet/feature_css
fix  处理本地js问题
2024-08-05 10:50:02 +08:00
zyxucp
58272e1ce8 fix 处理本地js问题 2024-08-05 10:49:39 +08:00
zyxucp
700bbcb63f update nuget 2024-07-20 18:14:42 +08:00
zyxucp
dde1d68876 Merge branch 'main' of github.com:AIDotNet/AntSK 2024-07-20 18:13:04 +08:00
zyxucp
71553a6153 fix 修改bge 默认cpu 2024-07-20 18:12:52 +08:00
zyxucp
d4f8de3e21 Merge pull request #96 from AIDotNet/feature_pyruntime
fix pyruntime
2024-07-20 18:11:25 +08:00
zyxucp
6cf5dea10d fix pyruntime 2024-07-20 18:11:03 +08:00
zyxucp
05379dfee6 Update README.zh.md 2024-07-13 14:18:57 +08:00
zyxucp
5a6d49ff64 Update README.md 2024-07-13 14:18:35 +08:00
zyxucp
64ab940a26 Merge branch 'main' of github.com:AIDotNet/AntSK 2024-07-03 21:22:18 +08:00
zyxucp
55982ea36d add ollama model list 2024-07-03 21:22:08 +08:00
zyxucp
21efcf2479 update 复制 2024-07-03 13:07:26 +08:00
zyxucp
0dc7bfcadb add 延迟 2024-07-01 17:10:24 +08:00
zyxucp
22d99091e1 fix string += 2024-07-01 11:52:18 +08:00
zyxucp
7558d3ffdc add ollama modellist 2024-06-30 18:51:01 +08:00
zyxucp
85ae41c44c add utf8 2024-06-30 18:43:48 +08:00
zyxucp
91193850dd fxi 2024-06-30 18:32:58 +08:00
zyxucp
7cc04e3364 add 处理代码 2024-06-30 17:55:19 +08:00
zyxucp
3da28090c6 fix 处理代码最后逻辑 2024-06-30 17:46:58 +08:00
zyxucp
1595ef2c0a Merge branch 'main' of github.com:AIDotNet/AntSK 2024-06-30 17:30:37 +08:00
zyxucp
83e3d81de7 fix markdown 2024-06-30 17:30:26 +08:00
zyxucp
18437ddda4 Update README.zh.md 2024-06-30 17:22:29 +08:00
zyxucp
fd503171a1 Update README.md 2024-06-30 17:22:04 +08:00
zyxucp
7022139780 update docker file and yaml 2024-06-30 17:15:06 +08:00
zyxucp
1e508e45af fix modellist 2024-06-30 17:11:21 +08:00
zyxucp
03d9ec2cad Merge pull request #94 from duyanming/main
解决内容较多的时候需要等结束转Markdown的不好体验。
2024-06-30 17:02:45 +08:00
zyxucp
86fb48bab7 Merge pull request #95 from AIDotNet/feature_ollama
Feature ollama
2024-06-30 17:01:39 +08:00
zyxucp
a4bc1e4a55 fix 2024-06-30 17:00:24 +08:00
zyxucp
8681e15da5 add ollama 2024-06-30 16:59:46 +08:00
zyxucp
ebc82f8b1b add ollamatype 2024-06-30 15:55:42 +08:00
duyanming
3bcd7bd7e1 1、生成结果的同时转化为 Markdown 文本,解决内容较多的时候需要等结束转Markdown的不好体验。
2、去掉模拟延迟,解决体验问题。仿佛生成很慢
2024-06-30 14:16:36 +08:00
zyxucp
b64d8669b1 fix AntDesign.ProLayout bug 2024-06-29 22:43:02 +08:00
zyxucp
0489044098 fix rerank 2024-06-29 10:57:58 +08:00
zyxucp
17e2062b72 margin 2024-06-29 10:57:18 +08:00
zyxucp
4e4f5a698d update nuget 2024-06-29 10:56:47 +08:00
zyxucp
b879d04bcd update nuget 2024-06-23 23:57:01 +08:00
29 changed files with 434 additions and 92 deletions

View File

@@ -1,8 +1,4 @@
# 1. Define the Python image to use for getting pip
FROM pytorch/pytorch AS python-base
# 2. Define the .NET SDK image to build your application
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["src/AntSK/AntSK.csproj", "AntSK/"]
RUN dotnet restore "AntSK/AntSK.csproj"
@@ -11,19 +7,11 @@ WORKDIR "/src/AntSK"
RUN dotnet build "AntSK.csproj" -c Release -o /app/build
RUN dotnet publish "AntSK.csproj" -c Release -o /app/publish
# 3. Define the final image that will contain both .NET runtime and Python
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
# Copy the Python/pip installation from the official Python image
COPY --from=python-base /usr/local /usr/local
COPY --from=python-base /opt/conda/ /opt/conda/
FROM registry.cn-hangzhou.aliyuncs.com/xuzeyu91/antsk-base:v1.0.0 AS final
WORKDIR /app
COPY --from=build /app/publish .
# Make sure the app and Python directories are in PATH
ENV PATH="/app:/opt/conda/bin:/usr/local/bin:${PATH}"
ENV PATH="/app:/opt/conda/bin:/usr/local/bin:${PATH}"
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' >/etc/timezone
RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN apt update && apt install -y libpugixml-dev libtbb-dev
ENTRYPOINT ["dotnet", "AntSK.dll"]

View File

@@ -20,7 +20,7 @@
- **Online Search**: AntSK, real-time access to the latest information, ensuring users receive the most timely and relevant data.
- **Model Management**: Adapts and manages integration of different models from different manufacturers, including gguf types supported by **llama.cpp** and models offline running supported by **llamafactory**.
- **Model Management**: Adapts and manages integration of different models from different manufacturers, including gguf types supported by **llama.cpp** and models offline running supported by **llamafactory** and **ollama**.
- **Domestic Innovation**: AntSK supports domestic models and databases and can run under domestic innovation conditions.
@@ -41,7 +41,7 @@ AntSK is suitable for various business scenarios, such as:
### Online Demo
[document](http://antsk.cn/)
[demo](https://antsk.ai-dotnet.com/)
[demo](https://demo.antsk.cn/)
```
Default account: test

View File

@@ -22,7 +22,7 @@
- **联网搜索**AntSK实时获取最新信息确保用户接受到的资料总是最及时、最相关的。
- **模型管理**:适配和管理集成不同厂商的不同模型。并且支持**llama.cpp**所支持的gguf类型以及**llamafactory**所支持的模型离线运行
- **模型管理**:适配和管理集成不同厂商的不同模型。并且支持**llama.cpp**所支持的gguf类型以及**llamafactory****ollama** 所支持的模型离线运行
- **国产信创**AntSK支持国产模型和国产数据库可以在信创条件下运行
@@ -45,7 +45,7 @@ AntSK 适用于多种业务场景,例如:
[文档地址](http://antsk.cn/)
[体验地址](https://antsk.ai-dotnet.com/)
[体验地址](https://demo.antsk.cn/)
```
默认账号test

View File

@@ -3,9 +3,9 @@ version: '3.8'
services:
antsk:
container_name: antsk
image: registry.cn-hangzhou.aliyuncs.com/xuzeyu91/antsk:v0.4.1
image: registry.cn-hangzhou.aliyuncs.com/xuzeyu91/antsk:v0.4.3
# 如果需要pytorch环境需要使用下面这个镜像镜像比较大
# image: registry.cn-hangzhou.aliyuncs.com/xuzeyu91/antsk:p0.4.1
# image: registry.cn-hangzhou.aliyuncs.com/xuzeyu91/antsk:p0.4.3
ports:
- 5000:5000
networks:

View File

@@ -32,9 +32,9 @@ services:
- ./pg/data:/var/lib/postgresql/data
antsk:
container_name: antsk
image: registry.cn-hangzhou.aliyuncs.com/xuzeyu91/antsk:v0.4.1
image: registry.cn-hangzhou.aliyuncs.com/xuzeyu91/antsk:v0.4.3
# 如果需要pytorch环境需要使用下面这个镜像镜像比较大
# image: registry.cn-hangzhou.aliyuncs.com/xuzeyu91/antsk:p0.4.1
# image: registry.cn-hangzhou.aliyuncs.com/xuzeyu91/antsk:p0.4.3
ports:
- 5000:5000
networks:

View File

@@ -8,27 +8,27 @@
<NoWarn>CA1050,CA1707,CA2007,VSTHRD111,CS1591,RCS1110,CA5394,SKEXP0001,SKEXP0002,SKEXP0003,SKEXP0004,SKEXP0010,SKEXP0011,,SKEXP0012,SKEXP0020,SKEXP0021,SKEXP0022,SKEXP0023,SKEXP0024,SKEXP0025,SKEXP0026,SKEXP0027,SKEXP0028,SKEXP0029,SKEXP0030,SKEXP0031,SKEXP0032,SKEXP0040,SKEXP0041,SKEXP0042,SKEXP0050,SKEXP0051,SKEXP0052,SKEXP0053,SKEXP0054,SKEXP0055,SKEXP0060,SKEXP0061,SKEXP0101,SKEXP0102,KMEXP00</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AntDesign.Charts" Version="0.5.1" />
<PackageReference Include="AntDesign.ProLayout" Version="0.19.0" />
<PackageReference Include="AntDesign.Charts" Version="0.5.5" />
<PackageReference Include="AntDesign.ProLayout" Version="0.19.7" />
<PackageReference Include="BlazorComponents.Terminal" Version="0.6.0" />
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageReference Include="pythonnet" Version="3.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.0" />
<PackageReference Include="AutoMapper" Version="8.1.0" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Markdig" Version="0.37.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.158" />
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftVersion)" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.166" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.118" />
<PackageReference Include="RestSharp" Version="111.2.0" />
<PackageReference Include="NPOI" Version="2.7.0" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.14.1" />
<PackageReference Include="Microsoft.SemanticKernel.Core" Version="1.14.1" />
<PackageReference Include="Microsoft.SemanticKernel.Plugins.Core" Version="1.14.1-alpha" />
<PackageReference Include="RestSharp" Version="$(RestSharpVersion)" />
<PackageReference Include="NPOI" Version="2.7.1" />
<PackageReference Include="Microsoft.SemanticKernel" Version="$(SKVersion)" />
<PackageReference Include="Microsoft.SemanticKernel.Core" Version="$(SKVersion)" />
<PackageReference Include="Microsoft.SemanticKernel.Plugins.Core" Version="$(SKVersion)-alpha" />
<PackageReference Include="Microsoft.KernelMemory.Core" Version="$(KMVersion)" />
<PackageReference Include="Microsoft.KernelMemory.MemoryDb.Postgres" Version="$(KMVersion)" />
<PackageReference Include="Microsoft.KernelMemory.MemoryDb.Qdrant" Version="$(KMVersion)" />
@@ -41,13 +41,13 @@
<PackageReference Include="LLamaSharp.kernel-memory" Version="$(LLamaSharpVersion)" />
<PackageReference Include="LLamaSharp.semantic-kernel" Version="$(LLamaSharpVersion)" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.1-dev-00972" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.1-dev-10391" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.2" />
<PackageReference Include="Serilog.Sinks.Seq" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.OpenTelemetry" Version="3.0.0" />
<PackageReference Include="Serilog.Sinks.OpenTelemetry" Version="4.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AntSK.LLamaFactory\AntSK.LLamaFactory.csproj" />

View File

@@ -52,5 +52,10 @@ namespace AntSK.Domain.Common.Embedding
{
return BgeEmbeddingConfig.TokenCount(text);
}
public IReadOnlyList<string> GetTokens(string text)
{
return new List<string>();
}
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static AntSK.Domain.Domain.Service.OllamaService;
namespace AntSK.Domain.Domain.Interface
{
public interface IOllamaService
{
public event LogMessageHandler LogMessageReceived;
Task StartOllama(string modelName);
}
}

View File

@@ -30,6 +30,9 @@ namespace AntSK.Domain.Domain.Model.Enum
BgeRerank = 8,
[Display(Name = "StableDiffusion")]
StableDiffusion = 9,
[Display(Name = "Ollama")]
Ollama = 10,
[Display(Name = "模拟输出")]
Mock = 100,

View File

@@ -26,11 +26,7 @@ namespace AntSK.Domain.Domain.Other.Bge
{
if (model == null)
{
if (string.IsNullOrEmpty(Runtime.PythonDLL))
{
Runtime.PythonDLL = pythondllPath;
}
PythonEngine.Initialize();
PyRunTime.InitRunTime(pythondllPath);
try
{
using (GIL())// 初始化Python环境的Global Interpreter Lock)
@@ -39,7 +35,7 @@ namespace AntSK.Domain.Domain.Other.Bge
dynamic flagEmbedding = Py.Import("FlagEmbedding");
dynamic model_dir = modelscope.snapshot_download(modelName, revision: "master");
dynamic flagReranker = flagEmbedding.FlagReranker(model_dir, use_fp16: true);
dynamic flagReranker = flagEmbedding.FlagReranker(model_dir, use_fp16: false);
model = flagReranker;
return model;
}

View File

@@ -1,5 +1,4 @@
using Microsoft.KernelMemory.AI.OpenAI;
using Microsoft.KernelMemory.AI.OpenAI.GPT3;
using Python.Runtime;
using Serilog;
using System;
@@ -28,13 +27,7 @@ namespace AntSK.Domain.Domain.Other.Bge
{
if (model == null)
{
//Runtime.PythonDLL = @"D:\Programs\Python\Python311\python311.dll";
if (string.IsNullOrEmpty(Runtime.PythonDLL))
{
Runtime.PythonDLL = pythondllPath;
}
PythonEngine.Initialize();
PythonEngine.BeginAllowThreads();
PyRunTime.InitRunTime(pythondllPath);
try
{
using (GIL())// 初始化Python环境的Global Interpreter Lock)

View File

@@ -0,0 +1,28 @@
using Python.Runtime;
namespace AntSK.Domain.Domain.Other.Bge
{
public static class PyRunTime
{
static object lockobj = new object();
static bool isInit = false;
public static void InitRunTime(string pythonPath)
{
lock (lockobj)
{
if (!isInit)
{
if (string.IsNullOrEmpty(Runtime.PythonDLL))
{
Runtime.PythonDLL = pythonPath;
}
PythonEngine.Initialize();
PythonEngine.BeginAllowThreads();
isInit = true;
}
}
}
}
}

View File

@@ -220,6 +220,13 @@ namespace AntSK.Domain.Domain.Service
break;
case Model.Enum.AIType.LLamaFactory:
memory.WithOpenAITextGeneration(new OpenAIConfig()
{
APIKey = "NotNull",
TextModel = chatModel.ModelName
}, null, chatHttpClient);
break;
case Model.Enum.AIType.Ollama:
memory.WithOpenAITextGeneration(new OpenAIConfig()
{
APIKey = "NotNull",

View File

@@ -154,7 +154,14 @@ namespace AntSK.Domain.Domain.Service
case Model.Enum.AIType.LLamaFactory:
builder.AddOpenAIChatCompletion(
modelId: chatModel.ModelName,
apiKey: "123",
apiKey: "NotNull",
httpClient: chatHttpClient
);
break;
case AIType.Ollama:
builder.AddOpenAIChatCompletion(
modelId: chatModel.ModelName,
apiKey: "NotNull",
httpClient: chatHttpClient
);
break;

View File

@@ -0,0 +1,74 @@
using AntSK.Domain.Common.DependencyInjection;
using AntSK.Domain.Domain.Interface;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Serilog;
using AntSK.Domain.Utils;
namespace AntSK.Domain.Domain.Service
{
[ServiceDescription(typeof(IOllamaService), ServiceLifetime.Singleton)]
public class OllamaService : IOllamaService
{
private Process process;
public delegate Task LogMessageHandler(string message);
public event LogMessageHandler LogMessageReceived;
protected virtual async Task OnLogMessageReceived(string message)
{
LogMessageReceived?.Invoke(message);
}
public async Task StartOllama(string modelName)
{
Console.OutputEncoding = Encoding.UTF8;
var cmdTask = Task.Factory.StartNew(() =>
{
var isProcessComplete = false;
process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "ollama",
Arguments = "run " + modelName,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
}
};
process.OutputDataReceived += (sender, eventArgs) =>
{
Log.Information($"{eventArgs.Data.ConvertToString()}");
if (!eventArgs.Data.ConvertToString().Contains("The handle is invalid"))
{
OnLogMessageReceived(eventArgs.Data.ConvertToString());
}
};
process.ErrorDataReceived += (sender, eventArgs) =>
{
Log.Error($"{eventArgs.Data.ConvertToString()}");
if (!eventArgs.Data.ConvertToString().Contains("The handle is invalid"))
{
OnLogMessageReceived(eventArgs.Data.ConvertToString());
}
};
process.StartInfo.StandardOutputEncoding = Encoding.UTF8;
process.StartInfo.StandardErrorEncoding = Encoding.UTF8;
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
OnLogMessageReceived("--------------------完成--------------------");
}, TaskCreationOptions.LongRunning);
await cmdTask;
}
}
}

View File

@@ -9,11 +9,11 @@
<PackageReference Include="Microsoft.KernelMemory.Core" Version="$(KMVersion)" />
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.9.0.20240103" />
<PackageReference Include="Sdcb.OpenCvSharp4.mini.runtime.debian.12-x64" Version="4.8.0.20231125" />
<PackageReference Include="Sdcb.OpenVINO" Version="0.6.5" />
<PackageReference Include="Sdcb.OpenVINO" Version="0.6.6" />
<PackageReference Include="Sdcb.OpenVINO.PaddleOCR.Models.Online" Version="0.6.2" />
<PackageReference Include="Sdcb.OpenVINO.PaddleOCR" Version="0.6.3" />
<PackageReference Include="Sdcb.OpenVINO.runtime.ubuntu.22.04-x64" Version="2024.0.0" />
<PackageReference Include="Sdcb.OpenVINO.runtime.win-x64" Version="2024.1.0" />
<PackageReference Include="Sdcb.OpenVINO.runtime.ubuntu.22.04-x64" Version="2024.2.0" />
<PackageReference Include="Sdcb.OpenVINO.runtime.win-x64" Version="2024.2.0" />
</ItemGroup>
</Project>

View File

@@ -19,7 +19,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MiddleWare", "MiddleWare",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntSK.BackgroundTask", "MiddleWare\AntSK.BackgroundTask\AntSK.BackgroundTask.csproj", "{DF87E829-99C5-44A7-9718-B3E67DC801F6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntSK.LLM", "AntSk.LLM\AntSK.LLM.csproj", "{19529BFA-152F-4A8C-8254-F2D4896AB739}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntSK.LLM", "AntSK.LLM\AntSK.LLM.csproj", "{19529BFA-152F-4A8C-8254-F2D4896AB739}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntSK.Test", "AntSK.Test\AntSK.Test.csproj", "{6AD71410-127F-4C83-95A8-F699C39B44FF}"
EndProject
@@ -38,6 +38,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntSK.AppHost", "AntSK.AppH
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntSK.ServiceDefaults", "AntSK.ServiceDefaults\AntSK.ServiceDefaults.csproj", "{21AC6184-336E-475F-8975-80A39D59B0CC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "解决方案项", "解决方案项", "{76407DD9-6F9D-401C-8A8C-4B6FEC03988A}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU

View File

@@ -24,7 +24,7 @@
<IconPicker @bind-Value="@context.Icon"></IconPicker>
</FormItem>
<FormItem Label="类型" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
<RadioGroup @bind-Value="context.Type" OnChange="OnAppTypeChange" TValue="string">
<RadioGroup @bind-Value="context.Type" OnChange="OnAppTypeChange" TValue="string" ButtonStyle="RadioButtonStyle.Solid">
<Radio RadioButton Value="@AppType.chat.ToString()">会话应用</Radio>
<Radio RadioButton Value="@AppType.kms.ToString()">知识库</Radio>
<Radio RadioButton Value="@AppType.img.ToString()">做图应用</Radio>

View File

@@ -19,6 +19,7 @@ using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Text;
namespace AntSK.Pages.ChatPage.Components
{
@@ -82,6 +83,7 @@ namespace AntSK.Pages.ChatPage.Components
var userSession = userSessionStorageResult.Success ? userSessionStorageResult.Value : null;
_userName = userSession?.UserName;
await GetMsgList();
await MarkDown();
}
/// <summary>
/// 获取聊天记录列表
@@ -323,15 +325,16 @@ namespace AntSK.Pages.ChatPage.Components
};
MessageList.Add(info);
var chatResult = _chatService.SendKmsByAppAsync(app, questions, history, filePath, _relevantSources);
StringBuilder rawContent = new StringBuilder();
await foreach (var content in chatResult)
{
info.Context += content.ConvertToString();
await Task.Delay(50);
rawContent.Append(content.ConvertToString());
info.Context = Markdown.ToHtml(rawContent.ToString());
await Task.Delay(30);
await InvokeAsync(StateHasChanged);
}
//全部处理完后再处理一次Markdown
await MarkDown(info);
//全部处理完后再处理一次Markdown 处理代码高亮
await MarkDown();
}
/// <summary>
@@ -344,10 +347,12 @@ namespace AntSK.Pages.ChatPage.Components
{
Chats info = null;
var chatResult = _chatService.SendChatByAppAsync(app, history);
StringBuilder rawContent = new StringBuilder();
await foreach (var content in chatResult)
{
if (info == null)
{
rawContent.Append(content.ConvertToString());
info = new Chats();
info.Id = Guid.NewGuid().ToString();
info.UserName = _userName;
@@ -359,13 +364,14 @@ namespace AntSK.Pages.ChatPage.Components
}
else
{
info.Context += content.ConvertToString();
await Task.Delay(50);
rawContent.Append(content.ConvertToString());
}
info.Context = Markdown.ToHtml(rawContent.ToString());
await Task.Delay(30);
await InvokeAsync(StateHasChanged);
}
//全部处理完后再处理一次Markdown
await MarkDown(info);
//全部处理完后再处理一次Markdown 处理代码高亮
await MarkDown();
}
/// <summary>
@@ -373,14 +379,8 @@ namespace AntSK.Pages.ChatPage.Components
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
private async Task MarkDown(Chats info)
private async Task MarkDown()
{
if (info.IsNotNull())
{
// info!.HtmlAnswers = markdown.Transform(info.HtmlAnswers);
info!.Context = Markdown.ToHtml(info.Context);
}
await InvokeAsync(StateHasChanged);
await _JSRuntime.InvokeVoidAsync("Prism.highlightAll");
await _JSRuntime.ScrollToBottomAsync("scrollDiv");

View File

@@ -29,7 +29,7 @@
<TextArea Placeholder="一个一行,以冒号分割。例如:Content-Type:application/json" @bind-Value="@context.Header" MinRows="3" />
</FormItem>
<FormItem Label="Method类型" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
<EnumRadioGroup ButtonStyle="@RadioButtonStyle.Outline" @bind-Value="context.Method"></EnumRadioGroup>
<EnumRadioGroup ButtonStyle="@RadioButtonStyle.Solid" @bind-Value="context.Method"></EnumRadioGroup>
</FormItem>
@if (context.Method == HttpMethodType.Get)

View File

@@ -27,7 +27,7 @@
<EnumRadioGroup @bind-Value="context.AIType" ButtonStyle="RadioButtonStyle.Solid" OnChange="AITypeChange" TEnum="AIType"> </EnumRadioGroup>
</FormItem>
<FormItem Label="模型类型" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
<RadioGroup @bind-Value="context.AIModelType">
<RadioGroup @bind-Value="context.AIModelType" ButtonStyle="RadioButtonStyle.Solid">
@if (context.AIType == AIType.StableDiffusion)
{
<Radio RadioButton Value="@(AIModelType.Image)">图片模型</Radio>
@@ -38,7 +38,7 @@
{
<Radio RadioButton Value="@(AIModelType.Chat)">会话模型</Radio>
}
@if (context.AIType != AIType.LLamaFactory && context.AIType != AIType.Mock && context.AIType != AIType.SparkDesk && context.AIType != AIType.BgeRerank)
@if (context.AIType != AIType.LLamaFactory && context.AIType != AIType.Mock && context.AIType != AIType.SparkDesk && context.AIType != AIType.BgeRerank && context.AIType != AIType.Ollama)
{
<Radio RadioButton Value="@(AIModelType.Embedding)">向量模型</Radio>
}
@@ -65,12 +65,12 @@
<Input Placeholder="请输入部署名" @bind-Value="@context.ModelName" />
</FormItem>
<FormItem Label="模型秘钥" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
<InputPassword @bind-Value="@context.ModelKey" Placeholder="请输入模型秘钥" />
<InputPassword @bind-Value="@context.ModelKey" Placeholder="请输入模型秘钥" />
</FormItem>
}
@if (context.AIType == AIType.OpenAI)
{
<FormItem Label="代理API" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
<FormItem Label="代理API" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
<a href="https://api.antsk.cn/" target="_blank">去创建</a>
</FormItem>
<FormItem Label="请求地址" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
@@ -98,7 +98,7 @@
<FormItem Label="请输入模型APPID|APISecret|APIKey" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
<InputPassword Placeholder="APPID|APISecret|APIKey" @bind-Value="@context.ModelKey" />
</FormItem>
}
@if (context.AIType == AIType.DashScope)
{
@@ -154,7 +154,39 @@
</InputGroup>
</FormItem>
}
@if (context.AIType == AIType.Ollama)
{
<FormItem Label="模型名称" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
<InputGroup>
<Select TItem="string"
TItemValue="string"
DataSource="@ollamaModelList"
@bind-Value="@context.ModelName"
ValueProperty="c=>c"
LabelProperty="c=>c"
Placeholder="选择模型"
DefaultActiveFirstOption="false"
EnableSearch
OnSearch="OnOllamaSearch">
</Select>
</InputGroup>
<a href="https://ollama.com/library" target="_blank">获取更多模型</a>
</FormItem>
<FormItem Label="请求地址" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
<Input Placeholder="http://localhost:11434/" @bind-Value="@context.EndPoint" />
</FormItem>
<FormItem Label="环境安装" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
<a href="https://ollama.com/download" target="_blank">下载Ollama</a>
</FormItem>
<FormItem Label="Ollama服务" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">
<InputGroup>
<Button Type="primary" OnClick="StartOllamaService" >启动</Button>
</InputGroup>
</FormItem>
}
@if (context.AIType == AIType.BgeEmbedding)
{
<FormItem Label="模型名称" LabelCol="LayoutModel._formItemLayout.LabelCol" WrapperCol="LayoutModel._formItemLayout.WrapperCol">

View File

@@ -29,6 +29,7 @@ namespace AntSK.Pages.Setting.AIModel
[Inject] public HttpClient HttpClient { get; set; }
[Inject] protected ILLamaFactoryService _ILLamaFactoryService { get; set; }
[Inject] protected IOllamaService _ollamaService { get; set; }
[Inject] protected IDics_Repositories _IDics_Repositories { get; set; }
[Inject] IConfirmService _confirmService { get; set; }
@@ -55,6 +56,9 @@ namespace AntSK.Pages.Setting.AIModel
private List<LLamaModel> modelList=new List<LLamaModel>();
private bool llamaFactoryIsStart = false;
private Dics llamaFactoryDic= new Dics();
private List<string> ollamaModelList = new List<string>();
//日志输出
private BlazorTerminal blazorTerminal = new BlazorTerminal();
private TerminalParagraph para;
@@ -86,7 +90,7 @@ namespace AntSK.Pages.Setting.AIModel
llamaFactoryIsStart = llamaFactoryDic.Value == "false" ? false : true;
}
ollamaModelList = File.ReadAllLines(Path.Combine(AppContext.BaseDirectory, "OllamaModelList.txt")).ToList();
//目前只支持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))
@@ -234,7 +238,20 @@ namespace AntSK.Pages.Setting.AIModel
}
}
private void OnOllamaSearch(string value)
{
if (string.IsNullOrEmpty(value))
{
ollamaModelList = File.ReadAllLines(Path.Combine(AppContext.BaseDirectory, "OllamaModelList.txt")).ToList();
}
else
{
ollamaModelList = File.ReadAllLines(Path.Combine(AppContext.BaseDirectory, "OllamaModelList.txt")).ToList().Where(p => p.ToLower().Contains(value.ToLower())).ToList();
}
}
/// <summary>
/// 启动服务
/// </summary>
@@ -261,6 +278,27 @@ namespace AntSK.Pages.Setting.AIModel
_IDics_Repositories.Update(llamaFactoryDic);
_ILLamaFactoryService.KillProcess();
}
/// <summary>
/// Ollama
/// </summary>
/// <returns></returns>
private async Task StartOllamaService()
{
if (string.IsNullOrEmpty(_aiModel.ModelName))
{
_ = Message.Error("请先选择模型!", 2);
return;
}
_logModalVisible = true;
_ollamaService.LogMessageReceived -= CmdLogHandler;
_ollamaService.LogMessageReceived += CmdLogHandler;
_ollamaService.StartOllama(_aiModel.ModelName);
}
private async Task PipInstall()
{
var content = "初次使用需要执行pip install点击确认后可自动执行是否执行";
@@ -365,6 +403,10 @@ namespace AntSK.Pages.Setting.AIModel
_aiModel.EndPoint = "http://localhost:8000/";
_aiModel.AIModelType=AIModelType.Chat;
break;
case AIType.Ollama:
_aiModel.EndPoint = "http://localhost:11434/";
_aiModel.AIModelType = AIModelType.Chat;
break;
case AIType.StableDiffusion:
_aiModel.AIModelType = AIModelType.Image;
break;

View File

@@ -82,6 +82,10 @@
{
<Tag Color="@PresetColor.Magenta.ToString()">StableDiffusion</Tag>
}
else if (context.AIType == AIType.Ollama)
{
<Tag Color="@PresetColor.Pink.ToString()">Ollama</Tag>
}
</p>
</div>

View File

@@ -31,7 +31,7 @@
<component type="typeof(App)" render-mode="Server" />
</app>
<script type="text/javascript" src="@("https://unpkg.com/@antv/g2plot@2.4.17/dist/g2plot.min.js")"></script>
<script src="./js/g2plot.min.js"></script>
<script src="_content/AntDesign/js/ant-design-blazor.js"></script>
<script src="_content/AntDesign.Charts/ant-design-charts-blazor.js"></script>
<script src="_framework/blazor.server.js"></script>

View File

@@ -95,7 +95,7 @@ namespace AntSK.Services.OpenApi
private async Task SendChatStream(HttpContext HttpContext, OpenAIStreamResult result, Apps app, ChatHistory history)
{
HttpContext.Response.Headers.Add("Content-Type", "text/event-stream");
HttpContext.Response.Headers.Add("Content-Type", "text/event-stream;charset=utf-8");
var chatResult = _chatService.SendChatByAppAsync(app, history);
await foreach (var content in chatResult)
{
@@ -165,7 +165,7 @@ namespace AntSK.Services.OpenApi
private async Task SendKmsStream(HttpContext HttpContext, OpenAIStreamResult result, Apps app, string questions,ChatHistory history)
{
HttpContext.Response.Headers.Add("Content-Type", "text/event-stream");
HttpContext.Response.Headers.Add("Content-Type", "text/event-stream;charset=utf-8");
var chatResult = _chatService.SendKmsByAppAsync(app, questions, history, "");
int i = 0;
await foreach (var content in chatResult)

32
src/AntSK/wwwroot/js/g2plot.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -7,16 +7,19 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SemanticKernel" Version="1.14.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RestSharp" Version="111.2.0" />
<PackageReference Include="Cnblogs.KernelMemory.AI.DashScope" Version="0.1.0" />
<PackageReference Include="Microsoft.SemanticKernel" Version="$(SKVersion)" />
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftVersion)" />
<PackageReference Include="RestSharp" Version="$(RestSharpVersion)" />
<PackageReference Include="Cnblogs.KernelMemory.AI.DashScope" Version="0.3.0" />
<PackageReference Include="Cnblogs.SemanticKernel.Connectors.DashScope" Version="0.3.2" />
<PackageReference Include="Sdcb.SparkDesk" Version="3.0.0" />
<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<None Update="OllamaModelList.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="StableDiffusion\Backend\CPU\stable-diffusion.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
@@ -42,7 +45,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="StableDiffusionModelList.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

View File

@@ -0,0 +1,105 @@
gemma2
gemma2:27b
gemma:2b
gemma:7b
llama3
llama3:70b
yi:6b
yi:9B
yi:34B
qwen2:0.5b
qwen2:1.5b
qwen2:7b
qwen2:72b
qwen:0.5b
qwen:1.8b
qwen:4b
qwen:7b
qwen:14b
qwen:32b
qwen:72b
qwen:110b
deepseek-coder:1.3b
deepseek-coder:6.7b
deepseek-coder:33b
deepseek-coder-v2:16b
deepseek-coder-v2:236b
phi:2.7b
phi3:mini
phi3:medium
phi3:medium-128k
aya:8b
aya:35b
mistral:7b
mixtral:8x22b
mixtral:8x7b
codegemma:2b
codegemma:7b
command-r:35b
llava
gemma:2b
gemma:7b
llama2:7b
llama2:13b
llama2:70b
llama2-chinese:7b
llama2-chinese:13b
llama3.1:8b
llama3.1:70b
llama3.1:405b
codellama:7b
codellama:13b
codellama:34b
codellama:70b
dolphin-mistral:7b
dolphin-mixtral:8x22b
dolphin-mixtral:8x7b
llama2-uncensored:7b
llama2-uncensored:70b
tinyllama:1.1b
openchat:7b
orca-mini:3b
orca-mini:7b
orca-mini:13b
orca-mini:70b
mistral-openorca:7b
dolphin-llama3:8b
dolphin-llama3:70b
starcoder:1b
starcoder:3b
starcoder:7b
starcoder:15b
starcoder2:3b
starcoder2:7b
starcoder2:15b
zephyr:7b
zephyr:141b
nous-hermes2:10.7b
nous-hermes2:34b
vicuna:7b
vicuna:13b
vicuna:33b
wizard-vicuna-uncensored:7b
wizard-vicuna-uncensored:13b
wizard-vicuna-uncensored:30b
wizardlm2:7b
codestral:22b
tinydolphin:1.1b
openhermes:v2.5
neural-chat:7b
codeqwen:7b
phind-codellama:34b
nous-hermes:7b
nous-hermes:13b
nous-hermes:13b
starling-lm:7b
llama3-gradient:8b
llama3-gradient:70b
yarn-llama2:7b
yarn-llama2:13b
llava-llama3:8b
llama-pro:instruct
everythinglm:13b
llava-phi3:3.8b
mistrallite:7b
notus:7b

View File

@@ -1,7 +1,10 @@
<Project>
<!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build -->
<PropertyGroup>
<KMVersion>0.62.240605.1</KMVersion>
<LLamaSharpVersion>0.13.0</LLamaSharpVersion>
<KMVersion>0.70.240803.1</KMVersion>
<LLamaSharpVersion>0.15.0</LLamaSharpVersion>
<NewtonsoftVersion>13.0.3</NewtonsoftVersion>
<RestSharpVersion>111.4.1</RestSharpVersion>
<SKVersion>1.16.2</SKVersion>
</PropertyGroup>
</Project>