@@ -399,8 +399,9 @@ public Message build() {
399
399
* @param model The model to use for completion.
400
400
* @param messages The list of messages to chat with.
401
401
* @param stream Whether to stream the response.
402
- * @param format The format to return the response in. Currently the only accepted
402
+ * @param format The format to return the response in. Currently, the only accepted
403
403
* value is "json".
404
+ * @param keepAlive The duration to keep the model loaded in ollama while idle. https://pkg.go.dev/time#ParseDuration
404
405
* @param options Additional model parameters. You can use the {@link OllamaOptions} builder
405
406
* to create the options then {@link OllamaOptions#toMap()} to convert the options into a
406
407
* map.
@@ -411,6 +412,7 @@ public record ChatRequest(
411
412
@ JsonProperty ("messages" ) List <Message > messages ,
412
413
@ JsonProperty ("stream" ) Boolean stream ,
413
414
@ JsonProperty ("format" ) String format ,
415
+ @ JsonProperty ("keep_alive" ) String keepAlive ,
414
416
@ JsonProperty ("options" ) Map <String , Object > options ) {
415
417
416
418
public static Builder builder (String model ) {
@@ -423,6 +425,7 @@ public static class Builder {
423
425
private List <Message > messages = List .of ();
424
426
private boolean stream = false ;
425
427
private String format ;
428
+ private String keepAlive ;
426
429
private Map <String , Object > options = Map .of ();
427
430
428
431
public Builder (String model ) {
@@ -445,6 +448,11 @@ public Builder withFormat(String format) {
445
448
return this ;
446
449
}
447
450
451
+ public Builder withKeepAlive (String keepAlive ) {
452
+ this .keepAlive = keepAlive ;
453
+ return this ;
454
+ }
455
+
448
456
public Builder withOptions (Map <String , Object > options ) {
449
457
Objects .requireNonNullElse (options , "The options can not be null." );
450
458
@@ -459,7 +467,7 @@ public Builder withOptions(OllamaOptions options) {
459
467
}
460
468
461
469
public ChatRequest build () {
462
- return new ChatRequest (model , messages , stream , format , options );
470
+ return new ChatRequest (model , messages , stream , format , keepAlive , options );
463
471
}
464
472
}
465
473
}
0 commit comments