refactor(AI): migrate chat controllers to RestClient - #360
Merged
Merged
Conversation
Member
Author
|
🎉 This PR is included in version 1.25.6 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR modernizes outbound HTTP communication across the AI chat controllers by replacing legacy
java.net.HttpURLConnectionimplementations with Spring 6 / Boot 3RestClient. It also adopts constructor injection, programs against domain interfaces inChatbotController, and introduces comprehensive unit tests usingMockRestServiceServer.Changes
1. Modernize Outgoing HTTP Clients with
RestClientChatGptController.java:HttpURLConnection, deprecatednew URL(...), and manual byte/character stream reading with Spring's declarative, fluentRestClient.@Value) to constructor injection (RestClient.Builder,@Value("${openai.api.key:}"), and@Value("${openai.chat.api.url:}")).HttpHeaders.AUTHORIZATION),MediaType.APPLICATION_JSON, and.retrieve().body(String.class).AWSBedrockController.java:@Autowired Environment appPropertieswith constructor injection alongsideRestClient.Builder.HttpURLConnectionboilerplate withRestClient.post().produces = "application/json;charset=UTF-8"to@PostMappingfor consistency.2. Interface Decoupling in
ChatbotController.java/chats/{run}/{workgroup}/**endpoints to bind to domain interfaces (Run,Workgroup) rather than concrete implementation classes (RunImpl,WorkgroupImpl).3. Unit Test Coverage
ChatGptControllerTest.java:MockRestServiceServer.Authorization: Bearer <key>header, JSON content-type, and payload matching.openai.api.keyis missing or null.AWSBedrockControllerTest.java:{aws.bedrock.runtime.endpoint}/openai/v1/chat/completions.aws.bedrock.api.keyand missingaws.bedrock.runtime.endpoint.Affected Files
src/main/java/org/wise/portal/presentation/web/AWSBedrockController.javasrc/main/java/org/wise/portal/presentation/web/controllers/ChatGptController.javasrc/main/java/org/wise/portal/presentation/web/controllers/ChatbotController.javasrc/test/java/org/wise/portal/presentation/web/AWSBedrockControllerTest.javasrc/test/java/org/wise/portal/presentation/web/controllers/ChatGptControllerTest.javaVerification
mvn compileandmvn test-compilebuilt with zero errors.ChatGptControllerTest,AWSBedrockControllerTest,ChatTest,ChatMessageTest, andCRaterServiceTestpassed successfully.