Я сделал это в своем 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
Программисты JAVA общаются здесь
1734084624
Anonymous
Я сделал это в своем 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());
}
}
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79277917/io-grpc-statusruntimeexception-unavailable-credentials-failed-to-obtain-metada[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия