-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
83 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ public enum AIType | |
AzureOpenAI = 2, | ||
LLamaSharp=3, | ||
SparkDesk=4, | ||
Mock=5, | ||
} | ||
|
||
/// <summary> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string, object?> _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<string, object?> Attributes => _attributes; | ||
|
||
public MockTextCompletion() | ||
{ | ||
|
||
} | ||
|
||
public async Task<IReadOnlyList<TextContent>> 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<StreamingTextContent> 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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters