Skip to content

Commit 7b87046

Browse files
authored
Merge pull request #459 from hchen2020/master
Fix llm selection bug.
2 parents 19ceb94 + 2c757ac commit 7b87046

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ public interface ILlmProviderService
66
{
77
LlmModelSetting GetSetting(string provider, string model);
88
List<string> GetProviders();
9-
LlmModelSetting GetProviderModel(string provider, string id, bool multiModal = false);
9+
LlmModelSetting GetProviderModel(string provider, string id, bool? multiModal = null);
1010
List<LlmModelSetting> GetProviderModels(string provider);
1111
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static IChatCompletion GetChatCompletion(IServiceProvider services,
3636
string? provider = null,
3737
string? model = null,
3838
string? modelId = null,
39-
bool multiModal = false,
39+
bool? multiModal = null,
4040
AgentLlmConfig? agentConfig = null)
4141
{
4242
var completions = services.GetServices<IChatCompletion>();
@@ -59,7 +59,7 @@ private static (string, string) GetProviderAndModel(IServiceProvider services,
5959
string? provider = null,
6060
string? model = null,
6161
string? modelId = null,
62-
bool multiModal = false,
62+
bool? multiModal = null,
6363
AgentLlmConfig? agentConfig = null)
6464
{
6565
var agentSetting = services.GetRequiredService<AgentSettings>();
@@ -82,7 +82,7 @@ private static (string, string) GetProviderAndModel(IServiceProvider services,
8282
{
8383
var modelIdentity = state.ContainsState("model_id") ? state.GetState("model_id") : modelId;
8484
var llmProviderService = services.GetRequiredService<ILlmProviderService>();
85-
model = llmProviderService.GetProviderModel(provider, modelIdentity, multiModal)?.Name;
85+
model = llmProviderService.GetProviderModel(provider, modelIdentity, multiModal: multiModal)?.Name;
8686
}
8787
}
8888

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ public List<LlmModelSetting> GetProviderModels(string provider)
4444
?.Models ?? new List<LlmModelSetting>();
4545
}
4646

47-
public LlmModelSetting GetProviderModel(string provider, string id, bool multiModal = false)
47+
public LlmModelSetting GetProviderModel(string provider, string id, bool? multiModal = null)
4848
{
4949
var models = GetProviderModels(provider)
50-
.Where(x => x.Id == id && x.MultiModal == multiModal)
51-
.ToList();
50+
.Where(x => x.Id == id);
51+
52+
if (multiModal.HasValue)
53+
{
54+
models = models.Where(x => x.MultiModal == multiModal);
55+
}
5256

5357
var random = new Random();
5458
var index = random.Next(0, models.Count());

0 commit comments

Comments
 (0)