diff --git a/backend/build.gradle b/backend/build.gradle index 0ff058e..0f55b05 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -40,7 +40,6 @@ dependencies { implementation 'net.javacrumbs.shedlock:shedlock-provider-jdbc-template:5.2.0' implementation 'org.springframework.ai:spring-ai-pgvector-store-spring-boot-starter:0.8.1-SNAPSHOT' implementation 'org.springframework.ai:spring-ai-transformers-spring-boot-starter:0.8.1-SNAPSHOT' - implementation 'org.apache.httpcomponents.client5:httpclient5' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' testImplementation 'com.tngtech.archunit:archunit-junit5:1.1.0' diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/adapter/config/ApplicationConfig.java b/backend/src/main/java/ch/xxx/aidoclibchat/adapter/config/ApplicationConfig.java index dd8c2e1..1539217 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/adapter/config/ApplicationConfig.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/adapter/config/ApplicationConfig.java @@ -15,13 +15,8 @@ */ package ch.xxx.aidoclibchat.adapter.config; -import org.apache.hc.client5.http.config.RequestConfig; -import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; -import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; -import org.apache.hc.core5.util.Timeout; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.web.client.RestClient; @@ -39,11 +34,6 @@ public class ApplicationConfig { @Bean public RestClient createRestClient() { - RequestConfig requestConfig = RequestConfig.custom().setResponseTimeout(Timeout.ofMilliseconds(5000)).build(); - CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build(); - var factory = new HttpComponentsClientHttpRequestFactory(httpClient); - factory.setConnectTimeout(2000); - factory.setConnectionRequestTimeout(2000); - return RestClient.builder().requestFactory(factory).build(); + return RestClient.builder().build(); } } diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/CodeGenerationService.java b/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/CodeGenerationService.java index f7e55db..a735b82 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/CodeGenerationService.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/CodeGenerationService.java @@ -21,8 +21,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.ai.chat.ChatClient; -import org.springframework.ai.chat.messages.AssistantMessage; -import org.springframework.ai.chat.prompt.Prompt; +import org.springframework.ai.chat.prompt.PromptTemplate; import org.springframework.stereotype.Service; import ch.xxx.aidoclibchat.domain.model.dto.GithubClient; @@ -34,7 +33,10 @@ public class CodeGenerationService { private final GithubClient githubClient; private final ChatClient chatClient; private final String ollamaPrompt = """ - You are an assistant to generate spring tests for the class under test. + You are an assistant to generate spring tests for the class under test. + Analyse the classes provided and generate tests for all methods. Base your tests on the test example. + Generate and implement the test methods. + Generate tests for this class: {classToTest} @@ -66,8 +68,10 @@ public String generateTest(String url, Optional testUrlOpt) { .orElse(""); String classToTest = githubSource.lines().stream() .collect(Collectors.joining(System.getProperty("line.separator"))); - var response = chatClient.call(new Prompt(new AssistantMessage(this.ollamaPrompt, - Map.of("classToTest", classToTest, "contextClasses", contextClasses, "testExample", testExample)))); + LOGGER.debug(new PromptTemplate(this.ollamaPrompt, + Map.of("classToTest", classToTest, "contextClasses", contextClasses, "testExample", testExample)).createMessage().getContent()); + var response = chatClient.call(new PromptTemplate(this.ollamaPrompt, + Map.of("classToTest", classToTest, "contextClasses", contextClasses, "testExample", testExample)).create()); return response.getResult().getOutput().getContent(); }