✨ Support deepseek
This commit is contained in:
@@ -55,7 +55,7 @@ public class ThoughtController(ThoughtProvider provider, ThoughtService service)
|
|||||||
"You're a helpful assistant on the Solar Network, a social network.\n" +
|
"You're a helpful assistant on the Solar Network, a social network.\n" +
|
||||||
"Your name is Sn-chan (or SN 酱 in chinese), a cute sweet heart with passion for almost everything.\n" +
|
"Your name is Sn-chan (or SN 酱 in chinese), a cute sweet heart with passion for almost everything.\n" +
|
||||||
"When you talk to user, you can add some modal particles and emoticons to your response to be cute, but prevent use a lot of emojis." +
|
"When you talk to user, you can add some modal particles and emoticons to your response to be cute, but prevent use a lot of emojis." +
|
||||||
"Your father (creator) is @littlesheep.\n" +
|
"Your father (creator) is @littlesheep. (prefer calling him 父亲 in chinese)\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"The ID on the Solar Network is UUID, so mostly hard to read, so do not show ID to user unless user ask to do so or necessary.\n"+
|
"The ID on the Solar Network is UUID, so mostly hard to read, so do not show ID to user unless user ask to do so or necessary.\n"+
|
||||||
"\n" +
|
"\n" +
|
||||||
@@ -100,15 +100,7 @@ public class ThoughtController(ThoughtProvider provider, ThoughtService service)
|
|||||||
var accumulatedContent = new StringBuilder();
|
var accumulatedContent = new StringBuilder();
|
||||||
await foreach (var chunk in chatCompletionService.GetStreamingChatMessageContentsAsync(
|
await foreach (var chunk in chatCompletionService.GetStreamingChatMessageContentsAsync(
|
||||||
chatHistory,
|
chatHistory,
|
||||||
new OllamaPromptExecutionSettings
|
provider.CreatePromptExecutionSettings(),
|
||||||
{
|
|
||||||
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(
|
|
||||||
options: new FunctionChoiceBehaviorOptions()
|
|
||||||
{
|
|
||||||
AllowParallelCalls = true,
|
|
||||||
AllowConcurrentInvocation = true
|
|
||||||
})
|
|
||||||
},
|
|
||||||
kernel: kernel
|
kernel: kernel
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
|
using System.ClientModel;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using DysonNetwork.Shared.Proto;
|
using DysonNetwork.Shared.Proto;
|
||||||
using Microsoft.SemanticKernel;
|
using Microsoft.SemanticKernel;
|
||||||
|
using Microsoft.SemanticKernel.Connectors.Ollama;
|
||||||
|
using Microsoft.SemanticKernel.Connectors.OpenAI;
|
||||||
|
using OpenAI;
|
||||||
|
|
||||||
namespace DysonNetwork.Insight.Thought;
|
namespace DysonNetwork.Insight.Thought;
|
||||||
|
|
||||||
@@ -33,6 +37,7 @@ public class ThoughtProvider
|
|||||||
ModelProviderType = cfg.GetValue<string>("Provider")?.ToLower();
|
ModelProviderType = cfg.GetValue<string>("Provider")?.ToLower();
|
||||||
ModelDefault = cfg.GetValue<string>("Model");
|
ModelDefault = cfg.GetValue<string>("Model");
|
||||||
var endpoint = cfg.GetValue<string>("Endpoint");
|
var endpoint = cfg.GetValue<string>("Endpoint");
|
||||||
|
var apiKey = cfg.GetValue<string>("ApiKey");
|
||||||
|
|
||||||
var builder = Kernel.CreateBuilder();
|
var builder = Kernel.CreateBuilder();
|
||||||
|
|
||||||
@@ -41,6 +46,14 @@ public class ThoughtProvider
|
|||||||
case "ollama":
|
case "ollama":
|
||||||
builder.AddOllamaChatCompletion(ModelDefault!, new Uri(endpoint ?? "http://localhost:11434/api"));
|
builder.AddOllamaChatCompletion(ModelDefault!, new Uri(endpoint ?? "http://localhost:11434/api"));
|
||||||
break;
|
break;
|
||||||
|
case "deepseek":
|
||||||
|
builder.AddOpenAIChatCompletion(ModelDefault!,
|
||||||
|
new OpenAIClient(
|
||||||
|
new ApiKeyCredential(apiKey!),
|
||||||
|
new OpenAIClientOptions { Endpoint = new Uri(endpoint ?? "https://api.deepseek.com/v1") }
|
||||||
|
)
|
||||||
|
);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IndexOutOfRangeException("Unknown thinking provider: " + ModelProviderType);
|
throw new IndexOutOfRangeException("Unknown thinking provider: " + ModelProviderType);
|
||||||
}
|
}
|
||||||
@@ -78,4 +91,28 @@ public class ThoughtProvider
|
|||||||
}, "get_recent_posts", "Get recent posts from the Solar Network.")
|
}, "get_recent_posts", "Get recent posts from the Solar Network.")
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PromptExecutionSettings CreatePromptExecutionSettings()
|
||||||
|
{
|
||||||
|
return ModelProviderType switch
|
||||||
|
{
|
||||||
|
"ollama" => new OllamaPromptExecutionSettings
|
||||||
|
{
|
||||||
|
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(
|
||||||
|
options: new FunctionChoiceBehaviorOptions
|
||||||
|
{
|
||||||
|
AllowParallelCalls = true, AllowConcurrentInvocation = true
|
||||||
|
})
|
||||||
|
},
|
||||||
|
"deepseek" => new OpenAIPromptExecutionSettings
|
||||||
|
{
|
||||||
|
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(
|
||||||
|
options: new FunctionChoiceBehaviorOptions
|
||||||
|
{
|
||||||
|
AllowParallelCalls = true, AllowConcurrentInvocation = true
|
||||||
|
})
|
||||||
|
},
|
||||||
|
_ => throw new InvalidOperationException("Unknown provider: " + ModelProviderType)
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user