-
Notifications
You must be signed in to change notification settings - Fork 20
Add GUI Chatbox for GPULlama3.java Inference #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
svntax
wants to merge
20
commits into
beehive-lab:main
Choose a base branch
from
svntax:feat/gui-chatbox
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4f2598f
Add JavaFX dependencies and set up main class.
svntax e00486e
Set up MVCI framework for the GUI chatbox.
svntax f65a1f6
Implement run inference button.
svntax 44c9750
Implement Browse button for Llama3 path.
svntax a0ce181
Implement Reload button for scanning for model files.
svntax f21cec1
Change output text area to autoscroll to the bottom.
svntax a281461
Change buttons to be disabled while inference is running.
svntax ad22925
Adjust buttons, labels, and container nodes for GUI chatbox.
svntax 7c29d68
Add AtlantaFX for new theme styles.
svntax c43f7a9
Decrease padding between left and right panels.
svntax bed9b66
Remove unused import
svntax eb454a7
Remove the need for setting Llama3 path.
svntax f1b565f
Modify LlamaApp and llama-tornado to support GUI mode.
svntax 03ee28c
Refactor chatbox interactor to run models directly.
svntax bc43b28
Fix width for engine dropdown menu and remove unused import.
svntax d381457
Add dropdown menu for chat mode selection.
svntax 6937602
Change USE_TORNADOVM flag into a regular member variable.
svntax 2e2408f
Implement interactive mode for GUI chatbox.
svntax 480336e
Disable GUI controls while an interactive chat is running.
svntax b898006
Merge branch 'main' of https://github.com/svntax/GPULlama3.java into …
svntax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,36 @@ | ||
package com.example.gui; | ||
|
||
import javafx.concurrent.Task; | ||
import javafx.scene.layout.Region; | ||
|
||
public class ChatboxController { | ||
|
||
private final ChatboxViewBuilder viewBuilder; | ||
private final ChatboxInteractor interactor; | ||
|
||
public ChatboxController() { | ||
ChatboxModel model = new ChatboxModel(); | ||
interactor = new ChatboxInteractor(model); | ||
viewBuilder = new ChatboxViewBuilder(model, this::runInference); | ||
} | ||
|
||
private void runInference(Runnable postRunAction) { | ||
Task<Void> inferenceTask = new Task<>() { | ||
@Override | ||
protected Void call() { | ||
interactor.runLlamaTornado(); | ||
return null; | ||
} | ||
}; | ||
inferenceTask.setOnSucceeded(evt -> { | ||
postRunAction.run(); | ||
}); | ||
Thread inferenceThread = new Thread(inferenceTask); | ||
inferenceThread.start(); | ||
} | ||
|
||
public Region getView() { | ||
return viewBuilder.build(); | ||
} | ||
|
||
} |
This file contains hidden or 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,89 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
package com.example.gui; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
import java.io.BufferedReader; | ||||||||||||||||||||||||||||||||||||||||||||||||
import java.io.IOException; | ||||||||||||||||||||||||||||||||||||||||||||||||
import java.io.InputStreamReader; | ||||||||||||||||||||||||||||||||||||||||||||||||
import java.util.ArrayList; | ||||||||||||||||||||||||||||||||||||||||||||||||
import java.util.Arrays; | ||||||||||||||||||||||||||||||||||||||||||||||||
import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
public class ChatboxInteractor { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
private final ChatboxModel model; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
public ChatboxInteractor(ChatboxModel viewModel) { | ||||||||||||||||||||||||||||||||||||||||||||||||
this.model = viewModel; | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
// Run the 'llama-tornado' script in the given Llama3 path, and stream its output to the GUI's output area. | ||||||||||||||||||||||||||||||||||||||||||||||||
public void runLlamaTornado() { | ||||||||||||||||||||||||||||||||||||||||||||||||
List<String> commands = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
String llama3Path = model.getLlama3Path(); | ||||||||||||||||||||||||||||||||||||||||||||||||
if (llama3Path == null || llama3Path.isEmpty()) { | ||||||||||||||||||||||||||||||||||||||||||||||||
model.setOutputText("Please set the Llama3 path:"); | ||||||||||||||||||||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
// Format for running 'llama-tornado' depends on the operating system. | ||||||||||||||||||||||||||||||||||||||||||||||||
if (System.getProperty("os.name").startsWith("Windows")) { | ||||||||||||||||||||||||||||||||||||||||||||||||
commands.add(String.format("%s\\external\\tornadovm\\.venv\\Scripts\\python", llama3Path)); | ||||||||||||||||||||||||||||||||||||||||||||||||
commands.add("llama-tornado"); | ||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||
commands.add(String.format("%s/.llama-tornado", llama3Path)); | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
ChatboxModel.Engine engine = model.getSelectedEngine(); | ||||||||||||||||||||||||||||||||||||||||||||||||
if (engine == ChatboxModel.Engine.TORNADO_VM) { | ||||||||||||||||||||||||||||||||||||||||||||||||
commands.add("--gpu"); | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
// Assume that models are found in a /models directory. | ||||||||||||||||||||||||||||||||||||||||||||||||
String selectedModel = model.getSelectedModel(); | ||||||||||||||||||||||||||||||||||||||||||||||||
if (selectedModel == null || selectedModel.isEmpty()) { | ||||||||||||||||||||||||||||||||||||||||||||||||
model.setOutputText("Please select a model."); | ||||||||||||||||||||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
String modelPath = String.format("%s/models/%s", llama3Path, selectedModel); | ||||||||||||||||||||||||||||||||||||||||||||||||
String prompt = String.format("\"%s\"", model.getPromptText()); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
commands.addAll(Arrays.asList( | ||||||||||||||||||||||||||||||||||||||||||||||||
"--model", modelPath, | ||||||||||||||||||||||||||||||||||||||||||||||||
"--prompt", prompt | ||||||||||||||||||||||||||||||||||||||||||||||||
)); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
ProcessBuilder processBuilder = new ProcessBuilder(commands); | ||||||||||||||||||||||||||||||||||||||||||||||||
processBuilder.redirectErrorStream(true); | ||||||||||||||||||||||||||||||||||||||||||||||||
BufferedReader bufferedReader = null; | ||||||||||||||||||||||||||||||||||||||||||||||||
Process process; | ||||||||||||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||||||||||||
process = processBuilder.start(); | ||||||||||||||||||||||||||||||||||||||||||||||||
bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); | ||||||||||||||||||||||||||||||||||||||||||||||||
StringBuilder builder = new StringBuilder(); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
// Make sure to output the raw command. | ||||||||||||||||||||||||||||||||||||||||||||||||
builder.append("Running command: "); | ||||||||||||||||||||||||||||||||||||||||||||||||
builder.append(String.join(" ", processBuilder.command().toArray(new String[0]))); | ||||||||||||||||||||||||||||||||||||||||||||||||
builder.append(System.getProperty("line.separator")); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
String line; | ||||||||||||||||||||||||||||||||||||||||||||||||
while ((line = bufferedReader.readLine()) != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||
builder.append(line); | ||||||||||||||||||||||||||||||||||||||||||||||||
builder.append(System.getProperty("line.separator")); | ||||||||||||||||||||||||||||||||||||||||||||||||
final String currentOutput = builder.toString(); | ||||||||||||||||||||||||||||||||||||||||||||||||
javafx.application.Platform.runLater(() -> model.setOutputText(currentOutput)); | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
while ((line = bufferedReader.readLine()) != null) { | |
builder.append(line); | |
builder.append(System.getProperty("line.separator")); | |
final String currentOutput = builder.toString(); | |
javafx.application.Platform.runLater(() -> model.setOutputText(currentOutput)); | |
} | |
int lineCounter = 0; // Counter to track the number of lines read. | |
while ((line = bufferedReader.readLine()) != null) { | |
builder.append(line); | |
builder.append(System.getProperty("line.separator")); | |
lineCounter++; | |
// Update the UI every 100 lines or when the process finishes. | |
if (lineCounter >= 100) { | |
final String currentOutput = builder.toString(); | |
javafx.application.Platform.runLater(() -> model.setOutputText(currentOutput)); | |
lineCounter = 0; // Reset the counter after updating the UI. | |
} | |
} | |
// Ensure any remaining output is flushed to the UI. | |
final String remainingOutput = builder.toString(); | |
javafx.application.Platform.runLater(() -> model.setOutputText(remainingOutput)); |
Copilot uses AI. Check for mistakes.
Positive FeedbackNegative Feedback
This file contains hidden or 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,78 @@ | ||
package com.example.gui; | ||
|
||
import javafx.beans.property.ObjectProperty; | ||
import javafx.beans.property.SimpleObjectProperty; | ||
import javafx.beans.property.SimpleStringProperty; | ||
import javafx.beans.property.StringProperty; | ||
|
||
public class ChatboxModel { | ||
|
||
public enum Engine { TORNADO_VM, JVM } | ||
|
||
private final ObjectProperty<Engine> selectedEngine = new SimpleObjectProperty<>(Engine.TORNADO_VM); | ||
private final StringProperty llama3Path = new SimpleStringProperty(""); | ||
private final StringProperty selectedModel = new SimpleStringProperty(""); | ||
private final StringProperty promptText = new SimpleStringProperty(""); | ||
private final StringProperty outputText = new SimpleStringProperty(""); | ||
|
||
public Engine getSelectedEngine() { | ||
return selectedEngine.get(); | ||
} | ||
|
||
public ObjectProperty<Engine> selectedEngineProperty() { | ||
return selectedEngine; | ||
} | ||
|
||
public void setSelectedEngine(Engine engine) { | ||
this.selectedEngine.set(engine); | ||
} | ||
|
||
public String getLlama3Path() { | ||
return llama3Path.get(); | ||
} | ||
|
||
public StringProperty llama3PathProperty() { | ||
return llama3Path; | ||
} | ||
|
||
public void setLlama3Path(String path) { | ||
this.llama3Path.set(path); | ||
} | ||
|
||
public String getSelectedModel() { | ||
return selectedModel.get(); | ||
} | ||
|
||
public StringProperty selectedModelProperty() { | ||
return selectedModel; | ||
} | ||
|
||
public void setSelectedModel(String selectedModel) { | ||
this.selectedModel.set(selectedModel); | ||
} | ||
|
||
public String getPromptText() { | ||
return promptText.get(); | ||
} | ||
|
||
public StringProperty promptTextProperty() { | ||
return promptText; | ||
} | ||
|
||
public void setPromptText(String text) { | ||
this.promptText.set(text); | ||
} | ||
|
||
public String getOutputText() { | ||
return outputText.get(); | ||
} | ||
|
||
public StringProperty outputTextProperty() { | ||
return outputText; | ||
} | ||
|
||
public void setOutputText(String text) { | ||
this.outputText.set(text); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.llama-tornado
does not work on Linux