Fix llm selection bug.

This commit is contained in:
Haiping Chen 2024-05-16 16:32:58 -05:00
parent d02b16d4d7
commit 57122f7833
3 changed files with 11 additions and 7 deletions

View file

@ -6,6 +6,6 @@ public interface ILlmProviderService
{ {
LlmModelSetting GetSetting(string provider, string model); LlmModelSetting GetSetting(string provider, string model);
List<string> GetProviders(); List<string> GetProviders();
LlmModelSetting GetProviderModel(string provider, string id, bool multiModal = false); LlmModelSetting GetProviderModel(string provider, string id, bool? multiModal = null);
List<LlmModelSetting> GetProviderModels(string provider); List<LlmModelSetting> GetProviderModels(string provider);
} }

View file

@ -36,7 +36,7 @@ public class CompletionProvider
string? provider = null, string? provider = null,
string? model = null, string? model = null,
string? modelId = null, string? modelId = null,
bool multiModal = false, bool? multiModal = null,
AgentLlmConfig? agentConfig = null) AgentLlmConfig? agentConfig = null)
{ {
var completions = services.GetServices<IChatCompletion>(); var completions = services.GetServices<IChatCompletion>();
@ -59,7 +59,7 @@ public class CompletionProvider
string? provider = null, string? provider = null,
string? model = null, string? model = null,
string? modelId = null, string? modelId = null,
bool multiModal = false, bool? multiModal = null,
AgentLlmConfig? agentConfig = null) AgentLlmConfig? agentConfig = null)
{ {
var agentSetting = services.GetRequiredService<AgentSettings>(); var agentSetting = services.GetRequiredService<AgentSettings>();
@ -82,7 +82,7 @@ public class CompletionProvider
{ {
var modelIdentity = state.ContainsState("model_id") ? state.GetState("model_id") : modelId; var modelIdentity = state.ContainsState("model_id") ? state.GetState("model_id") : modelId;
var llmProviderService = services.GetRequiredService<ILlmProviderService>(); var llmProviderService = services.GetRequiredService<ILlmProviderService>();
model = llmProviderService.GetProviderModel(provider, modelIdentity, multiModal)?.Name; model = llmProviderService.GetProviderModel(provider, modelIdentity, multiModal: multiModal)?.Name;
} }
} }

View file

@ -44,11 +44,15 @@ public class LlmProviderService : ILlmProviderService
?.Models ?? new List<LlmModelSetting>(); ?.Models ?? new List<LlmModelSetting>();
} }
public LlmModelSetting GetProviderModel(string provider, string id, bool multiModal = false) public LlmModelSetting GetProviderModel(string provider, string id, bool? multiModal = null)
{ {
var models = GetProviderModels(provider) var models = GetProviderModels(provider)
.Where(x => x.Id == id && x.MultiModal == multiModal) .Where(x => x.Id == id);
.ToList();
if (multiModal.HasValue)
{
models = models.Where(x => x.MultiModal == multiModal);
}
var random = new Random(); var random = new Random();
var index = random.Next(0, models.Count()); var index = random.Next(0, models.Count());