Skip to content

Commit 0c052dd

Browse files
committed
updates catching up
1 parent d77872f commit 0c052dd

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed
File renamed without changes.

src/main/java/org/myrobotlab/service/LLM.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ OllamaAPI getOllamaApi() throws MalformedURLException {
145145
URL url = new URL(config.url);
146146
ollam4JUrl = config.url;
147147
api = new OllamaAPI(String.format("%s://%s:%d", url.getProtocol(), url.getHost(), url.getPort()));
148+
api.setRequestTimeoutSeconds(config.timeout);
148149
}
149150
return api;
150151
}
@@ -349,6 +350,26 @@ public Response getResponseStream(String text, List<String> imageUrls) {
349350
responseText = result.getResponse();
350351
}
351352

353+
// we are at the end of our response of streaming, and now the "result" will unblock signalling the end of the response
354+
// now we have to check to see if there is any extra text on the end that did not get published
355+
if (handler.sentenceBuilder[0] != null && handler.sentenceBuilder[0].length() > 0) {
356+
invoke("publishText", handler.sentenceBuilder[0].toString());
357+
358+
Utterance utterance = new Utterance();
359+
utterance.username = getName();
360+
utterance.text = handler.sentenceBuilder[0].toString();
361+
utterance.isBot = true;
362+
utterance.channel = currentChannel;
363+
utterance.channelType = currentChannelType;
364+
utterance.channelBotName = currentBotName;
365+
utterance.channelName = currentChannelName;
366+
invoke("publishUtterance", utterance);
367+
368+
369+
Response response = new Response("friend", getName(), handler.sentenceBuilder[0].toString(), null);
370+
invoke("publishResponse", response);
371+
372+
}
352373

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

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

369391
@Override
370392
public void accept(String message) {
@@ -386,7 +408,7 @@ public void accept(String message) {
386408

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

391413
// Only process if the sentence is above the minimum length
392414
if (potentialSentence.length() >= MIN_SENTENCE_LENGTH) {
@@ -401,6 +423,11 @@ public void accept(String message) {
401423
utterance.channelBotName = currentBotName;
402424
utterance.channelName = currentChannelName;
403425
invoke("publishUtterance", utterance);
426+
427+
428+
Response response = new Response("friend", getName(), potentialSentence, null);
429+
invoke("publishResponse", response);
430+
404431

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

713740
Response response = null;
714741
LLM llm = (LLM) Runtime.start("llm", "LLM");
742+
// llm.getConfig().timeout = 1;
715743
Runtime.start("python", "Python");
716744

717745
WebGui webgui = (WebGui) Runtime.create("webgui", "WebGui");

src/main/java/org/myrobotlab/service/Runtime.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,7 @@ public static String getVersion() {
14861486
public static String getLatestVersion() {
14871487
String latest = "https://myrobotlab-repo.s3.us-east-1.amazonaws.com/latestVersion.txt";
14881488
byte[] b = Http.get(latest);
1489-
String version = (b == null) ? "unknown" : "1.1." + new String(b);
1489+
String version = (b == null) ? "unknown" : new String(b);
14901490
return version;
14911491
}
14921492

@@ -2846,7 +2846,7 @@ public Runtime(String n, String id) {
28462846

28472847
setLocale(Locale.getDefault().getTag());
28482848
locales = Locale.getDefaults();
2849-
2849+
28502850
Platform platform = Platform.getLocalInstance();
28512851

28522852
String libararyPath = System.getProperty("java.library.path");

src/main/java/org/myrobotlab/service/config/LLMConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public class LLMConfig extends ServiceConfig {
3030
*/
3131
public int maxHistory = 5;
3232

33+
/**
34+
* client side timeout waiting for response
35+
*/
36+
public int timeout = 1000;
3337

3438
/**
3539
* static prefix to send to gpt3

0 commit comments

Comments
 (0)