Skip to content

Conversation

@seungwoo-project
Copy link

작업 내용 ⚒️

  • AI 프롬프트 DB로 관리

리뷰어 참고 사항 🤔

  • 없음

DDL

-- 없음

Nano2998 and others added 26 commits August 5, 2025 00:08
	1) GPT CONFIG 추가
	2) OPENAI 의존성 추가
	3) API-KEY .env로 분리
	1) GPT CONFIG 추가
	2) OPENAI 의존성 추가
	3) API-KEY .env로 분리
- GPT 관련 설정(CONFIG) 추가
- OpenAI 의존성 추가
- API KEY를 .env 파일로 분리하여 관리
- Security Config에서 ChatBot 관련 설정 임시 해제
…nd into feat/ai-chat

# Conflicts:
#	src/main/java/kr/swyp/backend/chatbot/controller/ChatController.java
#	src/main/java/kr/swyp/backend/chatbot/domain/ChatHistory.java
#	src/main/java/kr/swyp/backend/chatbot/repository/ChatHistoryRepository.java
#	src/main/java/kr/swyp/backend/chatbot/service/ChatService.java
#	src/main/java/kr/swyp/backend/chatbot/service/ChatServiceImpl.java
#	src/main/resources/application-local.yml
@gemini-code-assist
Copy link

Summary of Changes

Hello @seungwoo-project, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 PR은 백엔드 시스템에 AI 챗봇 기능을 통합하기 위한 초기 구현을 담고 있습니다. AI 프롬프트를 데이터베이스에서 관리하여 유연성을 확보하고, OpenAI API를 활용하여 사용자에게 대화형 메시지 추천 및 세션 기반의 연속적인 챗봇 경험을 제공합니다. 이를 위해 필요한 데이터 모델, 서비스 로직, API 엔드포인트 및 관련 설정들이 전반적으로 추가 및 업데이트되었습니다.

Highlights

  • AI 프롬프트 DB 관리 도입: AI 프롬프트를 데이터베이스에서 관리할 수 있도록 ChatPrompt 엔티티와 관련 리포지토리 및 서비스 로직이 추가되었습니다. 이를 통해 프롬프트의 동적인 관리 및 활성화 상태 제어가 가능해졌습니다.
  • 챗봇 핵심 기능 구현: 사용자 메시지 추천, 새로운 채팅 세션 시작, 기존 세션 대화 이어가기, 사용자 채팅 세션 목록 조회, 특정 세션 대화 기록 조회 등 챗봇의 주요 기능들이 구현되었습니다.
  • OpenAI API 연동: OpenAI API와의 연동을 위해 FeignClient 기반의 ChatClient 인터페이스와 요청/응답 DTO가 추가되었으며, 이를 통해 외부 AI 모델과의 통신이 가능해졌습니다.
  • 채팅 기록 및 세션 관리 시스템 구축: 사용자의 챗봇 대화 기록을 저장하는 ChatHistory 엔티티와 대화 세션을 관리하는 ChatSession 엔티티 및 각각의 리포지토리가 추가되어, 대화의 연속성과 이력 관리가 가능해졌습니다.
  • 빌드 및 설정 파일 업데이트: build.gradle에 Spring AI BOM이 추가되었고, .gitignoreapplication-local.yml, application-test.yml에 AI 관련 설정 파일 (application-ai.yml)이 포함되도록 업데이트되었습니다.
  • 보안 설정 및 테스트 코드 추가: 챗봇 관련 엔드포인트 (/chat/**)에 대한 접근 권한이 permitAll()로 설정되었으며, 새로 추가된 챗봇 컨트롤러와 서비스 로직에 대한 단위 및 통합 테스트 코드가 작성되었습니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@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

안녕하세요. AI 프롬프트를 DB로 관리하도록 변경하고 챗봇 기능을 구현한 PR 잘 보았습니다. 전체적으로 채팅 세션 관리, 대화 기록 저장, OpenAI 연동 등 많은 기능이 추가되었네요. 코드 구조도 계층별로 잘 분리되어 있고, 테스트 코드도 충실하게 작성해주셔서 리뷰하기 좋았습니다.

몇 가지 개선점을 제안드립니다.

  • SecurityConfig에서 채팅 관련 경로의 권한 설정을 수정하여 인증된 사용자만 접근하도록 해야 합니다. 현재 설정은 NullPointerException을 유발할 수 있는 심각한 문제입니다.
  • OpenAI API URL, 모델명, temperature 등 주요 설정값들이 코드에 하드코딩되어 있습니다. 이 값들을 application.yml 설정 파일로 옮겨 유연성을 높이는 것이 좋겠습니다.
  • messageType과 같이 정해진 문자열을 사용하는 경우, Enum을 도입하여 타입 안정성을 높이는 것을 고려해볼 수 있습니다.
  • 그 외에 매직 넘버/스트링을 상수로 대체하고, API 응답 처리 시 방어적인 코드를 추가하는 등 코드의 유지보수성과 안정성을 높일 수 있는 부분들에 대해 몇 가지 의견을 남겼습니다.

자세한 내용은 각 파일의 리뷰 코멘트를 참고해주세요. 수고하셨습니다!

.requestMatchers("/error").permitAll()
.requestMatchers("/error/**").permitAll()
.requestMatchers("/actuator/**").permitAll()
.requestMatchers("/chat/**").permitAll()

Choose a reason for hiding this comment

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

critical

/chat/** 경로에 permitAll()을 사용하면 인증되지 않은 요청도 허용됩니다. 하지만 ChatController에서는 @AuthenticationPrincipal을 사용하여 인증된 사용자 정보를 필요로 합니다. 인증되지 않은 사용자가 이 엔드포인트를 호출하면 memberDetailsnull이 되어 NullPointerException이 발생합니다. 이 경로는 인증된 사용자만 접근할 수 있도록 해야 합니다. /chat/**에 대한 규칙을 제거하여 anyRequest().authenticated() 규칙이 적용되도록 하는 것이 좋습니다.

Comment on lines +55 to +57
@Column(name = "MESSAGE_TYPE")
@Comment("메시지 타입 (USER/BOT)")
private String messageType;

Choose a reason for hiding this comment

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

medium

messageType 필드가 String으로 선언되어 있습니다. "USER", "BOT"과 같이 정해진 값만 들어가는 경우, Enum 타입을 사용하는 것이 타입 안정성을 높이고 실수를 방지하는 데 도움이 됩니다. MessageType이라는 Enum을 만들고, 필드 타입을 MessageType으로 변경한 뒤 @Enumerated(EnumType.STRING) 어노테이션을 추가하여 DB에 문자열로 저장하도록 하는 것을 권장합니다.

@Enumerated(EnumType.STRING)
@Column(name = "MESSAGE_TYPE")
@Comment("메시지 타입 (USER/BOT)")
private MessageType messageType;

이렇게 변경하면 ChatServiceImpl 등에서 문자열로 비교하던 로직도 타입 안전하게 변경할 수 있습니다.


// DB에서 프롬프트 조회
ChatPrompt prompt = chatPromptRepository
.findByPromptKeyAndIsActiveTrue("MESSAGE_EXTRACTION")

Choose a reason for hiding this comment

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

medium

프롬프트 키인 "MESSAGE_EXTRACTION"이 문자열 리터럴로 하드코딩되어 있습니다. 이러한 매직 스트링은 오타에 취약하고, 여러 곳에서 사용될 경우 유지보수가 어렵습니다. 별도의 상수 클래스나 인터페이스에 상수로 정의하여 사용하는 것을 권장합니다. 예를 들어, PromptKeys.MESSAGE_EXTRACTION과 같이 사용할 수 있습니다.

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.

4 participants