Code: Select all
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/protobuf/MapFieldReflectionAccessor
Ich habe verschiedene Versionen der Abhängigkeiten ausprobiert, aber es funktioniert nicht.package com.multi_turn
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.google.cloud.aiplatform.v1.EndpointName;
import com.google.cloud.aiplatform.v1.PredictResponse;
import com.google.cloud.aiplatform.v1.PredictionServiceClient;
import com.google.cloud.aiplatform.v1.PredictionServiceSettings;
import com.google.protobuf.Value;
/*import com.google.cloud.aiplatform.v1.Value;*/
import com.google.protobuf.util.JsonFormat;
public class PredictTextPromptSample {
public static void main(String[] args) throws IOException {
String instance = "{ \"prompt\": " + "\"Give me ten interview questions for the role of program manager.\"}";
System.out.println("Instance: " + instance);
String parameters = "{\n" + " \"temperature\": 0.2,\n" + " \"maxOutputTokens\": 256,\n"
+ " \"topP\": 0.95,\n" + " \"topK\": 40\n" + "}";
String project = "repl-template-test";
String location = "us-central1";
String publisher = "google";
String model = "text-bison@001";
predictTextPrompt(instance, parameters, project, location, publisher, model);
}
public static void predictTextPrompt(String instance, String parameters, String project, String location,
String publisher, String model) throws IOException {
String endpoint = String.format("%s-aiplatform.googleapis.com:443", location);
PredictionServiceSettings predictionServiceSettings = PredictionServiceSettings.newBuilder()
.setEndpoint(endpoint).build();
try {
PredictionServiceClient client = PredictionServiceClient.create(predictionServiceSettings);
final EndpointName endPointName = EndpointName.ofProjectLocationPublisherModelName(project, location,
publisher, model);
Value.Builder instanceValue = Value.newBuilder();
JsonFormat.parser().merge(parameters, instanceValue);
List instances = new ArrayList();
instances.add(instanceValue.build());
Value.Builder parameterValueBuilder = Value.newBuilder();
JsonFormat.parser().merge(parameters, parameterValueBuilder);
Value parameterValue = parameterValueBuilder.build();
PredictResponse predictResponse = client.predict(endPointName, instances, parameterValue);
System.out.println(predictResponse);
} catch (Exception e) {
// TODO: handle exception
}
}
}
< /code>
4.0.0
multi-turn_replit
vertex.ai
jar
0.0.1-SNAPSHOT
vertex.ai
http://maven.apache.org
junit
junit
4.13.2
test
com.google.cloud
google-cloud-aiplatform
3.47.0
com.google.protobuf
protobuf-java
3.21.12
maven-central
Maven Central
https://repo1.maven.org/maven2/
< /code>
Ich sollte die Antwort von Vertex AI anstelle des Fehlers erhalten, den ich bekomme. Es scheint, dass es ein Kompatibilitätsproblem der Versionen von Protobuf-Java und Google-Cloud-Diplattform gibt, aber ich bin mir nicht sicher, was ich tun soll.