@@ -81,6 +81,8 @@ public class LLM extends Service<LLMConfig> implements TextListener, TextPublish
81
81
OllamaAPI ollamaAPI ;
82
82
83
83
List <LinkedHashMap <String , Object >> userMessages = new ArrayList <>();
84
+
85
+ List <String > userTextMessages = new ArrayList <>();
84
86
85
87
public void addInput (String key , Object value ) {
86
88
inputs .put (key , value );
@@ -221,12 +223,46 @@ public Response getResponseStream(String text) {
221
223
URL url = new URL (config .url );
222
224
ollamaAPI = new OllamaAPI (String .format ("%s://%s:%d" , url .getProtocol (), url .getHost (), url .getPort ()));
223
225
}
226
+
227
+
228
+
229
+ // Create and format date and time strings
230
+ LocalDateTime currentDateTime = LocalDateTime .now ();
231
+ DateTimeFormatter dateFormatter = DateTimeFormatter .ofPattern ("yyyy-MM-dd" );
232
+ DateTimeFormatter timeFormatter = DateTimeFormatter .ofPattern ("h:mm a" );
233
+ DateTimeFormatter fullDateFormatter = DateTimeFormatter .ofPattern ("EEEE MMMM d'th' yyyy h:mm a" );
224
234
235
+ inputs .put ("Date" , currentDateTime .format (dateFormatter ));
236
+ inputs .put ("Time" , currentDateTime .format (timeFormatter ));
237
+ inputs .put ("DateTime" , currentDateTime .format (fullDateFormatter ));
238
+
239
+ String systemContent = config .system ;
240
+
241
+ // Replace placeholders in system content
242
+ for (Map .Entry <String , Object > entry : inputs .entrySet ()) {
243
+ if (entry .getValue () != null ) {
244
+ systemContent = systemContent .replace (String .format ("{{%s}}" , entry .getKey ()), entry .getValue ().toString ());
245
+ }
246
+ }
247
+
248
+ userTextMessages .add (text );
249
+
250
+ if (config .maxHistory > 0 ) {
251
+ while (userTextMessages .size () > config .maxHistory ) {
252
+ userTextMessages .remove (0 );
253
+ }
254
+ } else {
255
+ userTextMessages .clear ();
256
+ }
257
+
258
+ String finalText = systemContent + " " + text ;
259
+
260
+ // sentence chunking stream processing
225
261
final StringBuilder [] sentenceBuilder = { new StringBuilder () };
226
262
final int [] lastProcessedLength = { 0 }; // Track the length of already
227
263
// processed text
228
264
229
- OllamaResult result = ollamaAPI .generate ("llama3" , text , false , new OptionsBuilder ().build (), (s ) -> {
265
+ OllamaResult result = ollamaAPI .generate ("llama3" , finalText , false , new OptionsBuilder ().build (), (s ) -> {
230
266
// Append only the new portion of the text
231
267
String newText = s .substring (lastProcessedLength [0 ]);
232
268
sentenceBuilder [0 ].append (newText );
0 commit comments