From 4a9623a64986533aba08452b9646a9f401a49a95 Mon Sep 17 00:00:00 2001 From: Angular2guy Date: Sat, 13 Jul 2024 07:54:05 +0200 Subject: [PATCH] feat: add new model --- .../usecase/service/CodeGenerationService.java | 11 ++++++++--- .../src/main/resources/application-ollama.properties | 8 ++++++-- runOllama.sh | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) 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 a5cfce8..bafa63f 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 @@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory; import org.springframework.ai.chat.ChatClient; import org.springframework.ai.chat.prompt.PromptTemplate; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import ch.xxx.aidoclibchat.domain.model.dto.GithubClient; @@ -37,7 +38,7 @@ public class CodeGenerationService { 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 and implement complete tests methods. - + Generate the complete source of the test class. Generate tests for this class: {classToTest} @@ -47,6 +48,8 @@ public class CodeGenerationService { {testExample} """; + @Value("${spring.ai.ollama.chat.options.num-ctx:0}") + private Long contextWindowSize; public CodeGenerationService(GithubClient githubClient, ChatClient chatClient) { this.githubClient = githubClient; @@ -58,7 +61,7 @@ public String generateTest(String url, Optional testUrlOpt) { var githubSource = this.createTestSources(url, true); var githubTestSource = testUrlOpt.map(testUrl -> this.createTestSources(testUrl, false)) .orElse(new GithubSource(null, null, List.of(), List.of())); - String contextClasses = githubSource.dependencies().stream() + String contextClasses = githubSource.dependencies().stream().filter(x -> this.contextWindowSize >= 16 * 1024) .map(myGithubSource -> myGithubSource.sourceName() + ":" + System.getProperty("line.separator") + myGithubSource.lines().stream() .collect(Collectors.joining(System.getProperty("line.separator")))) @@ -75,7 +78,9 @@ public String generateTest(String url, Optional testUrlOpt) { 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()); - LOGGER.info(response.getResult().getOutput().getContent()); + if((Instant.now().getEpochSecond() - start.getEpochSecond()) >= 300) { + LOGGER.info(response.getResult().getOutput().getContent()); + } LOGGER.info("Prompt tokens: " + response.getMetadata().getUsage().getPromptTokens()); LOGGER.info("Generation tokens: " + response.getMetadata().getUsage().getGenerationTokens()); LOGGER.info("Total tokens: " + response.getMetadata().getUsage().getTotalTokens()); diff --git a/backend/src/main/resources/application-ollama.properties b/backend/src/main/resources/application-ollama.properties index e057ca0..9a056bb 100644 --- a/backend/src/main/resources/application-ollama.properties +++ b/backend/src/main/resources/application-ollama.properties @@ -26,7 +26,11 @@ spring.liquibase.change-log=classpath:/dbchangelog/db.changelog-master-ollama.xm #spring.ai.ollama.embedding.options.model=mxbai-embed-large:335m #test with Spring AI 1.0 # generate code -spring.ai.ollama.chat.model=granite-code:20b +#spring.ai.ollama.chat.model=granite-code:20b +#spring.ai.ollama.chat.options.num-ctx=8192 + spring.ai.ollama.chat.options.num-thread=8 spring.ai.ollama.chat.options.keep_alive=1s -spring.ai.ollama.chat.options.num-ctx=8192 + +spring.ai.ollama.chat.model=deepseek-coder-v2:16b +spring.ai.ollama.chat.options.num-ctx=65536 diff --git a/runOllama.sh b/runOllama.sh index 459bdd6..85961a8 100644 --- a/runOllama.sh +++ b/runOllama.sh @@ -9,4 +9,5 @@ docker exec -it ollama ollama run stable-beluga:13bc #docker exec -it ollama ollama run mixtral:8x7b-text-v0.1-q6_K #docker exec -it ollama ollama run llava:34b-v1.6-q6_K #docker exec -it ollama ollama run granite-code:20b +#docker exec -it ollama ollama run deepseek-coder-v2:16b #docker exec -it ollama bash \ No newline at end of file