Skip to content

Commit

Permalink
fix: ollama calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Jul 12, 2024
1 parent 9d0358c commit e183385
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
1 change: 0 additions & 1 deletion backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}
Expand Down Expand Up @@ -66,8 +68,10 @@ public String generateTest(String url, Optional<String> 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();
}

Expand Down

0 comments on commit e183385

Please sign in to comment.