Google.Protobuf.JsonFormatter fails when formatting PredictResponse to JSON

97 views Asked by At

We use Google.Cloud.AIPlatform.V1 (v 2.19.0) library for making calls to Vertex AI in .NET application Here is an example of how we use it:

var builder = new PredictionServiceClientBuilder
{
    Endpoint = _settings.Endpoint,
    CredentialsPath = _credentialsFile
};

PredictionServiceClient predictionServiceClient = await builder.BuildAsync(cancellationToken);

EndpointName endpointName = EndpointName.FromProjectLocationPublisherModel(_settings.ProjectId, _settings.LocationId, _settings.Publisher, request.Model);

PredictResponse response = await predictionServiceClient.PredictAsync(endpointName, request.Instances, request.Parameters, cancellationToken);

var formatter = new JsonFormatter(JsonFormatter.Settings.Default);
string json = formatter.Format(response);

PredictAsync method returns a protobuf object which we format into JSON using Google.Protobuf.JsonFormatter It had been working well till the middle of this week but now we receive an error when we call formatter.Format(response) The error says: System.InvalidOperationException: 'Value message must contain a value for the oneof.'

We have not changed anything recently and we wonder what is the root cause of this error. How can we transform the protobuf object to JSON in other ways?

Call to text-biason works well, it cannot format protobuf object in JSON only when we call chat-biason model Input data:

Instances: {{ "messages": [ { "author": "user", "content": "who are you?" } ] }}
Parameters: {{ "candidateCount": 1, "maxOutputTokens": 100, "temperature": 0, "topP": 1 }}
Endpoint: projects/<projectName>/locations/us-central1/publishers/google/models/chat-bison

I tried to format protobuf object into JSON, but now it fails with an error: System.InvalidOperationException: 'Value message must contain a value for the oneof.' Also, I tried to call ToString method on the protobuf object, but it uses the JsonFormatter under the hood, so it fails as well.

string json = response.ToString();
0

There are 0 answers