@@ -52,7 +52,7 @@ public class OllamaOptions implements FunctionCallingOptions, ChatOptions, Embed
52
52
53
53
public static final String DEFAULT_MODEL = OllamaModel .MISTRAL .id ();
54
54
55
- private static final List <String > NON_SUPPORTED_FIELDS = List .of ("model" , "format" , "keep_alive" );
55
+ private static final List <String > NON_SUPPORTED_FIELDS = List .of ("model" , "format" , "keep_alive" , "truncate" );
56
56
57
57
// Following fields are options which must be set when the model is loaded into
58
58
// memory.
@@ -267,6 +267,13 @@ public class OllamaOptions implements FunctionCallingOptions, ChatOptions, Embed
267
267
* Part of Chat completion <a href="https://github.com/ollama/ollama/blob/main/docs/api.md#parameters-1">advanced parameters</a>.
268
268
*/
269
269
@ JsonProperty ("keep_alive" ) private String keepAlive ;
270
+
271
+
272
+ /**
273
+ * Truncates the end of each input to fit within context length. Returns error if false and context length is exceeded.
274
+ * Defaults to true.
275
+ */
276
+ @ JsonProperty ("truncate" ) private Boolean truncate ;
270
277
271
278
/**
272
279
* Tool Function Callbacks to register with the ChatModel.
@@ -312,14 +319,6 @@ public OllamaOptions withModel(OllamaModel model) {
312
319
return this ;
313
320
}
314
321
315
- public String getModel () {
316
- return model ;
317
- }
318
-
319
- public void setModel (String model ) {
320
- this .model = model ;
321
- }
322
-
323
322
public OllamaOptions withFormat (String format ) {
324
323
this .format = format ;
325
324
return this ;
@@ -330,6 +329,11 @@ public OllamaOptions withKeepAlive(String keepAlive) {
330
329
return this ;
331
330
}
332
331
332
+ public OllamaOptions withTruncate (Boolean truncate ) {
333
+ this .truncate = truncate ;
334
+ return this ;
335
+ }
336
+
333
337
public OllamaOptions withUseNUMA (Boolean useNUMA ) {
334
338
this .useNUMA = useNUMA ;
335
339
return this ;
@@ -491,6 +495,17 @@ public OllamaOptions withFunction(String functionName) {
491
495
return this ;
492
496
}
493
497
498
+ // -------------------
499
+ // Getters and Setters
500
+ // -------------------
501
+ public String getModel () {
502
+ return model ;
503
+ }
504
+
505
+ public void setModel (String model ) {
506
+ this .model = model ;
507
+ }
508
+
494
509
public String getFormat () {
495
510
return this .format ;
496
511
}
@@ -739,6 +754,14 @@ public void setStop(List<String> stop) {
739
754
this .stop = stop ;
740
755
}
741
756
757
+ public Boolean getTruncate () {
758
+ return this .truncate ;
759
+ }
760
+
761
+ public void setTruncate (Boolean truncate ) {
762
+ this .truncate = truncate ;
763
+ }
764
+
742
765
@ Override
743
766
public List <FunctionCallback > getFunctionCallbacks () {
744
767
return this .functionCallbacks ;
@@ -797,6 +820,7 @@ public static OllamaOptions fromOptions(OllamaOptions fromOptions) {
797
820
.withModel (fromOptions .getModel ())
798
821
.withFormat (fromOptions .getFormat ())
799
822
.withKeepAlive (fromOptions .getKeepAlive ())
823
+ .withTruncate (fromOptions .getTruncate ())
800
824
.withUseNUMA (fromOptions .getUseNUMA ())
801
825
.withNumCtx (fromOptions .getNumCtx ())
802
826
.withNumBatch (fromOptions .getNumBatch ())
@@ -839,15 +863,16 @@ public boolean equals(Object o) {
839
863
return false ;
840
864
OllamaOptions that = (OllamaOptions ) o ;
841
865
return Objects .equals (model , that .model ) && Objects .equals (format , that .format )
842
- && Objects .equals (keepAlive , that .keepAlive ) && Objects .equals (useNUMA , that .useNUMA )
843
- && Objects .equals (numCtx , that .numCtx ) && Objects .equals (numBatch , that .numBatch )
844
- && Objects .equals (numGPU , that .numGPU ) && Objects .equals (mainGPU , that .mainGPU )
845
- && Objects .equals (lowVRAM , that .lowVRAM ) && Objects .equals (f16KV , that .f16KV )
846
- && Objects .equals (logitsAll , that .logitsAll ) && Objects .equals (vocabOnly , that .vocabOnly )
847
- && Objects .equals (useMMap , that .useMMap ) && Objects .equals (useMLock , that .useMLock )
848
- && Objects .equals (numThread , that .numThread ) && Objects .equals (numKeep , that .numKeep )
849
- && Objects .equals (seed , that .seed ) && Objects .equals (numPredict , that .numPredict )
850
- && Objects .equals (topK , that .topK ) && Objects .equals (topP , that .topP ) && Objects .equals (tfsZ , that .tfsZ )
866
+ && Objects .equals (keepAlive , that .keepAlive ) && Objects .equals (truncate , that .truncate )
867
+ && Objects .equals (useNUMA , that .useNUMA ) && Objects .equals (numCtx , that .numCtx )
868
+ && Objects .equals (numBatch , that .numBatch ) && Objects .equals (numGPU , that .numGPU )
869
+ && Objects .equals (mainGPU , that .mainGPU ) && Objects .equals (lowVRAM , that .lowVRAM )
870
+ && Objects .equals (f16KV , that .f16KV ) && Objects .equals (logitsAll , that .logitsAll )
871
+ && Objects .equals (vocabOnly , that .vocabOnly ) && Objects .equals (useMMap , that .useMMap )
872
+ && Objects .equals (useMLock , that .useMLock ) && Objects .equals (numThread , that .numThread )
873
+ && Objects .equals (numKeep , that .numKeep ) && Objects .equals (seed , that .seed )
874
+ && Objects .equals (numPredict , that .numPredict ) && Objects .equals (topK , that .topK )
875
+ && Objects .equals (topP , that .topP ) && Objects .equals (tfsZ , that .tfsZ )
851
876
&& Objects .equals (typicalP , that .typicalP ) && Objects .equals (repeatLastN , that .repeatLastN )
852
877
&& Objects .equals (temperature , that .temperature ) && Objects .equals (repeatPenalty , that .repeatPenalty )
853
878
&& Objects .equals (presencePenalty , that .presencePenalty )
@@ -860,12 +885,12 @@ public boolean equals(Object o) {
860
885
861
886
@ Override
862
887
public int hashCode () {
863
- return Objects .hash (this .model , this .format , this .keepAlive , this .useNUMA , this .numCtx , this .numBatch ,
864
- this .numGPU , this .mainGPU , lowVRAM , this .f16KV , this .logitsAll , this .vocabOnly , this . useMMap ,
865
- this .useMLock , this .numThread , this .numKeep , this .seed , this .numPredict , this .topK , this . topP , tfsZ ,
866
- this .typicalP , this .repeatLastN , this .temperature , this .repeatPenalty , this .presencePenalty ,
867
- this .frequencyPenalty , this .mirostat , this .mirostatTau , this .mirostatEta , this .penalizeNewline ,
868
- this .stop , this .functionCallbacks , this .functions );
888
+ return Objects .hash (this .model , this .format , this .keepAlive , this .truncate , this .useNUMA , this .numCtx ,
889
+ this .numBatch , this . numGPU , this .mainGPU , lowVRAM , this .f16KV , this .logitsAll , this .vocabOnly ,
890
+ this .useMMap , this . useMLock , this .numThread , this .numKeep , this .seed , this .numPredict , this .topK ,
891
+ this .topP , tfsZ , this .typicalP , this .repeatLastN , this .temperature , this .repeatPenalty ,
892
+ this .presencePenalty , this .frequencyPenalty , this .mirostat , this .mirostatTau , this .mirostatEta ,
893
+ this .penalizeNewline , this . stop , this .functionCallbacks , this .functions );
869
894
}
870
895
871
896
}
0 commit comments