Skip to content

Commit

Permalink
polish openai RAG
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Jan 2, 2025
1 parent 2e8664e commit 605cff5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 31 deletions.
5 changes: 5 additions & 0 deletions rag/rag-springai-openai-llm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-tika-document-reader</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.27.1</version>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.client.ClientHttpRequestFactories;
import org.springframework.boot.web.client.ClientHttpRequestFactorySettings;
import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder;
import org.springframework.boot.web.client.RestClientCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -34,7 +33,7 @@ class ResponseHeadersModification {
RestClientCustomizer restClientCustomizer() {
return restClientBuilder -> restClientBuilder
.requestFactory(new BufferingClientHttpRequestFactory(
ClientHttpRequestFactories.get(ClientHttpRequestFactorySettings.DEFAULTS)))
ClientHttpRequestFactoryBuilder.detect().build()))
.requestInterceptor((request, body, execution) -> {
logRequest(request, body);
ClientHttpResponse response = execution.execute(request, body);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
package com.learning.ai.llmragwithspringai;

import com.learning.ai.llmragwithspringai.config.ContainersConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
public class TestLlmRagWithSpringAiApplication {

@Bean
@ServiceConnection
PostgreSQLContainer<?> pgvectorContainer() {
return new PostgreSQLContainer<>(DockerImageName.parse("pgvector/pgvector:pg17"));
}

public static void main(String[] args) {
SpringApplication.from(LlmRagWithSpringAiApplication::main)
.with(TestLlmRagWithSpringAiApplication.class)
.with(ContainersConfig.class)
.run(args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,9 @@

import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.learning.ai.llmragwithspringai.TestLlmRagWithSpringAiApplication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;

@SpringBootTest(
webEnvironment = RANDOM_PORT,
classes = {TestLlmRagWithSpringAiApplication.class})
@AutoConfigureMockMvc
public abstract class AbstractIntegrationTest {

@Autowired
protected MockMvc mockMvc;

@Autowired
protected ObjectMapper objectMapper;
}
classes = {ContainersConfig.class})
public abstract class AbstractIntegrationTest {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.learning.ai.llmragwithspringai.config;

import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
public class ContainersConfig {

@Bean
@ServiceConnection
PostgreSQLContainer<?> pgvectorContainer() {
return new PostgreSQLContainer<>(DockerImageName.parse("pgvector/pgvector:pg17"));
}
}

0 comments on commit 605cff5

Please sign in to comment.