diff --git a/src/AntSK.Domain/AntSK.Domain.csproj b/src/AntSK.Domain/AntSK.Domain.csproj
index c19f4e0d..ff65e6e4 100644
--- a/src/AntSK.Domain/AntSK.Domain.csproj
+++ b/src/AntSK.Domain/AntSK.Domain.csproj
@@ -34,7 +34,7 @@
-
+
diff --git a/src/AntSK.Domain/Domain/Service/KernelService.cs b/src/AntSK.Domain/Domain/Service/KernelService.cs
index ddaeae40..15600fdb 100644
--- a/src/AntSK.Domain/Domain/Service/KernelService.cs
+++ b/src/AntSK.Domain/Domain/Service/KernelService.cs
@@ -1,4 +1,4 @@
-using AntSk.LLM.SparkDesk;
+using AntSK.LLM.SparkDesk;
using AntSK.Domain.Common.DependencyInjection;
using AntSK.Domain.Domain.Interface;
using AntSK.Domain.Domain.Other;
@@ -14,6 +14,7 @@
using RestSharp;
using System;
using ServiceLifetime = AntSK.Domain.Common.DependencyInjection.ServiceLifetime;
+using AntSK.LLM.Mock;
namespace AntSK.Domain.Domain.Service
{
@@ -93,6 +94,9 @@ private void WithTextGenerationByAIType(IKernelBuilder builder, Apps app, AIMode
var options = new SparkDeskOptions { AppId = chatModel.EndPoint, ApiSecret = chatModel.ModelKey, ApiKey = chatModel.ModelName, ModelVersion = Sdcb.SparkDesk.ModelVersion.V3_5 };
builder.Services.AddKeyedSingleton("spark-desk", new SparkDeskTextCompletion(options, app.Id));
break;
+ case Model.Enum.AIType.Mock:
+ builder.Services.AddKeyedSingleton("mock", new MockTextCompletion());
+ break;
}
}
diff --git a/src/AntSK.Domain/Model/Enum/AIModelType.cs b/src/AntSK.Domain/Model/Enum/AIModelType.cs
index b2b9f23d..7b51d9b4 100644
--- a/src/AntSK.Domain/Model/Enum/AIModelType.cs
+++ b/src/AntSK.Domain/Model/Enum/AIModelType.cs
@@ -9,6 +9,7 @@ public enum AIType
AzureOpenAI = 2,
LLamaSharp=3,
SparkDesk=4,
+ Mock=5,
}
///
diff --git a/src/AntSK.sln b/src/AntSK.sln
index 90547e91..3cd362dd 100644
--- a/src/AntSK.sln
+++ b/src/AntSK.sln
@@ -18,7 +18,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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AntSk.LLM.SparkDesk", "AntSk.LLM.SparkDesk\AntSk.LLM.SparkDesk.csproj", "{1B4313B3-EF8E-4ADC-982A-C3F608BDEFDB}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntSK.LLM", "AntSk.LLM\AntSK.LLM.csproj", "{19529BFA-152F-4A8C-8254-F2D4896AB739}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -38,10 +38,10 @@ Global
{DF87E829-99C5-44A7-9718-B3E67DC801F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DF87E829-99C5-44A7-9718-B3E67DC801F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DF87E829-99C5-44A7-9718-B3E67DC801F6}.Release|Any CPU.Build.0 = Release|Any CPU
- {1B4313B3-EF8E-4ADC-982A-C3F608BDEFDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {1B4313B3-EF8E-4ADC-982A-C3F608BDEFDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {1B4313B3-EF8E-4ADC-982A-C3F608BDEFDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {1B4313B3-EF8E-4ADC-982A-C3F608BDEFDB}.Release|Any CPU.Build.0 = Release|Any CPU
+ {19529BFA-152F-4A8C-8254-F2D4896AB739}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {19529BFA-152F-4A8C-8254-F2D4896AB739}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {19529BFA-152F-4A8C-8254-F2D4896AB739}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {19529BFA-152F-4A8C-8254-F2D4896AB739}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/src/AntSK/Pages/KmsPage/AddKms.razor.cs b/src/AntSK/Pages/KmsPage/AddKms.razor.cs
index ee885392..73f235d7 100644
--- a/src/AntSK/Pages/KmsPage/AddKms.razor.cs
+++ b/src/AntSK/Pages/KmsPage/AddKms.razor.cs
@@ -28,9 +28,10 @@ public partial class AddKms
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
- //星火没实现KM先隐藏
- _chatList = _aimodels_Repositories.GetList(p => p.AIModelType == AIModelType.Chat&&p.AIType!=AIType.SparkDesk);
- _embeddingList = _aimodels_Repositories.GetList(p => p.AIModelType == AIModelType.Embedding && p.AIType != AIType.SparkDesk);
+ //星火 Mock没实现KM先隐藏
+ List ignores = new List() { AIType.SparkDesk, AIType.Mock };
+ _chatList = _aimodels_Repositories.GetList(p => p.AIModelType == AIModelType.Chat&& !ignores.Contains(p.AIType));
+ _embeddingList = _aimodels_Repositories.GetList(p => p.AIModelType == AIModelType.Embedding && !ignores.Contains(p.AIType));
if (!string.IsNullOrEmpty(KmsId))
{
//查看
diff --git a/src/AntSK/Pages/Setting/AIModel/AddModel.razor b/src/AntSK/Pages/Setting/AIModel/AddModel.razor
index 2fd15fce..17e5293a 100644
--- a/src/AntSK/Pages/Setting/AIModel/AddModel.razor
+++ b/src/AntSK/Pages/Setting/AIModel/AddModel.razor
@@ -76,6 +76,11 @@
+ }
+ @if (context.AIType == AIType.Mock)
+ {
+
+
}
diff --git a/src/AntSk.LLM.SparkDesk/AntSk.LLM.SparkDesk.csproj b/src/AntSk.LLM/AntSK.LLM.csproj
similarity index 100%
rename from src/AntSk.LLM.SparkDesk/AntSk.LLM.SparkDesk.csproj
rename to src/AntSk.LLM/AntSK.LLM.csproj
diff --git a/src/AntSk.LLM/Mock/MockTextCompletion.cs b/src/AntSk.LLM/Mock/MockTextCompletion.cs
new file mode 100644
index 00000000..5dc4a8d4
--- /dev/null
+++ b/src/AntSk.LLM/Mock/MockTextCompletion.cs
@@ -0,0 +1,56 @@
+using AntSK.LLM.SparkDesk;
+using Microsoft.SemanticKernel;
+using Microsoft.SemanticKernel.Connectors.OpenAI;
+using Microsoft.SemanticKernel.Services;
+using Microsoft.SemanticKernel.TextGeneration;
+using Sdcb.SparkDesk;
+using System;
+using System.ComponentModel;
+using System.Text;
+using System.Text.Encodings.Web;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using System.Text.Unicode;
+
+namespace AntSK.LLM.Mock
+{
+ public class MockTextCompletion : ITextGenerationService, IAIService
+ {
+ private readonly Dictionary _attributes = new();
+ private readonly SparkDeskClient _client;
+ private string _chatId;
+ private readonly SparkDeskOptions _options;
+
+ private static readonly JsonSerializerOptions _jsonSerializerOptions = new()
+ {
+ NumberHandling = JsonNumberHandling.AllowReadingFromString,
+ Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
+ };
+
+ public IReadOnlyDictionary Attributes => _attributes;
+
+ public MockTextCompletion()
+ {
+
+ }
+
+ public async Task> GetTextContentsAsync(string prompt, PromptExecutionSettings? executionSettings = null, Kernel? kernel = null, CancellationToken cancellationToken = default)
+ {
+ StringBuilder sb = new();
+ string result = $"这是一条Mock数据,便于聊天测试,你的消息是:{prompt}";
+ return [new(result.ToString())];
+ }
+
+ public async IAsyncEnumerable GetStreamingTextContentsAsync(string prompt, PromptExecutionSettings? executionSettings = null, Kernel? kernel = null, CancellationToken cancellationToken = default)
+ {
+ StringBuilder sb = new();
+ string result = $"这是一条Mock数据,便于聊天测试,你的消息是:{prompt}";
+ foreach (var c in result)
+ {
+ var streamingTextContent = new StreamingTextContent(c.ToString(), modelId: "mock");
+
+ yield return streamingTextContent;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/AntSk.LLM.SparkDesk/SparkDeskOptions.cs b/src/AntSk.LLM/SparkDesk/SparkDeskOptions.cs
similarity index 92%
rename from src/AntSk.LLM.SparkDesk/SparkDeskOptions.cs
rename to src/AntSk.LLM/SparkDesk/SparkDeskOptions.cs
index 3880becd..c604f54e 100644
--- a/src/AntSk.LLM.SparkDesk/SparkDeskOptions.cs
+++ b/src/AntSk.LLM/SparkDesk/SparkDeskOptions.cs
@@ -5,7 +5,7 @@
using System.Text;
using System.Threading.Tasks;
-namespace AntSk.LLM.SparkDesk
+namespace AntSK.LLM.SparkDesk
{
public class SparkDeskOptions
{
diff --git a/src/AntSk.LLM.SparkDesk/SparkDeskTextCompletion.cs b/src/AntSk.LLM/SparkDesk/SparkDeskTextCompletion.cs
similarity index 99%
rename from src/AntSk.LLM.SparkDesk/SparkDeskTextCompletion.cs
rename to src/AntSk.LLM/SparkDesk/SparkDeskTextCompletion.cs
index 7852ea34..5613173c 100644
--- a/src/AntSk.LLM.SparkDesk/SparkDeskTextCompletion.cs
+++ b/src/AntSk.LLM/SparkDesk/SparkDeskTextCompletion.cs
@@ -11,7 +11,7 @@
using System.Text.Json.Serialization;
using System.Text.Unicode;
-namespace AntSk.LLM.SparkDesk
+namespace AntSK.LLM.SparkDesk
{
public class SparkDeskTextCompletion : ITextGenerationService, IAIService
{