Improved model add dialog
This commit is contained in:
parent
17c276301f
commit
d7ce70cabb
|
@ -317,6 +317,8 @@ void addModel(BuildContext context, Function setState) async {
|
||||||
AppLocalizations.of(context)!.modelDialogAddPromptInvalid;
|
AppLocalizations.of(context)!.modelDialogAddPromptInvalid;
|
||||||
final networkErrorText =
|
final networkErrorText =
|
||||||
AppLocalizations.of(context)!.settingsHostInvalid("other");
|
AppLocalizations.of(context)!.settingsHostInvalid("other");
|
||||||
|
final timeoutErrorText =
|
||||||
|
AppLocalizations.of(context)!.settingsHostInvalid("timeout");
|
||||||
final alreadyExistsText =
|
final alreadyExistsText =
|
||||||
AppLocalizations.of(context)!.modelDialogAddPromptAlreadyExists;
|
AppLocalizations.of(context)!.modelDialogAddPromptAlreadyExists;
|
||||||
final downloadSuccessText =
|
final downloadSuccessText =
|
||||||
|
@ -430,7 +432,7 @@ void addModel(BuildContext context, Function setState) async {
|
||||||
.modelDialogAddDownloadPercent(
|
.modelDialogAddDownloadPercent(
|
||||||
(percent * 100).round().toString()),
|
(percent * 100).round().toString()),
|
||||||
),
|
),
|
||||||
const Padding(padding: EdgeInsets.only(top: 4)),
|
const Padding(padding: EdgeInsets.only(top: 8)),
|
||||||
LinearProgressIndicator(value: percent),
|
LinearProgressIndicator(value: percent),
|
||||||
],
|
],
|
||||||
)));
|
)));
|
||||||
|
@ -442,21 +444,67 @@ void addModel(BuildContext context, Function setState) async {
|
||||||
.timeout(Duration(
|
.timeout(Duration(
|
||||||
seconds: (10.0 * (prefs!.getDouble("timeoutMultiplier") ?? 1.0))
|
seconds: (10.0 * (prefs!.getDouble("timeoutMultiplier") ?? 1.0))
|
||||||
.round()));
|
.round()));
|
||||||
|
bool alreadyProgressed = false;
|
||||||
await for (final res in stream) {
|
await for (final res in stream) {
|
||||||
percent = ((res.completed ?? 0).toInt() / (res.total ?? 100).toInt());
|
double tmpPercent =
|
||||||
if ((percent * 100).round() == 0) {
|
((res.completed ?? 0).toInt() / (res.total ?? 100).toInt());
|
||||||
|
if ((tmpPercent * 100).round() == 0) {
|
||||||
|
if (!alreadyProgressed) {
|
||||||
percent = null;
|
percent = null;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
percent = tmpPercent;
|
||||||
|
alreadyProgressed = true;
|
||||||
|
}
|
||||||
setDialogState!(() {});
|
setDialogState!(() {});
|
||||||
}
|
}
|
||||||
Navigator.of(mainContext!).pop();
|
// done downloading
|
||||||
setState(() {
|
if (prefs!.getBool("resetOnModelSelect") ?? true && allowMultipleChats) {
|
||||||
|
messages = [];
|
||||||
|
chatUuid = null;
|
||||||
|
}
|
||||||
model = requestedModel;
|
model = requestedModel;
|
||||||
if (model!.split(":").length == 1) {
|
if (model!.split(":").length == 1) {
|
||||||
model = "$model:latest";
|
model = "$model:latest";
|
||||||
}
|
}
|
||||||
|
bool exists = false;
|
||||||
|
try {
|
||||||
|
var request = await client.listModels().timeout(Duration(
|
||||||
|
seconds:
|
||||||
|
(10.0 * (prefs!.getDouble("timeoutMultiplier") ?? 1.0)).round()));
|
||||||
|
for (var element in request.models!) {
|
||||||
|
if (element.model == model) {
|
||||||
|
exists = true;
|
||||||
|
multimodal = (element.details!.families ?? []).contains("clip");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!exists) {
|
||||||
|
throw Exception();
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
setState(() {
|
||||||
|
model = null;
|
||||||
|
multimodal = false;
|
||||||
|
chatAllowed = false;
|
||||||
|
});
|
||||||
|
prefs?.remove("model");
|
||||||
|
prefs?.setBool("multimodal", multimodal);
|
||||||
|
Navigator.of(mainContext!).pop();
|
||||||
|
if (!exists) {
|
||||||
|
ScaffoldMessenger.of(mainContext!).showSnackBar(
|
||||||
|
SnackBar(content: Text(downloadFailedText), showCloseIcon: true));
|
||||||
|
} else {
|
||||||
|
ScaffoldMessenger.of(mainContext!).showSnackBar(
|
||||||
|
SnackBar(content: Text(timeoutErrorText), showCloseIcon: true));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
prefs?.setString("model", model!);
|
||||||
|
prefs?.setBool("multimodal", multimodal);
|
||||||
|
setState(() {
|
||||||
chatAllowed = true;
|
chatAllowed = true;
|
||||||
});
|
});
|
||||||
|
Navigator.of(mainContext!).pop();
|
||||||
ScaffoldMessenger.of(mainContext!).showSnackBar(
|
ScaffoldMessenger.of(mainContext!).showSnackBar(
|
||||||
SnackBar(content: Text(downloadSuccessText), showCloseIcon: true));
|
SnackBar(content: Text(downloadSuccessText), showCloseIcon: true));
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
|
|
Loading…
Reference in New Issue