Added keep_alive
This commit is contained in:
parent
fdea5bab05
commit
0b04e89cc9
|
@ -262,6 +262,32 @@
|
|||
"description": "Text displayed as description for show tips toggle",
|
||||
"context": "Visible in the settings view"
|
||||
},
|
||||
"settingsKeepModelLoadedAlways": "Modell immer geladen lassen",
|
||||
"@settingsKeepModelLoadedAlways": {
|
||||
"description": "Text displayed as description for keep model loaded always toggle",
|
||||
"context": "Visible in the settings view"
|
||||
},
|
||||
"settingsKeepModelLoadedNever": "Modell nicht dauerhaft laden",
|
||||
"@settingsKeepModelLoadedNever": {
|
||||
"description": "Text displayed as description for don't keep model loaded toggle",
|
||||
"context": "Visible in the settings view"
|
||||
},
|
||||
"settingsKeepModelLoadedFor": "Bestimmte Modell-Ladedauer festlegen",
|
||||
"@settingsKeepModelLoadedFor": {
|
||||
"description": "Text displayed as description for keep model loaded for toggle",
|
||||
"context": "Visible in the settings view"
|
||||
},
|
||||
"settingsKeepModelLoadedSet": "Modell für {minutes} Minuten geladen behalten",
|
||||
"@settingsKeepModelLoadedSet": {
|
||||
"description": "Text displayed as description for keep model loaded for set time toggle",
|
||||
"context": "Visible in the settings view",
|
||||
"placeholders": {
|
||||
"minutes": {
|
||||
"type": "String",
|
||||
"description": "Minutes the model should be kept loaded"
|
||||
}
|
||||
}
|
||||
},
|
||||
"settingsEnableHapticFeedback": "Haptisches Feedback aktivieren",
|
||||
"@settingsEnableHapticFeedback": {
|
||||
"description": "Text displayed as description for enable haptic feedback toggle",
|
||||
|
|
|
@ -262,6 +262,32 @@
|
|||
"description": "Text displayed as description for show tips toggle",
|
||||
"context": "Visible in the settings view"
|
||||
},
|
||||
"settingsKeepModelLoadedAlways": "Keep model always loaded",
|
||||
"@settingsKeepModelLoadedAlways": {
|
||||
"description": "Text displayed as description for keep model loaded always toggle",
|
||||
"context": "Visible in the settings view"
|
||||
},
|
||||
"settingsKeepModelLoadedNever": "Don't keep model loaded",
|
||||
"@settingsKeepModelLoadedNever": {
|
||||
"description": "Text displayed as description for don't keep model loaded toggle",
|
||||
"context": "Visible in the settings view"
|
||||
},
|
||||
"settingsKeepModelLoadedFor": "Set specific time to keep model loaded",
|
||||
"@settingsKeepModelLoadedFor": {
|
||||
"description": "Text displayed as description for keep model loaded for toggle",
|
||||
"context": "Visible in the settings view"
|
||||
},
|
||||
"settingsKeepModelLoadedSet": "Keep model loaded for {minutes} minutes",
|
||||
"@settingsKeepModelLoadedSet": {
|
||||
"description": "Text displayed as description for keep model loaded for set time toggle",
|
||||
"context": "Visible in the settings view",
|
||||
"placeholders": {
|
||||
"minutes": {
|
||||
"type": "String",
|
||||
"description": "Minutes the model should be kept loaded"
|
||||
}
|
||||
}
|
||||
},
|
||||
"settingsEnableHapticFeedback": "Enable haptic feedback",
|
||||
"@settingsEnableHapticFeedback": {
|
||||
"description": "Text displayed as description for enable haptic feedback toggle",
|
||||
|
|
|
@ -1187,7 +1187,9 @@ class _MainAppState extends State<MainApp> {
|
|||
request: llama.GenerateChatCompletionRequest(
|
||||
model: model!,
|
||||
messages: history,
|
||||
keepAlive: 1,
|
||||
keepAlive: int.parse(prefs!
|
||||
.getString("keepAlive") ??
|
||||
"300")
|
||||
),
|
||||
)
|
||||
.timeout(const Duration(seconds: 15));
|
||||
|
@ -1221,7 +1223,9 @@ class _MainAppState extends State<MainApp> {
|
|||
request: llama.GenerateChatCompletionRequest(
|
||||
model: model!,
|
||||
messages: history,
|
||||
keepAlive: 1,
|
||||
keepAlive: int.parse(prefs!
|
||||
.getString("keepAlive") ??
|
||||
"300")
|
||||
),
|
||||
)
|
||||
.timeout(const Duration(seconds: 15));
|
||||
|
@ -1298,6 +1302,9 @@ class _MainAppState extends State<MainApp> {
|
|||
model: model!,
|
||||
prompt:
|
||||
"You must not use markdown or any other formatting language! Create a short title for the subject of the conversation described in the following json object. It is not allowed to be too general; no 'Assistance', 'Help' or similar!\n\n```json\n${jsonEncode(history)}\n```",
|
||||
keepAlive: int.parse(prefs!
|
||||
.getString("keepAlive") ??
|
||||
"300")
|
||||
),
|
||||
);
|
||||
var title = generated.response!
|
||||
|
|
|
@ -10,6 +10,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|||
|
||||
import 'package:bitsdojo_window/bitsdojo_window.dart';
|
||||
import 'package:restart_app/restart_app.dart';
|
||||
import 'package:duration_picker/duration_picker.dart';
|
||||
|
||||
class ScreenSettingsInterface extends StatefulWidget {
|
||||
const ScreenSettingsInterface({super.key});
|
||||
|
@ -149,6 +150,124 @@ class _ScreenSettingsInterfaceState extends State<ScreenSettingsInterface> {
|
|||
setState(() {});
|
||||
}),
|
||||
titleDivider(),
|
||||
toggle(
|
||||
context,
|
||||
AppLocalizations.of(context)!
|
||||
.settingsKeepModelLoadedAlways,
|
||||
int.parse(prefs!.getString("keepAlive") ?? "300") == -1,
|
||||
(value) {
|
||||
setState(() {
|
||||
if (value) {
|
||||
prefs!.setString("keepAlive", "-1");
|
||||
} else {
|
||||
prefs!.setString("keepAlive", "300");
|
||||
}
|
||||
});
|
||||
}),
|
||||
toggle(
|
||||
context,
|
||||
AppLocalizations.of(context)!
|
||||
.settingsKeepModelLoadedNever,
|
||||
int.parse(prefs!.getString("keepAlive") ?? "300") == 0,
|
||||
(value) {
|
||||
setState(() {
|
||||
if (value) {
|
||||
prefs!.setString("keepAlive", "0");
|
||||
} else {
|
||||
prefs!.setString("keepAlive", "300");
|
||||
}
|
||||
});
|
||||
}),
|
||||
button(
|
||||
(int.parse(prefs!.getString("keepAlive") ?? "300") > 0)
|
||||
? AppLocalizations.of(context)!
|
||||
.settingsKeepModelLoadedSet((int.parse(
|
||||
prefs!.getString("keepAlive") ??
|
||||
"300") ~/
|
||||
60)
|
||||
.toString())
|
||||
: AppLocalizations.of(context)!
|
||||
.settingsKeepModelLoadedFor,
|
||||
Icons.snooze_rounded, () async {
|
||||
bool loaded = false;
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return Dialog(
|
||||
alignment: (Platform.isWindows ||
|
||||
Platform.isLinux ||
|
||||
Platform.isMacOS)
|
||||
? null
|
||||
: Alignment.bottomRight,
|
||||
child: StatefulBuilder(
|
||||
builder: (context, setLocalState) {
|
||||
if (int.parse(prefs!.getString("keepAlive") ??
|
||||
"0") <=
|
||||
0 &&
|
||||
loaded == false) {
|
||||
prefs!.setString("keepAlive", "0");
|
||||
WidgetsBinding.instance
|
||||
.addPostFrameCallback((timeStamp) {
|
||||
setLocalState(() {});
|
||||
void load() async {
|
||||
try {
|
||||
while (int.parse(prefs!
|
||||
.getString("keepAlive")!) <
|
||||
300) {
|
||||
await Future.delayed(const Duration(
|
||||
milliseconds: 5));
|
||||
prefs!.setString(
|
||||
"keepAlive",
|
||||
(int.parse(prefs!.getString(
|
||||
"keepAlive")!) +
|
||||
30)
|
||||
.toString());
|
||||
setLocalState(() {});
|
||||
setState(() {});
|
||||
}
|
||||
prefs!.setString("keepAlive", "300");
|
||||
loaded = true;
|
||||
} catch (_) {
|
||||
prefs!.setString("keepAlive", "300");
|
||||
loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
load();
|
||||
});
|
||||
} else {
|
||||
loaded = true;
|
||||
}
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Theme(
|
||||
data: ThemeData.from(
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: Colors.black)),
|
||||
child: DurationPicker(
|
||||
duration: Duration(
|
||||
seconds: int.parse(prefs!
|
||||
.getString("keepAlive") ??
|
||||
"300")),
|
||||
baseUnit: BaseUnit.minute,
|
||||
lowerBound:
|
||||
const Duration(minutes: 1),
|
||||
upperBound:
|
||||
const Duration(minutes: 60),
|
||||
onChange: (value) {
|
||||
if (!loaded) return;
|
||||
if (value.inSeconds == 0) return;
|
||||
prefs!.setString("keepAlive",
|
||||
value.inSeconds.toString());
|
||||
setLocalState(() {});
|
||||
setState(() {});
|
||||
}),
|
||||
),
|
||||
);
|
||||
}));
|
||||
});
|
||||
}),
|
||||
titleDivider(),
|
||||
toggle(
|
||||
context,
|
||||
AppLocalizations.of(context)!
|
||||
|
@ -170,7 +289,7 @@ class _ScreenSettingsInterfaceState extends State<ScreenSettingsInterface> {
|
|||
setState(() {});
|
||||
})
|
||||
: const SizedBox.shrink(),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 8),
|
||||
SegmentedButton(
|
||||
segments: [
|
||||
ButtonSegment(
|
||||
|
@ -250,7 +369,7 @@ class _ScreenSettingsInterfaceState extends State<ScreenSettingsInterface> {
|
|||
});
|
||||
});
|
||||
}),
|
||||
const SizedBox(height: 16)
|
||||
const SizedBox(height: 16)
|
||||
]),
|
||||
)
|
||||
]))),
|
||||
|
|
|
@ -462,21 +462,24 @@ Future<String> prompt(BuildContext context,
|
|||
return;
|
||||
}
|
||||
|
||||
final generated = await llama.OllamaClient(
|
||||
headers: (jsonDecode(prefs!
|
||||
.getString(
|
||||
"hostHeaders") ??
|
||||
"{}") as Map)
|
||||
.cast<String,
|
||||
String>(),
|
||||
baseUrl: "$host/api")
|
||||
.generateCompletion(
|
||||
final generated =
|
||||
await llama.OllamaClient(
|
||||
headers: (jsonDecode(prefs!
|
||||
.getString(
|
||||
"hostHeaders") ??
|
||||
"{}") as Map)
|
||||
.cast<String, String>(),
|
||||
baseUrl: "$host/api",
|
||||
).generateCompletion(
|
||||
request: llama
|
||||
.GenerateCompletionRequest(
|
||||
model: model!,
|
||||
prompt:
|
||||
"You must not use markdown or any other formatting language! Create a short title for the subject of the conversation described in the following json object. It is not allowed to be too general; no 'Assistance', 'Help' or similar!\n\n```json\n${jsonEncode(history)}\n```",
|
||||
),
|
||||
model: model!,
|
||||
prompt:
|
||||
"You must not use markdown or any other formatting language! Create a short title for the subject of the conversation described in the following json object. It is not allowed to be too general; no 'Assistance', 'Help' or similar!\n\n```json\n${jsonEncode(history)}\n```",
|
||||
keepAlive: int.parse(
|
||||
prefs!.getString(
|
||||
"keepAlive") ??
|
||||
"300")),
|
||||
);
|
||||
var title = generated.response!
|
||||
.replaceAll("*", "")
|
||||
|
|
|
@ -137,6 +137,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.0.1"
|
||||
duration_picker:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: duration_picker
|
||||
sha256: e505a749c93f3218aa4194d339e5d5480d927df23a81f075b5282511f6ac11ab
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
equatable:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -37,6 +37,7 @@ dependencies:
|
|||
package_info_plus: ^8.0.0
|
||||
version: ^3.0.2
|
||||
flutter_displaymode: ^0.6.0
|
||||
duration_picker: ^1.2.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in New Issue