Skip to content

Commit b355839

Browse files
authored
Merge pull request #147 from hchen2020/master
Rename PackageVersion to BotSharpVersion;
2 parents 3df0565 + 73ead13 commit b355839

File tree

22 files changed

+79
-52
lines changed

22 files changed

+79
-52
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<LangVersion>10.0</LangVersion>
44
<OutputPath>..\..\..\packages</OutputPath>
5-
<PackageVersion>0.12.3</PackageVersion>
5+
<BotSharpVersion>0.13.0</BotSharpVersion>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
</PropertyGroup>
88
</Project>

src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<Nullable>enable</Nullable>
66
<LangVersion>$(LangVersion)</LangVersion>
7-
<VersionPrefix>$(PackageVersion)</VersionPrefix>
7+
<VersionPrefix>$(BotSharpVersion)</VersionPrefix>
88
<PackageIcon>Icon.png</PackageIcon>
99
<GeneratePackageOnBuild>$(GeneratePackageOnBuild)</GeneratePackageOnBuild>
1010
</PropertyGroup>

src/Infrastructure/BotSharp.Abstraction/MLTasks/IChatCompletion.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@ namespace BotSharp.Abstraction.MLTasks;
22

33
public interface IChatCompletion
44
{
5+
/// <summary>
6+
/// The LLM provider like Microsoft Azure, OpenAI, ClaudAI
7+
/// </summary>
58
string Provider { get; }
9+
10+
/// <summary>
11+
/// Set model name, one provider can consume different model or version(s)
12+
/// </summary>
13+
/// <param name="model"></param>
14+
void SetModelName(string model);
15+
616
Task<bool> GetChatCompletionsAsync(Agent agent,
717
List<RoleDialogModel> conversations,
818
Func<RoleDialogModel, Task> onMessageReceived,
919
Func<RoleDialogModel, Task> onFunctionExecuting);
1020

11-
Task<bool> GetChatCompletionsStreamingAsync(Agent agent, List<RoleDialogModel> conversations, Func<RoleDialogModel, Task> onMessageReceived);
21+
Task<bool> GetChatCompletionsStreamingAsync(Agent agent,
22+
List<RoleDialogModel> conversations,
23+
Func<RoleDialogModel, Task> onMessageReceived);
1224
}

src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<LangVersion>$(LangVersion)</LangVersion>
6-
<VersionPrefix>$(PackageVersion)</VersionPrefix>
6+
<VersionPrefix>$(BotSharpVersion)</VersionPrefix>
77
<GeneratePackageOnBuild>$(GeneratePackageOnBuild)</GeneratePackageOnBuild>
88
</PropertyGroup>
99

src/Infrastructure/BotSharp.Core/Infrastructures/CompletionProvider.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,31 @@ namespace BotSharp.Core.Infrastructures;
44

55
public class CompletionProvider
66
{
7-
public static IChatCompletion GetChatCompletion(IServiceProvider services, string? provider = null)
7+
public static IChatCompletion GetChatCompletion(IServiceProvider services, string? provider = null, string? model = null)
88
{
99
var completions = services.GetServices<IChatCompletion>();
1010

1111
var state = services.GetRequiredService<IConversationStateService>();
12+
1213
if (provider == null)
1314
{
14-
provider = state.GetState("provider", "azure-gpt-3.5");
15+
provider = state.GetState("provider", "azure-openai");
1516
}
16-
17-
return completions.FirstOrDefault(x => x.Provider == provider);
17+
18+
if (model == null)
19+
{
20+
model = state.GetState("model", "gpt-3.5-turbo");
21+
}
22+
23+
var completer = completions.FirstOrDefault(x => x.Provider == provider);
24+
if (completer == null)
25+
{
26+
var logger = services.GetRequiredService<ILogger<CompletionProvider>>();
27+
logger.LogError($"Can't resolve completion provider by {provider}");
28+
}
29+
30+
completer.SetModelName(model);
31+
32+
return completer;
1833
}
1934
}

src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<LangVersion>$(LangVersion)</LangVersion>
8-
<VersionPrefix>$(PackageVersion)</VersionPrefix>
8+
<VersionPrefix>$(BotSharpVersion)</VersionPrefix>
99
<GeneratePackageOnBuild>$(GeneratePackageOnBuild)</GeneratePackageOnBuild>
1010
</PropertyGroup>
1111

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
2323

2424
services.AddScoped<ITextCompletion, TextCompletionProvider>();
2525
services.AddScoped<IChatCompletion, ChatCompletionProvider>();
26-
services.AddScoped<IChatCompletion, GPT4CompletionProvider>();
2726
}
2827
}

src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<Nullable>enable</Nullable>
66
<LangVersion>$(LangVersion)</LangVersion>
7-
<VersionPrefix>$(PackageVersion)</VersionPrefix>
7+
<VersionPrefix>$(BotSharpVersion)</VersionPrefix>
88
<GeneratePackageOnBuild>$(GeneratePackageOnBuild)</GeneratePackageOnBuild>
99
</PropertyGroup>
1010

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ namespace BotSharp.Plugin.AzureOpenAI.Providers;
2020

2121
public class ChatCompletionProvider : IChatCompletion
2222
{
23-
protected readonly AzureOpenAiSettings _settings;
24-
protected readonly IServiceProvider _services;
25-
protected readonly ILogger _logger;
23+
private readonly AzureOpenAiSettings _settings;
24+
private readonly IServiceProvider _services;
25+
private readonly ILogger _logger;
26+
private string _model;
2627

27-
public virtual string Provider => "azure-gpt-3.5";
28+
public virtual string Provider => "azure-openai";
2829

2930
public ChatCompletionProvider(AzureOpenAiSettings settings,
3031
ILogger<ChatCompletionProvider> logger,
@@ -37,8 +38,16 @@ public ChatCompletionProvider(AzureOpenAiSettings settings,
3738

3839
protected virtual (OpenAIClient, string) GetClient()
3940
{
40-
var client = new OpenAIClient(new Uri(_settings.Endpoint), new AzureKeyCredential(_settings.ApiKey));
41-
return (client, _settings.DeploymentModel.ChatCompletionModel);
41+
if (_model == "gpt-4")
42+
{
43+
var client = new OpenAIClient(new Uri(_settings.GPT4.Endpoint), new AzureKeyCredential(_settings.GPT4.ApiKey));
44+
return (client, _settings.GPT4.DeploymentModel);
45+
}
46+
else
47+
{
48+
var client = new OpenAIClient(new Uri(_settings.Endpoint), new AzureKeyCredential(_settings.ApiKey));
49+
return (client, _settings.DeploymentModel.ChatCompletionModel);
50+
}
4251
}
4352

4453
public List<RoleDialogModel> GetChatSamples(string sampleText)
@@ -243,4 +252,9 @@ protected ChatCompletionsOptions PrepareOptions(Agent agent, List<RoleDialogMode
243252

244253
return chatCompletionsOptions;
245254
}
255+
256+
public void SetModelName(string model)
257+
{
258+
_model = model;
259+
}
246260
}

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

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)