Skip to content

Commit

Permalink
Merge pull request #17 from phillip-kruger/main
Browse files Browse the repository at this point in the history
Replace json-rpc with REST
  • Loading branch information
phillip-kruger authored Nov 14, 2024
2 parents 1b3da3f + 9302eca commit 6177498
Show file tree
Hide file tree
Showing 21 changed files with 161 additions and 76 deletions.
16 changes: 7 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<artifactId>chappie-server</artifactId>
<version>999-SNAPSHOT</version>

<name>Chappie Server</name>
<description>
The Chappie Server. AI for your project
</description>
Expand Down Expand Up @@ -45,17 +46,16 @@

<properties>
<compiler-plugin.version>3.13.0</compiler-plugin.version>
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.release>21</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.14.3</quarkus.platform.version>
<quarkus.platform.version>3.16.2</quarkus.platform.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.2.5</surefire-plugin.version>
<surefire-plugin.version>3.3.1</surefire-plugin.version>

<langchain4j.version>0.34.0</langchain4j.version>
<json-rpc.version>0.0.5</json-rpc.version>
<langchain4j.version>0.35.0</langchain4j.version>
</properties>

<dependencyManagement>
Expand All @@ -76,9 +76,8 @@
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.json-rpc</groupId>
<artifactId>quarkus-json-rpc</artifactId>
<version>${json-rpc.version}</version>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-jackson</artifactId>
</dependency>
<dependency>
<groupId>dev.langchain4j</groupId>
Expand All @@ -96,7 +95,6 @@
<version>${langchain4j.version}</version>
</dependency>


<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand Down
2 changes: 0 additions & 2 deletions publish.sh

This file was deleted.

8 changes: 0 additions & 8 deletions src/main/java/org/chappiebot/ChappieService.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.chappiebot;

import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.chat.request.ResponseFormat;
import dev.langchain4j.model.chat.request.json.JsonObjectSchema;
import dev.langchain4j.model.chat.request.json.JsonSchema;
import dev.langchain4j.model.ollama.OllamaChatModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;
Expand All @@ -19,12 +16,8 @@
import org.eclipse.microprofile.config.inject.ConfigProperty;

import java.time.Duration;
import java.util.Map;
import java.util.Optional;

import static dev.langchain4j.model.chat.request.ResponseFormatType.JSON;
import static dev.langchain4j.model.chat.request.json.JsonStringSchema.JSON_STRING_SCHEMA;

/**
* The Chappie Server
*
Expand All @@ -46,7 +39,6 @@ public class ChappieService {
Optional<Duration> timeout;

// OpenAI

@ConfigProperty(name = "chappie.openai.api-key")
Optional<String> openaiKey;

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/chappiebot/CommonInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.chappiebot;

public record CommonInput(String programmingLanguage,
String programmingLanguageVersion,
String product,
String productVersion) {

}
7 changes: 4 additions & 3 deletions src/main/java/org/chappiebot/doc/DocAssistant.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public interface DocAssistant {

static final String SYSTEM_MESSAGE = """
You are an AI assistant helping to add or modify {{doc}} in {{programmingLanguage}} code from a {{product}} {{version}} application.
You are an AI assistant helping to add or modify {{doc}} in {{programmingLanguage}} {{programmingLanguageVersion}} code from a {{product}} {{productVersion}} application.
You will receive the code that needs the {{doc}}. Please use that as input when considering the response.
Approach this task step-by-step, take your time and do not skip steps.
Expand All @@ -30,9 +30,10 @@ public interface DocAssistant {
Please add or modify the {{doc}} to reflect the code.
""")
public String addDoc(@V("programmingLanguage")String programmingLanguage,
public DocOutput addDoc(@V("programmingLanguage")String programmingLanguage,
@V("programmingLanguageVersion")String programmingLanguageVersion,
@V("product")String product,
@V("version")String version,
@V("productVersion")String version,
@V("extraContext")String extraContext,
@V("doc")String doc,
@V("source")String source);
Expand Down
27 changes: 16 additions & 11 deletions src/main/java/org/chappiebot/doc/DocEndpoint.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
package org.chappiebot.doc;

import io.quarkiverse.jsonrpc.runtime.api.JsonRPCApi;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.infrastructure.Infrastructure;
import jakarta.inject.Inject;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;

/**
* The JsonRPC Endpoint for doc creation
* The Endpoint for doc creation
* @author Phillip Kruger (phillip.kruger@gmail.com)
*/
@JsonRPCApi("doc")
@Path("/api/doc")
public class DocEndpoint {

@Inject
DocAssistant docAssistant;

public String addDoc(String programmingLanguage,
String product,
String version,
String extraContext,
String doc,
String source) {

return docAssistant.addDoc(programmingLanguage, product, version, extraContext, doc, source);
@POST
public Uni<DocOutput> addDoc(DocInput docInput) {
return Uni.createFrom().item(() -> docAssistant.addDoc(docInput.commonInput().programmingLanguage(),
docInput.commonInput().programmingLanguageVersion(),
docInput.commonInput().product(),
docInput.commonInput().productVersion(),
docInput.extraContext().orElse(""),
docInput.doc(), docInput.source()))
.runSubscriptionOn(Infrastructure.getDefaultWorkerPool());
}

}
10 changes: 10 additions & 0 deletions src/main/java/org/chappiebot/doc/DocInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.chappiebot.doc;

import java.util.Optional;
import org.chappiebot.CommonInput;

public record DocInput(CommonInput commonInput,
Optional<String> extraContext,
String doc,
String source){
}
4 changes: 4 additions & 0 deletions src/main/java/org/chappiebot/doc/DocOutput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.chappiebot.doc;

public record DocOutput(String sourceWithDoc){
}
21 changes: 16 additions & 5 deletions src/main/java/org/chappiebot/exception/ExceptionAssistant.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface ExceptionAssistant {

static final String SYSTEM_MESSAGE = """
# IDENTITY
You are the worlds best AI coding assistant helping to debug {{programmingLanguage}} exceptions in a {{product}} {{version}} application.
You are the worlds best AI coding assistant helping to debug {{programmingLanguage}} {{programmingLanguageVersion}} exceptions in a {{product}} {{productVersion}} application.
# STEPS
Consume the exception stacktrace.
Expand Down Expand Up @@ -73,9 +73,10 @@ public interface ExceptionAssistant {
'suggestedSource: 'String'
}
""")
public SuggestedFix suggestFix(@V("programmingLanguage")String programmingLanguage,
public ExceptionOutput suggestFix(@V("programmingLanguage")String programmingLanguage,
@V("programmingLanguageVersion")String programmingLanguageVersion,
@V("product")String product,
@V("version")String version,
@V("productVersion")String productVersion,
@V("extraContext")String extraContext,
@V("stacktrace")String stacktrace,
@V("source")String source);
Expand All @@ -90,10 +91,20 @@ public SuggestedFix suggestFix(@V("programmingLanguage")String programmingLangua
{{extraContext}}
Please help me fix it.
You must answer strictly in the following JSON format:
{
'response': 'String',
'explanation': 'String',
'diff': 'String',
'suggestedSource: 'String'
}
""")
public SuggestedFix suggestFix(@V("programmingLanguage")String programmingLanguage,
public ExceptionOutput suggestFix(@V("programmingLanguage")String programmingLanguage,
@V("programmingLanguageVersion")String programmingLanguageVersion,
@V("product")String product,
@V("version")String version,
@V("productVersion")String productVersion,
@V("extraContext")String extraContext,
@V("stacktrace")String stacktrace);

Expand Down
28 changes: 18 additions & 10 deletions src/main/java/org/chappiebot/exception/ExceptionEndpoint.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
package org.chappiebot.exception;

import io.quarkiverse.jsonrpc.runtime.api.JsonRPCApi;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.infrastructure.Infrastructure;
import jakarta.inject.Inject;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;

/**
* The JsonRPC Endpoint for exceptions
* The Endpoint for exceptions
* @author Phillip Kruger (phillip.kruger@gmail.com)
*/
@JsonRPCApi("exception")
@Path("/api/exception")
public class ExceptionEndpoint {

@Inject ExceptionAssistant exceptionAssistant;

public SuggestedFix suggestfix(String programmingLanguage,
String product,
String version,
String extraContext,
String stacktrace,
String source) {
@POST
public Uni<ExceptionOutput> suggestfix(ExceptionInput exceptionInput) {

return exceptionAssistant.suggestFix(programmingLanguage, product, version, extraContext, stacktrace, source);
return Uni.createFrom().item(() -> exceptionAssistant.suggestFix(
exceptionInput.commonInput().programmingLanguage(),
exceptionInput.commonInput().programmingLanguageVersion(),
exceptionInput.commonInput().product(),
exceptionInput.commonInput().productVersion(),
exceptionInput.extraContext().orElse(""),
exceptionInput.stacktrace(),
exceptionInput.source()))
.runSubscriptionOn(Infrastructure.getDefaultWorkerPool());
}
}
10 changes: 10 additions & 0 deletions src/main/java/org/chappiebot/exception/ExceptionInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.chappiebot.exception;

import org.chappiebot.CommonInput;
import java.util.Optional;

public record ExceptionInput(CommonInput commonInput,
Optional<String> extraContext,
String stacktrace,
String source){
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
*
* @author Phillip Kruger (phillip.kruger@gmail.com)
*/
public record SuggestedFix(String response, String explanation, String diff, String suggestedSource) {
public record ExceptionOutput(String response, String explanation, String diff, String suggestedSource) {
}
8 changes: 4 additions & 4 deletions src/main/java/org/chappiebot/explain/ExplainAssistant.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import dev.langchain4j.service.UserMessage;
import dev.langchain4j.service.V;


public interface ExplainAssistant {

static final String SYSTEM_MESSAGE = """
You are an AI assistant helping to explain source code in {{programmingLanguage}} code from a {{product}} {{version}} application.
You are an AI assistant helping to explain source code in {{programmingLanguage}} {{programmingLanguageVersion}} code from a {{product}} {{productVersion}} application.
You will receive the code that needs to be explained.
Approach this task step-by-step, take your time and do not skip steps.
Expand All @@ -28,9 +27,10 @@ public interface ExplainAssistant {
Please explain it to me.
""")
public String explain(@V("programmingLanguage")String programmingLanguage,
public ExplainOutput explain(@V("programmingLanguage")String programmingLanguage,
@V("programmingLanguageVersion")String programmingLanguageVersion,
@V("product")String product,
@V("version")String version,
@V("productVersion")String productVersion,
@V("extraContext")String extraContext,
@V("source")String source);

Expand Down
27 changes: 17 additions & 10 deletions src/main/java/org/chappiebot/explain/ExplainEndpoint.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package org.chappiebot.explain;

import dev.langchain4j.service.V;
import io.quarkiverse.jsonrpc.runtime.api.JsonRPCApi;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.infrastructure.Infrastructure;
import jakarta.inject.Inject;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;

/**
* The JsonRPC Endpoint for explanation
* The Endpoint for explanation
* @author Phillip Kruger (phillip.kruger@gmail.com)
*/
@JsonRPCApi("explanation")
@Path("/api/explanation")
public class ExplainEndpoint {

@Inject ExplainAssistant explainAssistant;

public String explain(@V("programmingLanguage")String programmingLanguage,
@V("product")String product,
@V("version")String version,
@V("extraContext")String extraContext,
@V("source")String source) {
@POST
public Uni<ExplainOutput> explain(ExplainInput explainInput) {

return explainAssistant.explain(programmingLanguage, product, version, extraContext, source);
return Uni.createFrom().item(() -> explainAssistant.explain(
explainInput.commonInput().programmingLanguage(),
explainInput.commonInput().programmingLanguageVersion(),
explainInput.commonInput().product(),
explainInput.commonInput().productVersion(),
explainInput.extraContext().orElse(""),
explainInput.source()))
.runSubscriptionOn(Infrastructure.getDefaultWorkerPool());
}
}
9 changes: 9 additions & 0 deletions src/main/java/org/chappiebot/explain/ExplainInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.chappiebot.explain;

import java.util.Optional;
import org.chappiebot.CommonInput;

public record ExplainInput(CommonInput commonInput,
Optional<String> extraContext,
String source){
}
4 changes: 4 additions & 0 deletions src/main/java/org/chappiebot/explain/ExplainOutput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.chappiebot.explain;

public record ExplainOutput(String explanation){
}
7 changes: 4 additions & 3 deletions src/main/java/org/chappiebot/test/TestAssistant.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public interface TestAssistant {

static final String SYSTEM_MESSAGE = """
You are an AI assistant helping to create Unit tests in {{programmingLanguage}} code from a {{product}} {{version}} application.
You are an AI assistant helping to create Unit tests in {{programmingLanguage}} {{programmingLanguageVersion}} code from a {{product}} {{productVersion}} application.
You will receive the code that needs a test. Please use that as input when considering the response.
Approach this task step-by-step, take your time and do not skip steps.
Expand Down Expand Up @@ -39,9 +39,10 @@ public interface TestAssistant {
Please provide a test.
""")
public SuggestedTest suggestTest(@V("programmingLanguage")String programmingLanguage,
public TestOutput suggestTest(@V("programmingLanguage")String programmingLanguage,
@V("programmingLanguageVersion")String programmingLanguageVersion,
@V("product")String product,
@V("version")String version,
@V("productVersion")String productVersion,
@V("extraContext")String extraContext,
@V("source")String source);

Expand Down
Loading

0 comments on commit 6177498

Please sign in to comment.