diff --git a/src/main/java/org/chappiebot/exception/ExceptionAssistant.java b/src/main/java/org/chappiebot/exception/ExceptionAssistant.java index dd5605f..daa5af3 100644 --- a/src/main/java/org/chappiebot/exception/ExceptionAssistant.java +++ b/src/main/java/org/chappiebot/exception/ExceptionAssistant.java @@ -33,7 +33,7 @@ public interface ExceptionAssistant { @UserMessage(""" - I have the following java exception: + I have the following {programmingLanguage} exception: ``` {stacktrace} ``` @@ -46,7 +46,7 @@ public interface ExceptionAssistant { public SuggestedFix suggestFix(String programmingLanguage, String product, String version, String stacktrace, String source); @UserMessage(""" - I have the following java exception: + I have the following {programmingLanguage} exception: ``` {stacktrace} ``` diff --git a/src/main/java/org/chappiebot/test/SuggestedTest.java b/src/main/java/org/chappiebot/test/SuggestedTest.java new file mode 100644 index 0000000..e68c2b6 --- /dev/null +++ b/src/main/java/org/chappiebot/test/SuggestedTest.java @@ -0,0 +1,9 @@ +package org.chappiebot.test; + +/** + * Contains the suggested test from AI + * + * @author Phillip Kruger (phillip.kruger@gmail.com) + */ +public record SuggestedTest(String explanation, String suggestedTestSource) { +} diff --git a/src/main/java/org/chappiebot/test/TestAssistant.java b/src/main/java/org/chappiebot/test/TestAssistant.java new file mode 100644 index 0000000..da9c45b --- /dev/null +++ b/src/main/java/org/chappiebot/test/TestAssistant.java @@ -0,0 +1,41 @@ +package org.chappiebot.test; + +import dev.langchain4j.service.SystemMessage; +import dev.langchain4j.service.UserMessage; +import io.quarkiverse.langchain4j.RegisterAiService; + +@RegisterAiService +@SystemMessage(""" + You are an AI assistant helping to create Unit tests in {programmingLanguage} code from a {product} {version} application. + You will receive the code that needs a test. + + Approach this task step-by-step, take your time and do not skip steps. + + Respond with a json file, and only a json file, that is valid, and can be parsed in {programmingLanguage}. + + You must respond in a valid JSON format. + You must not wrap JSON response in backticks, markdown, or in any other way, but return it as plain text. + The json response must contain the following fields: + - explanation + - suggestedTestSource (this must be the full source code for the test class. Note that this suggested test source should compile) + + JSON Structure: + { + 'explanation': 'String', + 'suggestedTestSource: 'String' + } + + """) +public interface TestAssistant { + + @UserMessage(""" + I have the following {programmingLanguage} class: + ``` + {source} + ``` + + Please provide a test. + """) + public SuggestedTest suggestTest(String programmingLanguage, String product, String version, String source); + +} diff --git a/src/main/java/org/chappiebot/test/TestEndpoint.java b/src/main/java/org/chappiebot/test/TestEndpoint.java new file mode 100644 index 0000000..ee77aec --- /dev/null +++ b/src/main/java/org/chappiebot/test/TestEndpoint.java @@ -0,0 +1,21 @@ +package org.chappiebot.test; + +import io.quarkiverse.jsonrpc.runtime.api.JsonRPCApi; +import jakarta.inject.Inject; +/** + * The JsonRPC Endpoint for test creation + * @author Phillip Kruger (phillip.kruger@gmail.com) + */ +@JsonRPCApi("testing") +public class TestEndpoint { + + @Inject TestAssistant testAssistant; + + public SuggestedTest suggesttest(String programmingLanguage, + String product, + String version, + String source) { + + return testAssistant.suggestTest(programmingLanguage, product, version, source); + } +}