Skip to content

Commit 6e8afba

Browse files
authored
Merge pull request #258 from hchen2020/master
Fix ChatbotUi models.
2 parents 6224a04 + 2f197c4 commit 6e8afba

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

src/Infrastructure/BotSharp.Abstraction/MLTasks/Settings/LlmModelSetting.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace BotSharp.Abstraction.MLTasks.Settings;
22

33
public class LlmModelSetting
44
{
5+
public string Id { get; set; }
56
public string Name { get; set; }
67
public string ApiKey { get; set; }
78
public string Endpoint { get; set; }

src/Plugins/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
using BotSharp.Abstraction.Conversations.Models;
1717
using Microsoft.AspNetCore.Authorization;
1818
using BotSharp.Abstraction.Agents.Enums;
19+
using BotSharp.Abstraction.MLTasks;
20+
using BotSharp.Abstraction.MLTasks.Settings;
1921

2022
namespace BotSharp.Plugin.ChatbotUI.Controllers;
2123

@@ -35,27 +37,18 @@ public ChatbotUiController(ILogger<ChatbotUiController> logger, IServiceProvider
3537
[HttpGet("/v1/models")]
3638
public OpenAiModels GetOpenAiModels()
3739
{
40+
var llm = _services.GetRequiredService<ILlmProviderService>();
41+
var models = llm.GetProviderModels("azure-openai").Where(x => x.Type == LlmModelType.Chat)
42+
.Select(x => new AiModel
43+
{
44+
Id = x.Id,
45+
Model = x.Name,
46+
Name = x.Name
47+
}).ToList();
48+
3849
return new OpenAiModels
3950
{
40-
Data = new List<AiModel>
41-
{
42-
new AiModel
43-
{
44-
Id = "gpt-3.5-turbo",
45-
Model = "gpt-3.5-turbo",
46-
Name = "GPT-3.5 Turbo",
47-
MaxLength = 4 * 1024,
48-
TokenLimit = 4 * 1024
49-
},
50-
new AiModel
51-
{
52-
Id = "gpt-4",
53-
Model = "gpt-4",
54-
Name = "GPT-4",
55-
MaxLength = 8 * 1024,
56-
TokenLimit = 8 * 1024
57-
}
58-
}
51+
Data = models,
5952
};
6053
}
6154

@@ -73,11 +66,16 @@ public async Task SendMessage([FromBody] OpenAiMessageInput input)
7366
.Select(x => new RoleDialogModel(x.Role, x.Content))
7467
.Last();
7568

69+
var llm = _services.GetRequiredService<ILlmProviderService>();
70+
var model = llm.GetProviderModels("azure-openai")
71+
.First(x => x.Type == LlmModelType.Chat && x.Id == input.Model)
72+
.Name;
73+
7674
var conv = _services.GetRequiredService<IConversationService>();
7775
conv.SetConversationId(input.ConversationId, input.States);
7876
conv.States.SetState("channel", input.Channel)
79-
.SetState("provider", input.Provider)
80-
.SetState("model", input.Model)
77+
.SetState("provider", "azure-openai")
78+
.SetState("model", model)
8179
.SetState("temperature", input.Temperature)
8280
.SetState("sampling_factor", input.SamplingFactor);
8381

0 commit comments

Comments
 (0)