Skip to content

Commit

Permalink
feat: add new model
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Jul 13, 2024
1 parent 1173eb9 commit 4a9623a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}
Expand All @@ -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;
Expand All @@ -58,7 +61,7 @@ public String generateTest(String url, Optional<String> 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"))))
Expand All @@ -75,7 +78,9 @@ 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());
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());
Expand Down
8 changes: 6 additions & 2 deletions backend/src/main/resources/application-ollama.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions runOllama.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4a9623a

Please sign in to comment.