Skip to content

Commit

Permalink
updates catching up
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick committed Nov 4, 2024
1 parent d77872f commit 0c052dd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
File renamed without changes.
30 changes: 29 additions & 1 deletion src/main/java/org/myrobotlab/service/LLM.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ OllamaAPI getOllamaApi() throws MalformedURLException {
URL url = new URL(config.url);
ollam4JUrl = config.url;
api = new OllamaAPI(String.format("%s://%s:%d", url.getProtocol(), url.getHost(), url.getPort()));
api.setRequestTimeoutSeconds(config.timeout);
}
return api;
}
Expand Down Expand Up @@ -349,6 +350,26 @@ public Response getResponseStream(String text, List<String> imageUrls) {
responseText = result.getResponse();
}

// we are at the end of our response of streaming, and now the "result" will unblock signalling the end of the response
// now we have to check to see if there is any extra text on the end that did not get published
if (handler.sentenceBuilder[0] != null && handler.sentenceBuilder[0].length() > 0) {
invoke("publishText", handler.sentenceBuilder[0].toString());

Utterance utterance = new Utterance();
utterance.username = getName();
utterance.text = handler.sentenceBuilder[0].toString();
utterance.isBot = true;
utterance.channel = currentChannel;
utterance.channelType = currentChannelType;
utterance.channelBotName = currentBotName;
utterance.channelName = currentChannelName;
invoke("publishUtterance", utterance);


Response response = new Response("friend", getName(), handler.sentenceBuilder[0].toString(), null);
invoke("publishResponse", response);

}

Response response = new Response("friend", getName(), responseText, null);
invoke("publishResponse", response);
Expand All @@ -365,6 +386,7 @@ public class StreamHandler implements OllamaStreamHandler {

final StringBuilder[] sentenceBuilder = { new StringBuilder() };
final int[] lastProcessedLength = { 0 }; // Track the length of already
public String potentialSentence = null;

@Override
public void accept(String message) {
Expand All @@ -386,7 +408,7 @@ public void accept(String message) {

if (lastSentenceEndIndex != -1) {
// Extract the potential sentence
String potentialSentence = sentenceBuilder[0].substring(0, lastSentenceEndIndex + 1).trim();
potentialSentence = sentenceBuilder[0].substring(0, lastSentenceEndIndex + 1).trim();

// Only process if the sentence is above the minimum length
if (potentialSentence.length() >= MIN_SENTENCE_LENGTH) {
Expand All @@ -401,6 +423,11 @@ public void accept(String message) {
utterance.channelBotName = currentBotName;
utterance.channelName = currentChannelName;
invoke("publishUtterance", utterance);


Response response = new Response("friend", getName(), potentialSentence, null);
invoke("publishResponse", response);


// Keep any remaining text after the last sentence-ending character
sentenceBuilder[0] = new StringBuilder(sentenceBuilder[0].substring(lastSentenceEndIndex + 1));
Expand Down Expand Up @@ -712,6 +739,7 @@ public static void main(String[] args) {

Response response = null;
LLM llm = (LLM) Runtime.start("llm", "LLM");
// llm.getConfig().timeout = 1;
Runtime.start("python", "Python");

WebGui webgui = (WebGui) Runtime.create("webgui", "WebGui");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/myrobotlab/service/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ public static String getVersion() {
public static String getLatestVersion() {
String latest = "https://myrobotlab-repo.s3.us-east-1.amazonaws.com/latestVersion.txt";
byte[] b = Http.get(latest);
String version = (b == null) ? "unknown" : "1.1." + new String(b);
String version = (b == null) ? "unknown" : new String(b);
return version;
}

Expand Down Expand Up @@ -2846,7 +2846,7 @@ public Runtime(String n, String id) {

setLocale(Locale.getDefault().getTag());
locales = Locale.getDefaults();

Platform platform = Platform.getLocalInstance();

String libararyPath = System.getProperty("java.library.path");
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/myrobotlab/service/config/LLMConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class LLMConfig extends ServiceConfig {
*/
public int maxHistory = 5;

/**
* client side timeout waiting for response
*/
public int timeout = 1000;

/**
* static prefix to send to gpt3
Expand Down

0 comments on commit 0c052dd

Please sign in to comment.