12
12
*/
13
13
package ch .xxx .aidoclibchat .usecase .service ;
14
14
15
+ import java .time .Instant ;
15
16
import java .util .List ;
16
17
import java .util .Map ;
17
18
import java .util .Optional ;
@@ -36,6 +37,7 @@ public class CodeGenerationService {
36
37
You are an assistant to generate spring tests for the class under test.
37
38
Analyse the classes provided and generate tests for all methods. Base your tests on the test example.
38
39
Generate and implement the test methods. Generate and implement complete tests methods.
40
+
39
41
40
42
Generate tests for this class:
41
43
{classToTest}
@@ -52,6 +54,7 @@ public CodeGenerationService(GithubClient githubClient, ChatClient chatClient) {
52
54
}
53
55
54
56
public String generateTest (String url , Optional <String > testUrlOpt ) {
57
+ var start = Instant .now ();
55
58
var githubSource = this .createTestSources (url , true );
56
59
var githubTestSource = testUrlOpt .map (testUrl -> this .createTestSources (testUrl , false ))
57
60
.orElse (new GithubSource (null , null , List .of (), List .of ()));
@@ -72,9 +75,11 @@ public String generateTest(String url, Optional<String> testUrlOpt) {
72
75
Map .of ("classToTest" , classToTest , "contextClasses" , contextClasses , "testExample" , testExample )).createMessage ().getContent ());
73
76
var response = chatClient .call (new PromptTemplate (this .ollamaPrompt ,
74
77
Map .of ("classToTest" , classToTest , "contextClasses" , contextClasses , "testExample" , testExample )).create ());
78
+ LOGGER .info (response .getResult ().getOutput ().getContent ());
75
79
LOGGER .info ("Prompt tokens: " + response .getMetadata ().getUsage ().getPromptTokens ());
76
80
LOGGER .info ("Generation tokens: " + response .getMetadata ().getUsage ().getGenerationTokens ());
77
81
LOGGER .info ("Total tokens: " + response .getMetadata ().getUsage ().getTotalTokens ());
82
+ LOGGER .info ("Time in seconds: {}" , (Instant .now ().toEpochMilli () - start .toEpochMilli ()) / 1000 );
78
83
return response .getResult ().getOutput ().getContent ();
79
84
}
80
85
0 commit comments