From 972981b6d252cf20b7467dfae0fbdc0d17a14181 Mon Sep 17 00:00:00 2001 From: su080915 Date: Mon, 26 Aug 2024 22:31:50 +0900 Subject: [PATCH] feat :: ai --- crescendo-server/build.gradle | 3 ++- .../domain/ai/controller/AiController.java | 21 +++++++++++++++++++ .../config/security/SecurityConfig.java | 2 +- .../src/main/resources/application.yml | 16 +++++++------- 4 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 crescendo-server/src/main/java/com/example/crescendoserver/domain/ai/controller/AiController.java diff --git a/crescendo-server/build.gradle b/crescendo-server/build.gradle index a6c8520..8133571 100644 --- a/crescendo-server/build.gradle +++ b/crescendo-server/build.gradle @@ -21,6 +21,7 @@ configurations { repositories { mavenCentral() + maven {url 'https://repo.spring.io/snapshot'} //스냅샷 저장소 추가 } dependencies { @@ -57,7 +58,7 @@ dependencies { testRuntimeOnly 'org.junit.platform:junit-platform-launcher' // spring AI -// implementation 'org.springframework.ai:spring-ai-openai-spring-boot-starter:1.0.0-SNAPSHOT' + implementation 'org.springframework.ai:spring-ai-openai-spring-boot-starter:1.0.0-SNAPSHOT' // 소켓 통신 // implementation 'org.springframework.boot:spring-boot-starter-websocket' diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/domain/ai/controller/AiController.java b/crescendo-server/src/main/java/com/example/crescendoserver/domain/ai/controller/AiController.java new file mode 100644 index 0000000..a53abc6 --- /dev/null +++ b/crescendo-server/src/main/java/com/example/crescendoserver/domain/ai/controller/AiController.java @@ -0,0 +1,21 @@ +package com.example.crescendoserver.domain.ai.controller; + +import lombok.RequiredArgsConstructor; +import org.springframework.ai.openai.OpenAiChatModel; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RequestMapping("/ai") +@RestController +@RequiredArgsConstructor +public class AiController { + private final OpenAiChatModel openAiChatModel; + + @GetMapping("/chat") + public String chat(@RequestParam String message) { + return openAiChatModel.call(String.valueOf(message)); + } + +} \ No newline at end of file diff --git a/crescendo-server/src/main/java/com/example/crescendoserver/global/config/security/SecurityConfig.java b/crescendo-server/src/main/java/com/example/crescendoserver/global/config/security/SecurityConfig.java index d8158d0..8ded9ca 100644 --- a/crescendo-server/src/main/java/com/example/crescendoserver/global/config/security/SecurityConfig.java +++ b/crescendo-server/src/main/java/com/example/crescendoserver/global/config/security/SecurityConfig.java @@ -49,7 +49,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .requestMatchers(HttpMethod.POST, "/auth/signup", "/auth/login", "/auth/reissue").anonymous() .requestMatchers(HttpMethod.GET, "/auth/me").authenticated() .requestMatchers(HttpMethod.GET, "/swagger-ui/**", "/v3/api-docs/**").permitAll() - .requestMatchers(HttpMethod.GET, "/api/chat").permitAll() + .requestMatchers(HttpMethod.GET, "/ai/chat").permitAll() .requestMatchers(HttpMethod.POST, "/ws/chat").permitAll() .requestMatchers(HttpMethod.GET, "/ws/chat").permitAll() .requestMatchers(HttpMethod.POST, "/chat").permitAll() diff --git a/crescendo-server/src/main/resources/application.yml b/crescendo-server/src/main/resources/application.yml index 478a5e6..f0ca524 100644 --- a/crescendo-server/src/main/resources/application.yml +++ b/crescendo-server/src/main/resources/application.yml @@ -12,14 +12,14 @@ spring: # dialect: org.hibernate.dialect.PostgreSQLDialect show-sql: true hibernate: - ddl-auto: update + ddl-auto: create -#ai: -# openai: -# api-key: ${CHATGPT_API_KEY} -# chat: -# options: -# model: gpt-3.5-turbo +ai: + openai: + api-key: ${CHATGPT_API_KEY} + chat: + options: + model: gpt-3.5-turbo redis: @@ -28,7 +28,7 @@ redis: password: 3333 jwt: - secret-key: c2lsdmVybmluZS10ZWNoLXNwcmluZy1ib290LWp3dC10dXRvcmlhbC1zZWNyZXQtc2lsdmVybmluZS10ZWNoLXNwcmluZy1ib290LWp3dC10dXRvcmlhbC1zZWNyZXQK + secret-key: ${SECRET_KEY} access-token-expiration: 300000 # 5m refresh-token-expiration: 86400000 # 24h