Support multiple models in thought

This commit is contained in:
2025-11-16 01:22:07 +08:00
parent b29f4fce4d
commit a035b23242
3 changed files with 21 additions and 24 deletions

View File

@@ -32,18 +32,11 @@ public class BillingController(AppDatabase db, ThoughtService thoughtService, IL
if (success) if (success)
{ {
if (cost > 0) return Ok(cost > 0
{ ? new { message = $"Billing retry successful. Billed {cost} points." }
return Ok(new { message = $"Billing retry successful. Billed {cost} points." }); : new { message = "No outstanding payment found." });
}
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 BadRequest(new { message = "Billing retry failed. Please check your balance and try again." });
} }
} }

View File

@@ -1,20 +1,15 @@
using System.ClientModel; using System.ClientModel;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using DysonNetwork.Insight.Thought.Plugins; using DysonNetwork.Insight.Thought.Plugins;
using DysonNetwork.Shared.Models;
using DysonNetwork.Shared.Proto; using DysonNetwork.Shared.Proto;
using DysonNetwork.Shared.Registry; using DysonNetwork.Shared.Registry;
using Microsoft.SemanticKernel; using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.Ollama; using Microsoft.SemanticKernel.Connectors.Ollama;
using Microsoft.SemanticKernel.Connectors.OpenAI; using Microsoft.SemanticKernel.Connectors.OpenAI;
using OpenAI; using OpenAI;
using PostType = DysonNetwork.Shared.Proto.PostType;
using Microsoft.SemanticKernel.Plugins.Web; using Microsoft.SemanticKernel.Plugins.Web;
using Microsoft.SemanticKernel.Plugins.Web.Bing; using Microsoft.SemanticKernel.Plugins.Web.Bing;
using Microsoft.SemanticKernel.Plugins.Web.Google; using Microsoft.SemanticKernel.Plugins.Web.Google;
using NodaTime.Serialization.Protobuf;
using NodaTime.Text;
namespace DysonNetwork.Insight.Thought; namespace DysonNetwork.Insight.Thought;
@@ -29,6 +24,7 @@ public class ThoughtProvider
private string? ModelProviderType { get; set; } private string? ModelProviderType { get; set; }
public string? ModelDefault { get; set; } public string? ModelDefault { get; set; }
public List<string> ModelAvailable { get; set; } = [];
[Experimental("SKEXP0050")] [Experimental("SKEXP0050")]
public ThoughtProvider( public ThoughtProvider(
@@ -52,6 +48,7 @@ public class ThoughtProvider
var cfg = configuration.GetSection("Thinking"); var cfg = configuration.GetSection("Thinking");
ModelProviderType = cfg.GetValue<string>("Provider")?.ToLower(); ModelProviderType = cfg.GetValue<string>("Provider")?.ToLower();
ModelDefault = cfg.GetValue<string>("Model"); ModelDefault = cfg.GetValue<string>("Model");
ModelAvailable = cfg.GetValue<List<string>>("ModelAvailable") ?? [];
var endpoint = cfg.GetValue<string>("Endpoint"); var endpoint = cfg.GetValue<string>("Endpoint");
var apiKey = cfg.GetValue<string>("ApiKey"); var apiKey = cfg.GetValue<string>("ApiKey");
@@ -60,14 +57,20 @@ public class ThoughtProvider
switch (ModelProviderType) switch (ModelProviderType)
{ {
case "ollama": 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; break;
case "deepseek": case "deepseek":
var client = new OpenAIClient( var client = new OpenAIClient(
new ApiKeyCredential(apiKey!), new ApiKeyCredential(apiKey!),
new OpenAIClientOptions { Endpoint = new Uri(endpoint ?? "https://api.deepseek.com/v1") } 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; break;
default: default:
throw new IndexOutOfRangeException("Unknown thinking provider: " + ModelProviderType); throw new IndexOutOfRangeException("Unknown thinking provider: " + ModelProviderType);

View File

@@ -22,6 +22,7 @@
"Thinking": { "Thinking": {
"Provider": "deepseek", "Provider": "deepseek",
"Model": "deepseek-chat", "Model": "deepseek-chat",
"ModelAvailable": ["deepseek-chat", "deepseek-reasoner"],
"ApiKey": "sk-bd20f6a2e9fa40b98c46899baa0e9f09" "ApiKey": "sk-bd20f6a2e9fa40b98c46899baa0e9f09"
} }
} }