Skip to content

Commit

Permalink
fix: generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Jul 12, 2024
1 parent 8bbec66 commit 9d0358c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public CodeGenerationController(CodeGenerationService codeGenerationService) {

@GetMapping("/test")
public String getGenerateTests(@RequestParam("url") String url,
@RequestParam(required = false) String testUrl) {
return this.codeGenerationService.generateTest(URLDecoder.decode(url, StandardCharsets.UTF_8),URLDecoder.decode(testUrl, StandardCharsets.UTF_8));
@RequestParam(name = "testUrl", required = false) String testUrl) {
return this.codeGenerationService.generateTest(URLDecoder.decode(url, StandardCharsets.UTF_8),
Optional.ofNullable(testUrl).map(myValue -> URLDecoder.decode(myValue, StandardCharsets.UTF_8)));
}

@GetMapping("/sources")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -48,16 +49,21 @@ public CodeGenerationService(GithubClient githubClient, ChatClient chatClient) {
this.chatClient = chatClient;
}

public String generateTest(String url, String testUrl) {
public String generateTest(String url, Optional<String> testUrlOpt) {
var githubSource = this.createTestSources(url, true);
var githubTestSource = this.createTestSources(testUrl, false);
var githubTestSource = testUrlOpt.map(testUrl -> this.createTestSources(testUrl, false))
.orElse(new GithubSource(null, null, List.of(), List.of()));
String contextClasses = githubSource.dependencies().stream()
.map(myGithubSource -> myGithubSource.sourceName() + ":" + System.getProperty("line.separator")
+ myGithubSource.lines().stream()
.collect(Collectors.joining(System.getProperty("line.separator"))))
.collect(Collectors.joining(System.getProperty("line.separator")));
String testExample = "Use this class as test example:" + System.getProperty("line.separator")
+ githubTestSource.lines().stream().collect(Collectors.joining(System.getProperty("line.separator")));
String testExample = Optional
.ofNullable(
githubTestSource.sourceName())
.map(x -> "Use this class as test example:" + System.getProperty("line.separator") + githubTestSource
.lines().stream().collect(Collectors.joining(System.getProperty("line.separator"))))
.orElse("");
String classToTest = githubSource.lines().stream()
.collect(Collectors.joining(System.getProperty("line.separator")));
var response = chatClient.call(new Prompt(new AssistantMessage(this.ollamaPrompt,
Expand Down

0 comments on commit 9d0358c

Please sign in to comment.