From 7bc76b5c7b209b9e0ac1ee14e0a40b5e06687cea Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Thu, 28 Mar 2024 09:06:48 +0000 Subject: [PATCH] feat : removes unnecessary configuration --- .../config/ResponseHeadersModification.java | 64 ------------------- .../config/SwaggerConfig.java | 2 +- 2 files changed, 1 insertion(+), 65 deletions(-) delete mode 100644 rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/config/ResponseHeadersModification.java diff --git a/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/config/ResponseHeadersModification.java b/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/config/ResponseHeadersModification.java deleted file mode 100644 index c808f4a..0000000 --- a/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/config/ResponseHeadersModification.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.learning.ai.llmragwithspringai.config; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Collections; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatusCode; -import org.springframework.http.MediaType; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; -import org.springframework.web.client.RestClient; - -@Configuration(proxyBeanMethods = false) -@ConditionalOnProperty(value = "spring.ai.openai.api-key", havingValue = "demo") -public class ResponseHeadersModification { - - @Bean - RestClient.Builder restClientBuilder() { - return RestClient.builder().requestInterceptor((request, body, execution) -> { - ClientHttpResponse response = execution.execute(request, body); - return new CustomClientHttpResponse(response); - }); - } - - private static class CustomClientHttpResponse implements ClientHttpResponse { - - private final ClientHttpResponse originalResponse; - private final HttpHeaders headers; - - public CustomClientHttpResponse(ClientHttpResponse originalResponse) { - this.originalResponse = originalResponse; - MultiValueMap modifiedHeaders = new LinkedMultiValueMap<>(originalResponse.getHeaders()); - modifiedHeaders.put(HttpHeaders.CONTENT_TYPE, Collections.singletonList(MediaType.APPLICATION_JSON_VALUE)); - this.headers = new HttpHeaders(modifiedHeaders); - } - - @Override - public HttpStatusCode getStatusCode() throws IOException { - return originalResponse.getStatusCode(); - } - - @Override - public String getStatusText() throws IOException { - return originalResponse.getStatusText(); - } - - @Override - public void close() {} - - @Override - public InputStream getBody() throws IOException { - return originalResponse.getBody(); - } - - @Override - public HttpHeaders getHeaders() { - return headers; - } - } -} diff --git a/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/config/SwaggerConfig.java b/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/config/SwaggerConfig.java index e5541d6..426d3e4 100644 --- a/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/config/SwaggerConfig.java +++ b/rag-springai-ollama-llm/src/main/java/com/learning/ai/llmragwithspringai/config/SwaggerConfig.java @@ -6,5 +6,5 @@ import org.springframework.context.annotation.Configuration; @Configuration(proxyBeanMethods = false) -@OpenAPIDefinition(info = @Info(title = "llm-rag-with-springai", version = "v1.0.0"), servers = @Server(url = "/")) +@OpenAPIDefinition(info = @Info(title = "rag-springai-ollama-llm", version = "v1.0.0"), servers = @Server(url = "/")) public class SwaggerConfig {}