mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-05-21 04:32:16 +00:00
Merge branch 'main' into pr/654
# Conflicts: # app/MindWork AI Studio/Provider/Google/ProviderGoogle.cs
This commit is contained in:
commit
876529f96e
@ -1,3 +0,0 @@
|
|||||||
namespace AIStudio.Provider.Google;
|
|
||||||
|
|
||||||
public readonly record struct Model(string Name, string DisplayName);
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
namespace AIStudio.Provider.Google;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A data model for the response from the model endpoint.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="Models"></param>
|
|
||||||
public readonly record struct ModelsResponse(IList<Model> Models);
|
|
||||||
@ -260,6 +260,45 @@ public class ProviderGoogle() : BaseProvider(LLMProviders.GOOGLE, "https://gener
|
|||||||
private sealed record GoogleEmbeddingResponse
|
private sealed record GoogleEmbeddingResponse
|
||||||
{
|
{
|
||||||
public List<GoogleEmbedding>? Embedding { get; set; }
|
public List<GoogleEmbedding>? Embedding { get; set; }
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var modelResponse = await response.Content.ReadFromJsonAsync<ModelsResponse>(token);
|
||||||
|
if (modelResponse == default || modelResponse.Data.Count is 0)
|
||||||
|
{
|
||||||
|
LOGGER.LogError("Google model list response did not contain a valid data array.");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return modelResponse.Data
|
||||||
|
.Where(model => !string.IsNullOrWhiteSpace(model.Id))
|
||||||
|
.Select(model => new Model(this.NormalizeModelId(model.Id), model.DisplayName))
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LOGGER.LogError("Failed to parse Google model list response: '{Message}'.", e.Message);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsEmbeddingModel(string modelId)
|
||||||
|
{
|
||||||
|
return modelId.Contains("embedding", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
modelId.Contains("embed", StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Model WithDisplayNameFallback(Model model)
|
||||||
|
{
|
||||||
|
return string.IsNullOrWhiteSpace(model.DisplayName)
|
||||||
|
? new Model(model.Id, model.Id)
|
||||||
|
: model;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string NormalizeModelId(string modelId)
|
||||||
|
{
|
||||||
|
return modelId.StartsWith("models/", StringComparison.OrdinalIgnoreCase)
|
||||||
|
? modelId["models/".Length..]
|
||||||
|
: modelId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed record GoogleEmbedding
|
private sealed record GoogleEmbedding
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user