Skip to content

Commit

Permalink
feat: use full context window
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Jul 12, 2024
1 parent 733726c commit 1173eb9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package ch.xxx.aidoclibchat.usecase.service;

import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -36,6 +37,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 tests for this class:
{classToTest}
Expand All @@ -52,6 +54,7 @@ public CodeGenerationService(GithubClient githubClient, ChatClient chatClient) {
}

public String generateTest(String url, Optional<String> testUrlOpt) {
var start = Instant.now();
var githubSource = this.createTestSources(url, true);
var githubTestSource = testUrlOpt.map(testUrl -> this.createTestSources(testUrl, false))
.orElse(new GithubSource(null, null, List.of(), List.of()));
Expand All @@ -72,9 +75,11 @@ public String generateTest(String url, Optional<String> 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());
LOGGER.info("Prompt tokens: " + response.getMetadata().getUsage().getPromptTokens());
LOGGER.info("Generation tokens: " + response.getMetadata().getUsage().getGenerationTokens());
LOGGER.info("Total tokens: " + response.getMetadata().getUsage().getTotalTokens());
LOGGER.info("Time in seconds: {}", (Instant.now().toEpochMilli() - start.toEpochMilli()) / 1000);
return response.getResult().getOutput().getContent();
}

Expand Down
5 changes: 3 additions & 2 deletions backend/src/main/resources/application-ollama.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ spring.liquibase.change-log=classpath:/dbchangelog/db.changelog-master-ollama.xm

# generate code
spring.ai.ollama.chat.model=granite-code:20b
#spring.ai.ollama.chat.options.num-thread=8
#spring.ai.ollama.chat.options.keep_alive=1s
spring.ai.ollama.chat.options.num-thread=8
spring.ai.ollama.chat.options.keep_alive=1s
spring.ai.ollama.chat.options.num-ctx=8192

0 comments on commit 1173eb9

Please sign in to comment.