Я сделал это в своем Linux:
curl https://sdk.cloud.google.com | bash
source ~/.bashrc
gcloud auth application-default set-quota-project my-project-id
и все работает нормально, тем не менее у меня такая ошибка:
2024-12-13 03:47:44.390 [scheduling-1] ERROR [] c.m.service.GoogleGeminiService@simpleQuestion(62) - io.grpc.StatusRuntimeException: UNAVAILABLE: Credentials failed to obtain metadata
2024-12-13 03:47:44.391 [scheduling-1] ERROR [] c.m.s.SendMessageTask@sendMessage(150) - Cannot invoke "com.google.cloud.vertexai.api.GenerateContentResponse.getCandidatesList()" because "response
" is null
Класс:
@Service
@Transactional(readOnly = true)
@Slf4j
public class GoogleGeminiService {
static final String PROJECT_ID = "systicblanets";
static final String LOCATION = "us-central1";
static final String MODEL_NAME = "gemini-pro-vision";
public String simpleQuestion (String question) throws Exception {
// Initialize client that will be used to send requests.
// This client only needs to be created once, and can be reused for multiple requests.
try (VertexAI vertexAI = new VertexAI(PROJECT_ID, LOCATION)) {
GenerateContentResponse response = null;
GenerativeModel model = new GenerativeModel(MODEL_NAME, vertexAI);
model.setGenerationConfig(GenerationConfig.newBuilder().build());
try {
SafetySetting safetySetting = SafetySetting.newBuilder()
.build();
model.setSafetySettings(Collections.singletonList(safetySetting));
model.setSafetySettings(Collections.singletonList(safetySetting));
response = model.generateContent(question);
return ResponseHandler.getText(response);
} catch (Exception e) {
log.error(e.getMessage());
AtomicReference harmCategory = new AtomicReference(HarmCategory.UNRECOGNIZED);
response.getCandidatesList().forEach(candidate -> candidate.getSafetyRatingsList().forEach(safetyRating -> {
if (SafetyRating.HarmProbability.HIGH.equals(safetyRating.getProbability())) {
harmCategory.set(safetyRating.getCategory());
}
}));
log.error(e.getMessage() + harmCategory);
throw new Exception(harmCategory.get().name());
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... ain-metada
Io.grpc.StatusRuntimeException: НЕДОСТУПНО: учетным данным не удалось получить метаданные ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение