11package org .jabref .gui .preferences .ai ;
22
3+ import java .util .Arrays ;
4+
35import javafx .beans .property .BooleanProperty ;
46import javafx .beans .property .DoubleProperty ;
57import javafx .beans .property .FloatProperty ;
@@ -32,6 +34,7 @@ public class AiTabViewModel implements PreferenceTabViewModel {
3234 private final ObjectProperty <AiPreferences .AiModel > modelProperty = new SimpleObjectProperty <>();
3335
3436 private final StringProperty systemMessage = new SimpleStringProperty ();
37+ private final DoubleProperty temperature = new SimpleDoubleProperty ();
3538 private final IntegerProperty messageWindowSize = new SimpleIntegerProperty ();
3639 private final IntegerProperty documentSplitterChunkSize = new SimpleIntegerProperty ();
3740 private final IntegerProperty documentSplitterOverlapSize = new SimpleIntegerProperty ();
@@ -42,6 +45,7 @@ public class AiTabViewModel implements PreferenceTabViewModel {
4245
4346 private final Validator openAiTokenValidator ;
4447 private final Validator systemMessageValidator ;
48+ private final Validator temperatureValidator ;
4549 private final Validator messageWindowSizeValidator ;
4650 private final Validator documentSplitterChunkSizeValidator ;
4751 private final Validator documentSplitterOverlapSizeValidator ;
@@ -61,6 +65,11 @@ public AiTabViewModel(PreferencesService preferencesService) {
6165 (message ) -> !StringUtil .isBlank (message ),
6266 ValidationMessage .error (Localization .lang ("The system message cannot be empty" )));
6367
68+ this .temperatureValidator = new FunctionBasedValidator <>(
69+ temperature ,
70+ (temp ) -> (double )temp >= 0 && (double )temp <= 2 ,
71+ ValidationMessage .error (Localization .lang ("Temperature must be between 0 and 2" )));
72+
6473 this .messageWindowSizeValidator = new FunctionBasedValidator <>(
6574 messageWindowSize ,
6675 (size ) -> (int )size > 0 ,
@@ -94,6 +103,7 @@ public void setValues() {
94103 modelProperty .setValue (aiPreferences .getModel ());
95104
96105 systemMessage .setValue (aiPreferences .getSystemMessage ());
106+ temperature .setValue (aiPreferences .getTemperature ());
97107 messageWindowSize .setValue (aiPreferences .getMessageWindowSize ());
98108 documentSplitterChunkSize .setValue (aiPreferences .getDocumentSplitterChunkSize ());
99109 documentSplitterOverlapSize .setValue (aiPreferences .getDocumentSplitterOverlapSize ());
@@ -108,6 +118,7 @@ public void storeSettings() {
108118 aiPreferences .setModel (modelProperty .get ());
109119
110120 aiPreferences .setSystemMessage (systemMessage .get ());
121+ aiPreferences .setTemperature (temperature .get ());
111122 aiPreferences .setMessageWindowSize (messageWindowSize .get ());
112123 aiPreferences .setDocumentSplitterChunkSize (documentSplitterChunkSize .get ());
113124 aiPreferences .setDocumentSplitterOverlapSize (documentSplitterOverlapSize .get ());
@@ -117,7 +128,18 @@ public void storeSettings() {
117128
118129 @ Override
119130 public boolean validateSettings () {
120- return openAiTokenValidator .getValidationStatus ().isValid () && systemMessageValidator .getValidationStatus ().isValid () && messageWindowSizeValidator .getValidationStatus ().isValid () && documentSplitterChunkSizeValidator .getValidationStatus ().isValid () && documentSplitterOverlapSizeValidator .getValidationStatus ().isValid () && ragMaxResultsCountValidator .getValidationStatus ().isValid () && ragMinScoreValidator .getValidationStatus ().isValid ();
131+ Validator [] validators = {
132+ openAiTokenValidator ,
133+ systemMessageValidator ,
134+ temperatureValidator ,
135+ messageWindowSizeValidator ,
136+ documentSplitterChunkSizeValidator ,
137+ documentSplitterOverlapSizeValidator ,
138+ ragMaxResultsCountValidator ,
139+ ragMinScoreValidator
140+ };
141+
142+ return Arrays .stream (validators ).map (Validator ::getValidationStatus ).allMatch (ValidationStatus ::isValid );
121143 }
122144
123145 public StringProperty openAiTokenProperty () {
@@ -136,6 +158,10 @@ public StringProperty systemMessageProperty() {
136158 return systemMessage ;
137159 }
138160
161+ public DoubleProperty temperatureProperty () {
162+ return temperature ;
163+ }
164+
139165 public IntegerProperty messageWindowSizeProperty () {
140166 return messageWindowSize ;
141167 }
@@ -164,6 +190,10 @@ public ValidationStatus getSystemMessageValidatorStatus() {
164190 return systemMessageValidator .getValidationStatus ();
165191 }
166192
193+ public ValidationStatus getTemperatureValidatorStatus () {
194+ return temperatureValidator .getValidationStatus ();
195+ }
196+
167197 public ValidationStatus getMessageWindowSizeValidatorStatus () {
168198 return messageWindowSizeValidator .getValidationStatus ();
169199 }
0 commit comments