Skip to content

[fix] Gemini 모델 gemini-2.0-flash로 업데이트#115

Merged
k3vin7 merged 1 commit intomainfrom
fix/gemini-model-update
Mar 27, 2026
Merged

[fix] Gemini 모델 gemini-2.0-flash로 업데이트#115
k3vin7 merged 1 commit intomainfrom
fix/gemini-model-update

Conversation

@k3vin7
Copy link
Copy Markdown
Contributor

@k3vin7 k3vin7 commented Mar 27, 2026

gemini-1.5-flash 404 에러 → gemini-2.0-flash로 변경

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Gemini model version from 1.5-flash to 2.0-flash in the GeminiClient. The review feedback suggests refactoring the client to externalize the model name into a configuration file for better maintainability and recommends passing the API key via an HTTP header instead of a query parameter to enhance security.


private static final String GEMINI_URL =
"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent";
"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

모델 이름(gemini-2.0-flash)이 URL에 하드코딩되어 있습니다. 이번 PR의 계기가 된 것처럼 모델 이름은 변경될 수 있으므로, application.properties와 같은 설정 파일에서 관리하는 것이 유지보수 측면에서 더 좋습니다. 이렇게 하면 코드 변경 및 재배포 없이 모델을 업데이트할 수 있습니다.

더불어, 현재 API 키가 URL의 쿼리 파라미터로 전달되고 있습니다. 이 방식은 서버 로그, 브라우저 히스토리 등에 API 키가 노출될 수 있어 보안상 권장되지 않습니다. Gemini API는 x-goog-api-key HTTP 헤더를 지원하므로, 이를 사용하는 것이 더 안전합니다.

아래와 같이 리팩토링하는 것을 제안합니다.

// application.properties
gemini.model=gemini-2.0-flash

// GeminiClient.java
@Component
public class GeminiClient {
    private static final String GEMINI_URL_FORMAT = "https://generativelanguage.googleapis.com/v1beta/models/%s:generateContent";
    private final RestClient restClient;
    private final String apiKey;
    private final String geminiUrl;

    public GeminiClient(@Value("${gemini.api-key:}") String apiKey,
                        @Value("${gemini.model}") String model) {
        this.apiKey = apiKey;
        this.restClient = RestClient.create();
        this.geminiUrl = String.format(GEMINI_URL_FORMAT, model);
    }

    public String generateComment(String systemInstruction, String userPrompt) {
        // ...
        try {
            Map<?, ?> response = restClient.post()
                    .uri(geminiUrl)
                    .header("x-goog-api-key", apiKey)
                    .header("Content-Type", "application/json")
                    .body(requestBody)
                    .retrieve()
                    .body(Map.class);

            return extractText(response);
        } // ...
    }
    // ...
}

이 변경을 적용하면 코드의 유연성과 보안이 모두 향상됩니다.

@k3vin7 k3vin7 merged commit 94cf742 into main Mar 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant