-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feat: AI Client기능 구현 * Test: AI Client 통합테스트 작성 * build: 빌드시 테스트에서 제외해야 할 테스트 태그 추가 * Test: AI Client 단위테스트 작성 * Feat: LLMService에 AI 서버 요청 기능 추가 * Test: LLMService AI_기능_요청 메서드에 클라이언트 단위테스트 코드 추가 * Chore: 불필요한 주석 제거 * Chore: 더미 AI서버 주소 추가 * Chore: 불필요한 impl클래스 제거 및 테스트코드 수정
- Loading branch information
1 parent
780b049
commit 751e5cd
Showing
18 changed files
with
277 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package notai.client.ai; | ||
|
||
import notai.client.ai.request.LlmTaskRequest; | ||
import notai.client.ai.response.TaskResponse; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.multipart.MultipartFile; | ||
import org.springframework.web.service.annotation.PostExchange; | ||
|
||
public interface AiClient { | ||
|
||
@PostExchange(url = "/api/ai/llm") | ||
TaskResponse submitLlmTask(@RequestBody LlmTaskRequest request); | ||
|
||
@PostExchange(url = "/api/ai/stt") | ||
TaskResponse submitSttTask(@RequestPart("audio") MultipartFile audioFile); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package notai.client.ai; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import static notai.client.HttpInterfaceUtil.createHttpInterface; | ||
import notai.common.exception.type.ExternalApiException; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.HttpStatusCode; | ||
import org.springframework.web.client.RestClient; | ||
|
||
@Slf4j | ||
@Configuration | ||
public class AiClientConfig { | ||
|
||
@Value("${ai-server-url}") | ||
private String aiServerUrl; | ||
|
||
@Bean | ||
public AiClient aiClient() { | ||
RestClient restClient = | ||
RestClient.builder().baseUrl(aiServerUrl).requestInterceptor((request, body, execution) -> { | ||
request.getHeaders().setContentLength(body.length); // Content-Length 설정 안하면 411 에러 발생 | ||
return execution.execute(request, body); | ||
}).defaultStatusHandler(HttpStatusCode::isError, (request, response) -> { | ||
String responseBody = new String(response.getBody().readAllBytes()); | ||
log.error("Response Status: {}", response.getStatusCode()); | ||
throw new ExternalApiException(responseBody, response.getStatusCode().value()); | ||
}).build(); | ||
return createHttpInterface(restClient, AiClient.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package notai.client.ai.request; | ||
|
||
public record LlmTaskRequest( | ||
String ocrText, | ||
String stt, | ||
String keyboardNote | ||
) { | ||
public static LlmTaskRequest of(String ocrText, String stt, String keyboardNote) { | ||
return new LlmTaskRequest(ocrText, stt, keyboardNote); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package notai.client.ai.request; | ||
|
||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
public record SttTaskRequest( | ||
MultipartFile audioFile | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package notai.client.ai.response; | ||
|
||
import java.util.UUID; | ||
|
||
public record TaskResponse( | ||
UUID taskId, | ||
String taskType | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/test/java/notai/client/ai/AiClientIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package notai.client.ai; | ||
|
||
import notai.client.ai.request.LlmTaskRequest; | ||
import notai.client.ai.response.TaskResponse; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.mock.web.MockMultipartFile; | ||
|
||
@SpringBootTest | ||
@Tag("exclude-test") // 테스트 필요할때 주석 | ||
class AiClientIntegrationTest { | ||
|
||
@Autowired | ||
private AiClient aiClient; | ||
|
||
@Test | ||
void LLM_태스크_제출_통합_테스트() { | ||
// Given | ||
LlmTaskRequest request = LlmTaskRequest.of("OCR 텍스트", "STT 텍스트", "키보드 노트"); | ||
|
||
// When | ||
TaskResponse response = aiClient.submitLlmTask(request); | ||
|
||
// Then | ||
assertNotNull(response); | ||
assertNotNull(response.taskId()); | ||
assertEquals("llm", response.taskType()); | ||
} | ||
|
||
@Test | ||
void STT_태스크_제출_통합_테스트() { | ||
// Given | ||
MockMultipartFile audioFile = new MockMultipartFile( | ||
"audio", "test.mp3", "audio/mpeg", "test audio content".getBytes() | ||
); | ||
|
||
// When | ||
TaskResponse response = aiClient.submitSttTask(audioFile); | ||
|
||
// Then | ||
assertNotNull(response); | ||
assertNotNull(response.taskId()); | ||
assertEquals("llm", response.taskType()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package notai.client.ai; | ||
|
||
import notai.client.ai.request.LlmTaskRequest; | ||
import notai.client.ai.response.TaskResponse; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import static org.mockito.Mockito.*; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.util.UUID; | ||
|
||
class AiClientTest { | ||
|
||
@Mock | ||
private AiClient aiClient; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test | ||
void LLM_테스크_전달_테스트() { | ||
// Given | ||
LlmTaskRequest request = LlmTaskRequest.of("OCR 텍스트", "STT 텍스트", "키보드 노트"); | ||
UUID expectedTaskId = UUID.randomUUID(); | ||
TaskResponse expectedResponse = new TaskResponse(expectedTaskId, "llm"); | ||
when(aiClient.submitLlmTask(request)).thenReturn(expectedResponse); | ||
|
||
// When | ||
TaskResponse response = aiClient.submitLlmTask(request); | ||
|
||
// Then | ||
assertEquals(expectedResponse, response); | ||
verify(aiClient, times(1)).submitLlmTask(request); | ||
} | ||
|
||
@Test | ||
void STT_테스크_전달_테스트() { | ||
// Given | ||
MultipartFile mockAudioFile = mock(MultipartFile.class); | ||
UUID expectedTaskId = UUID.randomUUID(); | ||
TaskResponse expectedResponse = new TaskResponse(expectedTaskId, "stt"); | ||
when(aiClient.submitSttTask(mockAudioFile)).thenReturn(expectedResponse); | ||
|
||
// When | ||
TaskResponse response = aiClient.submitSttTask(mockAudioFile); | ||
|
||
// Then | ||
assertEquals(expectedResponse, response); | ||
verify(aiClient, times(1)).submitSttTask(mockAudioFile); | ||
} | ||
} |
Oops, something went wrong.