@@ -145,6 +145,7 @@ OllamaAPI getOllamaApi() throws MalformedURLException {
145
145
URL url = new URL (config .url );
146
146
ollam4JUrl = config .url ;
147
147
api = new OllamaAPI (String .format ("%s://%s:%d" , url .getProtocol (), url .getHost (), url .getPort ()));
148
+ api .setRequestTimeoutSeconds (config .timeout );
148
149
}
149
150
return api ;
150
151
}
@@ -349,6 +350,26 @@ public Response getResponseStream(String text, List<String> imageUrls) {
349
350
responseText = result .getResponse ();
350
351
}
351
352
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
+ }
352
373
353
374
Response response = new Response ("friend" , getName (), responseText , null );
354
375
invoke ("publishResponse" , response );
@@ -365,6 +386,7 @@ public class StreamHandler implements OllamaStreamHandler {
365
386
366
387
final StringBuilder [] sentenceBuilder = { new StringBuilder () };
367
388
final int [] lastProcessedLength = { 0 }; // Track the length of already
389
+ public String potentialSentence = null ;
368
390
369
391
@ Override
370
392
public void accept (String message ) {
@@ -386,7 +408,7 @@ public void accept(String message) {
386
408
387
409
if (lastSentenceEndIndex != -1 ) {
388
410
// Extract the potential sentence
389
- String potentialSentence = sentenceBuilder [0 ].substring (0 , lastSentenceEndIndex + 1 ).trim ();
411
+ potentialSentence = sentenceBuilder [0 ].substring (0 , lastSentenceEndIndex + 1 ).trim ();
390
412
391
413
// Only process if the sentence is above the minimum length
392
414
if (potentialSentence .length () >= MIN_SENTENCE_LENGTH ) {
@@ -401,6 +423,11 @@ public void accept(String message) {
401
423
utterance .channelBotName = currentBotName ;
402
424
utterance .channelName = currentChannelName ;
403
425
invoke ("publishUtterance" , utterance );
426
+
427
+
428
+ Response response = new Response ("friend" , getName (), potentialSentence , null );
429
+ invoke ("publishResponse" , response );
430
+
404
431
405
432
// Keep any remaining text after the last sentence-ending character
406
433
sentenceBuilder [0 ] = new StringBuilder (sentenceBuilder [0 ].substring (lastSentenceEndIndex + 1 ));
@@ -712,6 +739,7 @@ public static void main(String[] args) {
712
739
713
740
Response response = null ;
714
741
LLM llm = (LLM ) Runtime .start ("llm" , "LLM" );
742
+ // llm.getConfig().timeout = 1;
715
743
Runtime .start ("python" , "Python" );
716
744
717
745
WebGui webgui = (WebGui ) Runtime .create ("webgui" , "WebGui" );
0 commit comments