-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from phillip-kruger/local
Local
- Loading branch information
Showing
32 changed files
with
1,112 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
deployment/src/main/java/io/quarkiverse/chappie/deployment/ChappieAvailableBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.quarkiverse.chappie.deployment; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
final public class ChappieAvailableBuildItem extends SimpleBuildItem { | ||
|
||
public ChappieAvailableBuildItem() { | ||
} | ||
} |
13 changes: 6 additions & 7 deletions
13
deployment/src/main/java/io/quarkiverse/chappie/deployment/ChappieConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
deployment/src/main/java/io/quarkiverse/chappie/deployment/ChappieDevUIProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.quarkiverse.chappie.deployment; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import io.quarkiverse.chappie.deployment.devservice.ollama.OllamaBuildItem; | ||
import io.quarkus.deployment.IsDevelopment; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.BuildSteps; | ||
import io.quarkus.devui.spi.page.CardPageBuildItem; | ||
import io.quarkus.devui.spi.page.Page; | ||
|
||
@BuildSteps(onlyIf = IsDevelopment.class) | ||
class ChappieDevUIProcessor { | ||
|
||
@BuildStep | ||
void pages(List<ChappiePageBuildItem> chappiePageBuildItems, | ||
Optional<OllamaBuildItem> ollamaBuildItem, | ||
BuildProducer<CardPageBuildItem> cardPageProducer, | ||
ChappieConfig config) { | ||
|
||
if (config.openai().apiKey().isPresent()) { | ||
configuredOpenAiPage(chappiePageBuildItems, cardPageProducer, config); | ||
} else if (ollamaBuildItem.isPresent()) { | ||
configuredOllamaPage(chappiePageBuildItems, cardPageProducer, config); | ||
} else { | ||
unconfiguredPage(cardPageProducer); | ||
} | ||
} | ||
|
||
private void configuredOpenAiPage(List<ChappiePageBuildItem> chappiePageBuildItems, | ||
BuildProducer<CardPageBuildItem> cardPageProducer, | ||
ChappieConfig config) { | ||
configuredPage(chappiePageBuildItems, cardPageProducer, "OpenAI", config.openai().modelName()); | ||
} | ||
|
||
private void configuredOllamaPage(List<ChappiePageBuildItem> chappiePageBuildItems, | ||
BuildProducer<CardPageBuildItem> cardPageProducer, | ||
ChappieConfig config) { | ||
configuredPage(chappiePageBuildItems, cardPageProducer, "Ollama", config.ollama().modelName()); | ||
} | ||
|
||
private void configuredPage(List<ChappiePageBuildItem> chappiePageBuildItems, | ||
BuildProducer<CardPageBuildItem> cardPageProducer, | ||
String llm, String modelName) { | ||
CardPageBuildItem chappieCard = new CardPageBuildItem(); | ||
chappieCard.setCustomCard("qwc-chappie-custom-card.js"); | ||
|
||
chappieCard.addBuildTimeData("llm", llm); | ||
chappieCard.addBuildTimeData("modelName", modelName); | ||
|
||
for (ChappiePageBuildItem cpbi : chappiePageBuildItems) { | ||
chappieCard.addPage(cpbi.getPageBuilder()); | ||
} | ||
|
||
cardPageProducer.produce(chappieCard); | ||
} | ||
|
||
private void unconfiguredPage(BuildProducer<CardPageBuildItem> cardPageProducer) { | ||
CardPageBuildItem chappieCard = new CardPageBuildItem(); | ||
|
||
chappieCard.addPage(Page.webComponentPageBuilder() | ||
.icon("font-awesome-solid:circle-question") | ||
.title("Configure assistant") | ||
.componentLink("qwc-chappie-unconfigured.js")); | ||
|
||
cardPageProducer.produce(chappieCard); | ||
} | ||
|
||
} |
22 changes: 0 additions & 22 deletions
22
deployment/src/main/java/io/quarkiverse/chappie/deployment/ChappieEnabled.java
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
deployment/src/main/java/io/quarkiverse/chappie/deployment/ConfiguredDevUIProcessor.java
This file was deleted.
Oops, something went wrong.
125 changes: 125 additions & 0 deletions
125
deployment/src/main/java/io/quarkiverse/chappie/deployment/ConsoleProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package io.quarkiverse.chappie.deployment; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.Supplier; | ||
|
||
import io.quarkiverse.chappie.deployment.devservice.ChappieClient; | ||
import io.quarkiverse.chappie.deployment.devservice.ChappieClientBuildItem; | ||
import io.quarkiverse.chappie.deployment.devservice.ollama.OllamaBuildItem; | ||
import io.quarkiverse.chappie.deployment.exception.LastException; | ||
import io.quarkiverse.chappie.deployment.exception.LastExceptionBuildItem; | ||
import io.quarkus.deployment.IsDevelopment; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.BuildSteps; | ||
import io.quarkus.deployment.annotations.Consume; | ||
import io.quarkus.deployment.builditem.FeatureBuildItem; | ||
import io.quarkus.deployment.console.ConsoleCommand; | ||
import io.quarkus.deployment.console.ConsoleInstalledBuildItem; | ||
import io.quarkus.deployment.console.ConsoleStateManager; | ||
import io.quarkus.deployment.dev.testing.MessageFormat; | ||
import io.quarkus.deployment.logging.LoggingDecorateBuildItem; | ||
import io.vertx.core.Vertx; | ||
|
||
/** | ||
* Main console Chappie Processor. This create a few Build Items also used by the DevUI processor | ||
* | ||
* @author Phillip Kruger ([email protected]) | ||
*/ | ||
@BuildSteps(onlyIf = IsDevelopment.class) | ||
class ConsoleProcessor { | ||
static volatile ConsoleStateManager.ConsoleContext chappieConsoleContext; | ||
|
||
@BuildStep | ||
void chappieAvailable(BuildProducer<ChappieAvailableBuildItem> chappieAvailableProducer, | ||
ChappieConfig config, | ||
Optional<OllamaBuildItem> ollamaBuildItem) { | ||
|
||
if (config.openai().apiKey().isPresent() || ollamaBuildItem.isPresent()) { | ||
chappieAvailableProducer.produce(new ChappieAvailableBuildItem()); | ||
} | ||
} | ||
|
||
@Consume(ConsoleInstalledBuildItem.class) | ||
@BuildStep | ||
void setupConsole(BuildProducer<FeatureBuildItem> featureProducer, | ||
LastExceptionBuildItem lastExceptionBuildItem, | ||
ChappieClientBuildItem chappieClientBuildItem, | ||
LoggingDecorateBuildItem loggingDecorateBuildItem, | ||
Optional<ChappieAvailableBuildItem> chappieAvailable) { | ||
|
||
if (chappieAvailable.isPresent()) { | ||
|
||
Path srcMainJava = loggingDecorateBuildItem.getSrcMainJava(); | ||
|
||
if (chappieConsoleContext == null) { | ||
chappieConsoleContext = ConsoleStateManager.INSTANCE.createContext("Assistant"); | ||
} | ||
|
||
Vertx vertx = Vertx.vertx(); | ||
chappieConsoleContext.reset( | ||
new ConsoleCommand('a', "Help with the latest exception", | ||
new ConsoleCommand.HelpState(new Supplier<String>() { | ||
@Override | ||
public String get() { | ||
return MessageFormat.RED; | ||
} | ||
}, new Supplier<String>() { | ||
@Override | ||
public String get() { | ||
LastException lastException = lastExceptionBuildItem.getLastException().get(); | ||
if (lastException == null) { | ||
return "none"; | ||
} | ||
return lastException.throwable().getMessage(); | ||
} | ||
}), new Runnable() { | ||
@Override | ||
public void run() { | ||
LastException lastException = lastExceptionBuildItem.getLastException().get(); | ||
if (lastException == null) { | ||
return; | ||
} | ||
|
||
String sourceString = SourceCodeFinder.getSourceCode(srcMainJava, | ||
lastException.stackTraceElement()); | ||
|
||
String stacktraceString = lastException.getStackTraceString(); | ||
|
||
System.out.println( | ||
"===============\nAssisting with the exception, please wait"); | ||
|
||
long timer = vertx.setPeriodic(800, id -> System.out.print(".")); | ||
|
||
ChappieClient chappieClient = chappieClientBuildItem.getChappieClient(); | ||
Object[] params = ParameterCreator.getParameters("", stacktraceString, sourceString); | ||
|
||
CompletableFuture<Object> futureResult = chappieClient.executeRPC("exception#suggestfix", | ||
params); | ||
|
||
futureResult.thenAccept(r -> { | ||
vertx.cancelTimer(timer); | ||
Map result = (Map) r; | ||
|
||
System.out.println("\n\n" + result.get("response")); | ||
System.out.println("\n\n" + result.get("explanation")); | ||
System.out.println("\n------ Diff ------ "); | ||
System.out.println("\n\n" + result.get("diff")); | ||
System.out.println("\n------ Suggested source ------ "); | ||
System.out.println("\n\n" + result.get("suggestedSource")); | ||
}).exceptionally(throwable -> { | ||
// Handle any errors | ||
System.out.println("\n\nCould not get a response from ai due the this exception:"); | ||
throwable.printStackTrace(); | ||
return null; | ||
}); | ||
} | ||
})); | ||
} | ||
|
||
featureProducer.produce(new FeatureBuildItem(Feature.FEATURE)); | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
deployment/src/main/java/io/quarkiverse/chappie/deployment/UnconfiguredDevUIProcessor.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.