mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-05-20 00:32:15 +00:00
Fixed handling of Google embedding response
This commit is contained in:
parent
6d446a2ca3
commit
321e24cfce
@ -0,0 +1,37 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AIStudio.Provider.Google;
|
||||
|
||||
public sealed record GoogleEmbeddingResponse
|
||||
{
|
||||
[JsonConverter(typeof(GoogleEmbeddingListConverter))]
|
||||
public List<GoogleEmbedding>? Embedding { get; init; }
|
||||
|
||||
private sealed class GoogleEmbeddingListConverter : JsonConverter<List<GoogleEmbedding>>
|
||||
{
|
||||
public override List<GoogleEmbedding> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.StartObject)
|
||||
{
|
||||
var single = JsonSerializer.Deserialize<GoogleEmbedding>(ref reader, options);
|
||||
return single is null ? new() : new() { single };
|
||||
}
|
||||
|
||||
if (reader.TokenType == JsonTokenType.StartArray)
|
||||
{
|
||||
return JsonSerializer.Deserialize<List<GoogleEmbedding>>(ref reader, options) ?? new();
|
||||
}
|
||||
|
||||
throw new JsonException("Expected object or array for embedding.");
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, List<GoogleEmbedding> value, JsonSerializerOptions options) =>
|
||||
JsonSerializer.Serialize(writer, value, options);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record GoogleEmbedding
|
||||
{
|
||||
public List<float>? Values { get; init; }
|
||||
}
|
||||
@ -256,14 +256,4 @@ public class ProviderGoogle() : BaseProvider(LLMProviders.GOOGLE, "https://gener
|
||||
? modelId["models/".Length..]
|
||||
: modelId;
|
||||
}
|
||||
|
||||
private sealed record GoogleEmbeddingResponse
|
||||
{
|
||||
public List<GoogleEmbedding>? Embedding { get; set; }
|
||||
}
|
||||
|
||||
private sealed record GoogleEmbedding
|
||||
{
|
||||
public List<float>? Values { get; set; }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user