Skip to content

Commit 2c5fa98

Browse files
committed
1 parent 7c945ac commit 2c5fa98

File tree

9 files changed

+71
-22
lines changed

9 files changed

+71
-22
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using BotSharp.Abstraction.Models;
2+
3+
namespace BotSharp.Abstraction.MLTasks;
4+
5+
public interface IChatCompletion
6+
{
7+
Task<string> GetChatCompletionsAsync(List<RoleDialogModel> conversations);
8+
}

src/Plugins/BotSharp.Plugin.AzureOpenAI/AzureOpenAiPlugin.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using BotSharp.Abstraction.MLTasks;
33
using BotSharp.Abstraction.Plugins;
44
using BotSharp.Plugin.AzureOpenAI.Providers;
5+
using BotSharp.Plugin.AzureOpenAI.Services;
6+
using BotSharp.Plugin.AzureOpenAI.Settings;
57
using Microsoft.Extensions.Configuration;
68
using Microsoft.Extensions.DependencyInjection;
79

@@ -16,6 +18,7 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
1618
services.AddSingleton(x => settings);
1719

1820
services.AddSingleton<ITextCompletion, TextCompletionProvider>();
19-
services.AddScoped<IServiceZone, ChatCompletionProvider>();
21+
services.AddScoped<IChatCompletion, ChatCompletionProvider>();
22+
services.AddScoped<IServiceZone, ChatCompletionService>();
2023
}
2124
}

src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
using Azure.AI.OpenAI;
33
using BotSharp.Abstraction.Infrastructures.ContentTransfers;
44
using BotSharp.Abstraction.Infrastructures.ContentTransmitters;
5+
using BotSharp.Abstraction.MLTasks;
56
using BotSharp.Abstraction.Models;
6-
using BotSharp.Platform.AzureAi;
7+
using BotSharp.Plugin.AzureOpenAI.Settings;
78
using System;
89
using System.Collections.Generic;
910
using System.IO;
1011
using System.Threading.Tasks;
1112

1213
namespace BotSharp.Plugin.AzureOpenAI.Providers;
13-
14-
public class ChatCompletionProvider : IServiceZone
14+
15+
public class ChatCompletionProvider : IChatCompletion
1516
{
1617
private readonly AzureOpenAiSettings _settings;
1718

@@ -26,7 +27,7 @@ public async Task GetChatCompletionsAsync(List<RoleDialogModel> conversations,
2627
var client = new OpenAIClient(new Uri(_settings.Endpoint), new AzureKeyCredential(_settings.ApiKey));
2728
var chatCompletionsOptions = PrepareOptions(conversations);
2829

29-
var response = await client.GetChatCompletionsStreamingAsync(_settings.DeploymentName, chatCompletionsOptions);
30+
var response = await client.GetChatCompletionsStreamingAsync(_settings.DeploymentModel.ChatCompletionModel, chatCompletionsOptions);
3031
using StreamingChatCompletions streaming = response.Value;
3132

3233
string content = "";
@@ -76,12 +77,12 @@ public string GetInstruction()
7677
return string.Empty;
7778
}
7879

79-
public async Task Serving(ContentContainer content)
80+
public async Task<string> GetChatCompletionsAsync(List<RoleDialogModel> conversations)
8081
{
8182
var client = new OpenAIClient(new Uri(_settings.Endpoint), new AzureKeyCredential(_settings.ApiKey));
82-
var chatCompletionsOptions = PrepareOptions(content.Conversations);
83+
var chatCompletionsOptions = PrepareOptions(conversations);
8384

84-
var response = await client.GetChatCompletionsStreamingAsync(_settings.DeploymentName, chatCompletionsOptions);
85+
var response = await client.GetChatCompletionsStreamingAsync(_settings.DeploymentModel.ChatCompletionModel, chatCompletionsOptions);
8586
using StreamingChatCompletions streaming = response.Value;
8687

8788
string output = "";
@@ -96,12 +97,7 @@ public async Task Serving(ContentContainer content)
9697
}
9798
}
9899

99-
Console.WriteLine();
100-
content.Output = new RoleDialogModel
101-
{
102-
Role = ChatRole.Assistant.ToString(),
103-
Content = output
104-
};
100+
return output;
105101
}
106102

107103
private ChatCompletionsOptions PrepareOptions(List<RoleDialogModel> conversations)

src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/TextCompletionProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using Azure.AI.OpenAI;
22
using Azure;
33
using BotSharp.Abstraction.MLTasks;
4-
using BotSharp.Platform.AzureAi;
54
using System;
65
using System.Threading.Tasks;
6+
using BotSharp.Plugin.AzureOpenAI.Settings;
77

88
namespace BotSharp.Plugin.AzureOpenAI.Providers;
99

@@ -31,7 +31,7 @@ public async Task<string> GetCompletion(string text)
3131
};
3232

3333
var response = await client.GetCompletionsAsync(
34-
deploymentOrModelName: _settings.DeploymentName,
34+
deploymentOrModelName: _settings.DeploymentModel.TextCompletionModel,
3535
completionsOptions);
3636

3737
// OpenAI
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Azure.AI.OpenAI;
2+
using BotSharp.Abstraction.Infrastructures.ContentTransfers;
3+
using BotSharp.Abstraction.Infrastructures.ContentTransmitters;
4+
using BotSharp.Abstraction.MLTasks;
5+
using BotSharp.Abstraction.Models;
6+
using System.Threading.Tasks;
7+
8+
namespace BotSharp.Plugin.AzureOpenAI.Services;
9+
10+
public class ChatCompletionService : IServiceZone
11+
{
12+
private readonly IChatCompletion _chatCompletion;
13+
14+
public ChatCompletionService(IChatCompletion chatCompletion)
15+
{
16+
_chatCompletion = chatCompletion;
17+
}
18+
19+
public async Task Serving(ContentContainer content)
20+
{
21+
var output = await _chatCompletion.GetChatCompletionsAsync(content.Conversations);
22+
23+
content.Output = new RoleDialogModel
24+
{
25+
Role = ChatRole.Assistant.ToString(),
26+
Content = output
27+
};
28+
}
29+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
namespace BotSharp.Platform.AzureAi;
1+
namespace BotSharp.Plugin.AzureOpenAI.Settings;
22

33
public class AzureOpenAiSettings
44
{
55
public string ApiKey { get; set; } = string.Empty;
66
public string Endpoint { get; set; } = string.Empty;
7-
public string DeploymentName { get; set; } = string.Empty;
7+
public DeploymentModelSetting DeploymentModel { get; set; }
8+
= new DeploymentModelSetting();
89
public string InstructionFile { get; set; } = string.Empty;
910
public string ChatSampleFile { get; set; } = string.Empty;
1011
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace BotSharp.Plugin.AzureOpenAI.Settings;
2+
3+
public class DeploymentModelSetting
4+
{
5+
public string? ChatCompletionModel { get; set; }
6+
public string? TextCompletionModel { get; set; }
7+
}

src/Plugins/BotSharp.Plugin.PaddleSharp/PaddleSharpPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public class PaddleSharpPlugin : IBotSharpPlugin
99
{
1010
public void RegisterDI(IServiceCollection services, IConfiguration config)
1111
{
12-
throw new NotImplementedException();
12+
1313
}
1414
}

src/WebStarter/appsettings.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
"Endpoint": "",
3232
"InstructionFile": "Prompts\\chat-with-bob.txt",
3333
"ChatSampleFile": "Prompts\\chat-samples.txt",
34-
"DeploymentModel": ""
34+
"DeploymentModel": {
35+
"ChatCompletionModel": "",
36+
"TextCompletionModel": ""
37+
}
3538
},
3639

3740
"MetaAi": {
@@ -62,13 +65,15 @@
6265
"BotSharp.Core",
6366
"BotSharp.Plugin.AzureOpenAI",
6467
"BotSharp.Plugin.MetaAI",
65-
"BotSharp.Plugin.Qdrant"
68+
"BotSharp.Plugin.Qdrant",
69+
"BotSharp.Plugin.PaddleSharp"
6670
],
6771
"Plugins": [
6872
// "LLamaSharpPlugin",
6973
"AzureOpenAiPlugin",
7074
"MetaAiPlugin",
71-
"QdrantPlugin"
75+
"QdrantPlugin",
76+
"PaddleSharpPlugin"
7277
]
7378
}
7479
}

0 commit comments

Comments
 (0)