Skip to content

Commit 0ff80a3

Browse files
stephentoubamanda-tarafa
authored andcommitted
Address gemini feedback
1 parent 6961b1f commit 0ff80a3

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

apis/Google.Cloud.VertexAI.Extensions/Google.Cloud.VertexAI.Extensions/PredictionServiceEmbeddingGenerator.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
using Microsoft.Extensions.AI;
1818
using System;
1919
using System.Collections.Generic;
20+
using System.Linq;
2021
using System.Threading;
2122
using System.Threading.Tasks;
22-
using Value = Google.Protobuf.WellKnownTypes.Value;
2323
using Struct = Google.Protobuf.WellKnownTypes.Struct;
24+
using Value = Google.Protobuf.WellKnownTypes.Value;
2425

2526
namespace Google.Cloud.VertexAI.Extensions;
2627

@@ -70,10 +71,9 @@ public async Task<GeneratedEmbeddings<Embedding<float>>> GenerateAsync(IEnumerab
7071
// If a dimensionality is specified, add it to the parameters.
7172
if ((options?.Dimensions ?? _defaultModelDimensions) is { } outputDimensions)
7273
{
73-
(request.Parameters ??= new()).StructValue ??= new Struct
74-
{
75-
Fields = { { "outputDimensionality", Value.ForNumber(outputDimensions) } },
76-
};
74+
request.Parameters ??= new Value();
75+
request.Parameters.StructValue ??= new Struct();
76+
request.Parameters.StructValue.Fields["outputDimensionality"] = Value.ForNumber(outputDimensions);
7777
}
7878

7979
// Make the request.
@@ -97,13 +97,7 @@ public async Task<GeneratedEmbeddings<Embedding<float>>> GenerateAsync(IEnumerab
9797
{
9898
Protobuf.Collections.RepeatedField<Value> numberValues = listValue.ListValue.Values;
9999

100-
float[] embedding = new float[numberValues.Count];
101-
for (int j = 0; j < numberValues.Count; j++)
102-
{
103-
embedding[j] = (float) numberValues[j].NumberValue;
104-
}
105-
106-
result.Add(new Embedding<float>(embedding)
100+
result.Add(new Embedding<float>(numberValues.Select(v => (float) v.NumberValue).ToArray())
107101
{
108102
CreatedAt = DateTimeOffset.UtcNow,
109103
ModelId = !string.IsNullOrWhiteSpace(response.ModelVersionId) ? response.ModelVersionId : request.Endpoint,

0 commit comments

Comments
 (0)