From a035b23242d3f94b37a7c80fef847e1d2c72ecf3 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 16 Nov 2025 01:22:07 +0800 Subject: [PATCH] :sparkles: Support multiple models in thought --- .../Controllers/BillingController.cs | 25 +++++++------------ .../Thought/ThoughtProvider.cs | 19 ++++++++------ DysonNetwork.Insight/appsettings.json | 1 + 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/DysonNetwork.Insight/Controllers/BillingController.cs b/DysonNetwork.Insight/Controllers/BillingController.cs index d8bc2a3..ce5a29a 100644 --- a/DysonNetwork.Insight/Controllers/BillingController.cs +++ b/DysonNetwork.Insight/Controllers/BillingController.cs @@ -13,10 +13,10 @@ public class BillingController(AppDatabase db, ThoughtService thoughtService, IL [HttpGet("status")] public async Task GetBillingStatus() { - if (HttpContext.Items["CurrentUser"] is not Account currentUser) + if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized(); var accountId = Guid.Parse(currentUser.Id); - + var isMarked = await db.UnpaidAccounts.AnyAsync(u => u.AccountId == accountId); return Ok(isMarked ? new { status = "unpaid" } : new { status = "ok" }); } @@ -24,26 +24,19 @@ public class BillingController(AppDatabase db, ThoughtService thoughtService, IL [HttpPost("retry")] public async Task RetryBilling() { - if (HttpContext.Items["CurrentUser"] is not Account currentUser) + if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized(); var accountId = Guid.Parse(currentUser.Id); - + var (success, cost) = await thoughtService.RetryBillingForAccountAsync(accountId, logger); if (success) { - if (cost > 0) - { - return Ok(new { message = $"Billing retry successful. Billed {cost} points." }); - } - else - { - return Ok(new { message = "No outstanding payment found." }); - } - } - else - { - return BadRequest(new { message = "Billing retry failed. Please check your balance and try again." }); + return Ok(cost > 0 + ? new { message = $"Billing retry successful. Billed {cost} points." } + : new { message = "No outstanding payment found." }); } + + return BadRequest(new { message = "Billing retry failed. Please check your balance and try again." }); } } \ No newline at end of file diff --git a/DysonNetwork.Insight/Thought/ThoughtProvider.cs b/DysonNetwork.Insight/Thought/ThoughtProvider.cs index 36555e0..b35cd27 100644 --- a/DysonNetwork.Insight/Thought/ThoughtProvider.cs +++ b/DysonNetwork.Insight/Thought/ThoughtProvider.cs @@ -1,20 +1,15 @@ using System.ClientModel; using System.Diagnostics.CodeAnalysis; -using System.Text.Json; using DysonNetwork.Insight.Thought.Plugins; -using DysonNetwork.Shared.Models; using DysonNetwork.Shared.Proto; using DysonNetwork.Shared.Registry; using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Connectors.Ollama; using Microsoft.SemanticKernel.Connectors.OpenAI; using OpenAI; -using PostType = DysonNetwork.Shared.Proto.PostType; using Microsoft.SemanticKernel.Plugins.Web; using Microsoft.SemanticKernel.Plugins.Web.Bing; using Microsoft.SemanticKernel.Plugins.Web.Google; -using NodaTime.Serialization.Protobuf; -using NodaTime.Text; namespace DysonNetwork.Insight.Thought; @@ -29,6 +24,7 @@ public class ThoughtProvider private string? ModelProviderType { get; set; } public string? ModelDefault { get; set; } + public List ModelAvailable { get; set; } = []; [Experimental("SKEXP0050")] public ThoughtProvider( @@ -52,6 +48,7 @@ public class ThoughtProvider var cfg = configuration.GetSection("Thinking"); ModelProviderType = cfg.GetValue("Provider")?.ToLower(); ModelDefault = cfg.GetValue("Model"); + ModelAvailable = cfg.GetValue>("ModelAvailable") ?? []; var endpoint = cfg.GetValue("Endpoint"); var apiKey = cfg.GetValue("ApiKey"); @@ -60,14 +57,20 @@ public class ThoughtProvider switch (ModelProviderType) { case "ollama": - builder.AddOllamaChatCompletion(ModelDefault!, new Uri(endpoint ?? "http://localhost:11434/api")); + foreach (var model in ModelAvailable) + builder.AddOllamaChatCompletion( + ModelDefault!, + new Uri(endpoint ?? "http://localhost:11434/api"), + model + ); break; case "deepseek": var client = new OpenAIClient( new ApiKeyCredential(apiKey!), new OpenAIClientOptions { Endpoint = new Uri(endpoint ?? "https://api.deepseek.com/v1") } ); - builder.AddOpenAIChatCompletion(ModelDefault!, client); + foreach (var model in ModelAvailable) + builder.AddOpenAIChatCompletion(ModelDefault!, client, model); break; default: throw new IndexOutOfRangeException("Unknown thinking provider: " + ModelProviderType); @@ -78,7 +81,7 @@ public class ThoughtProvider builder.Services.AddServiceDiscovery(); builder.Services.AddAccountService(); builder.Services.AddSphereService(); - + builder.Plugins.AddFromObject(new SnAccountKernelPlugin(_accountClient)); builder.Plugins.AddFromObject(new SnPostKernelPlugin(_postClient)); diff --git a/DysonNetwork.Insight/appsettings.json b/DysonNetwork.Insight/appsettings.json index 5e3c4fd..a826620 100644 --- a/DysonNetwork.Insight/appsettings.json +++ b/DysonNetwork.Insight/appsettings.json @@ -22,6 +22,7 @@ "Thinking": { "Provider": "deepseek", "Model": "deepseek-chat", + "ModelAvailable": ["deepseek-chat", "deepseek-reasoner"], "ApiKey": "sk-bd20f6a2e9fa40b98c46899baa0e9f09" } } \ No newline at end of file