44 lines
1.4 KiB
Java
44 lines
1.4 KiB
Java
/*
|
|
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
|
|
* Your use of it is subject to your agreement with Google.
|
|
*/
|
|
|
|
package com.example.config;
|
|
|
|
import com.google.genai.Client;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import java.io.IOException;
|
|
|
|
/**
|
|
* Spring configuration class for initializing the Google Gen AI Client.
|
|
* It uses properties from the application's configuration to create a
|
|
* singleton `Client` bean for interacting with the Gemini model, ensuring
|
|
* proper resource management by specifying a destroy method.
|
|
*/
|
|
@Configuration
|
|
public class GeminiConfig {
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(GeminiConfig.class);
|
|
|
|
@Value("${google.cloud.project}")
|
|
private String projectId;
|
|
|
|
@Value("${google.cloud.location}")
|
|
private String location;
|
|
|
|
@Bean(destroyMethod = "close")
|
|
public Client geminiClient() throws IOException {
|
|
logger.info("Initializing Google Gen AI Client. Project: {}, Location: {}", projectId, location);
|
|
return Client.builder()
|
|
.project(projectId)
|
|
.location(location)
|
|
.vertexAI(true)
|
|
.build();
|
|
}
|
|
|
|
} |