✨ Support multiple models in thought
This commit is contained in:
@@ -13,10 +13,10 @@ public class BillingController(AppDatabase db, ThoughtService thoughtService, IL
|
|||||||
[HttpGet("status")]
|
[HttpGet("status")]
|
||||||
public async Task<IActionResult> GetBillingStatus()
|
public async Task<IActionResult> GetBillingStatus()
|
||||||
{
|
{
|
||||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
var accountId = Guid.Parse(currentUser.Id);
|
var accountId = Guid.Parse(currentUser.Id);
|
||||||
|
|
||||||
var isMarked = await db.UnpaidAccounts.AnyAsync(u => u.AccountId == accountId);
|
var isMarked = await db.UnpaidAccounts.AnyAsync(u => u.AccountId == accountId);
|
||||||
return Ok(isMarked ? new { status = "unpaid" } : new { status = "ok" });
|
return Ok(isMarked ? new { status = "unpaid" } : new { status = "ok" });
|
||||||
}
|
}
|
||||||
@@ -24,26 +24,19 @@ public class BillingController(AppDatabase db, ThoughtService thoughtService, IL
|
|||||||
[HttpPost("retry")]
|
[HttpPost("retry")]
|
||||||
public async Task<IActionResult> RetryBilling()
|
public async Task<IActionResult> RetryBilling()
|
||||||
{
|
{
|
||||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
var accountId = Guid.Parse(currentUser.Id);
|
var accountId = Guid.Parse(currentUser.Id);
|
||||||
|
|
||||||
var (success, cost) = await thoughtService.RetryBillingForAccountAsync(accountId, logger);
|
var (success, cost) = await thoughtService.RetryBillingForAccountAsync(accountId, logger);
|
||||||
|
|
||||||
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." });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
@@ -78,7 +81,7 @@ public class ThoughtProvider
|
|||||||
builder.Services.AddServiceDiscovery();
|
builder.Services.AddServiceDiscovery();
|
||||||
builder.Services.AddAccountService();
|
builder.Services.AddAccountService();
|
||||||
builder.Services.AddSphereService();
|
builder.Services.AddSphereService();
|
||||||
|
|
||||||
builder.Plugins.AddFromObject(new SnAccountKernelPlugin(_accountClient));
|
builder.Plugins.AddFromObject(new SnAccountKernelPlugin(_accountClient));
|
||||||
builder.Plugins.AddFromObject(new SnPostKernelPlugin(_postClient));
|
builder.Plugins.AddFromObject(new SnPostKernelPlugin(_postClient));
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user