diff --git a/lib/main.dart b/lib/main.dart index ecabcc0..0da1c26 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1185,14 +1185,13 @@ class _MainAppState extends State { final stream = client .generateChatCompletionStream( request: llama.GenerateChatCompletionRequest( - model: model!, - messages: history, - keepAlive: int.parse(prefs! - .getString("keepAlive") ?? - "300") - ), + model: model!, + messages: history, + keepAlive: int.parse( + prefs!.getString("keepAlive") ?? + "300")), ) - .timeout(const Duration(seconds: 15)); + .timeout(const Duration(seconds: 30)); String text = ""; await for (final res in stream) { @@ -1221,14 +1220,13 @@ class _MainAppState extends State { request = await client .generateChatCompletion( request: llama.GenerateChatCompletionRequest( - model: model!, - messages: history, - keepAlive: int.parse(prefs! - .getString("keepAlive") ?? - "300") - ), + model: model!, + messages: history, + keepAlive: int.parse( + prefs!.getString("keepAlive") ?? + "300")), ) - .timeout(const Duration(seconds: 15)); + .timeout(const Duration(seconds: 30)); if (chatAllowed) return; if (request.message!.content.trim() == "") { throw Exception(); @@ -1297,17 +1295,20 @@ class _MainAppState extends State { history = history.reversed.toList(); try { - final generated = await client.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```", - keepAlive: int.parse(prefs! - .getString("keepAlive") ?? - "300") - ), - ); + final generated = await client + .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```", + keepAlive: int.parse( + prefs!.getString("keepAlive") ?? + "300")), + ) + .timeout(const Duration(seconds: 10)); var title = generated.response! + .replaceAll("\"", "") + .replaceAll("'", "") .replaceAll("*", "") .replaceAll("_", "") .trim(); diff --git a/lib/worker/setter.dart b/lib/worker/setter.dart index 4077f46..5097d44 100644 --- a/lib/worker/setter.dart +++ b/lib/worker/setter.dart @@ -458,10 +458,11 @@ Future prompt(BuildContext context, for (var j = 0; j < tmp.length; j++) { - if (tmp[j]["text"] == null) { + if (tmp[j]["type"] != null) { continue; } - history.add(tmp[j]["text"]); + history + .add(tmp[j]["content"]); } if (history.isEmpty) { controller @@ -482,18 +483,22 @@ Future prompt(BuildContext context, "{}") as Map) .cast(), 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```", - keepAlive: int.parse( - prefs!.getString( - "keepAlive") ?? - "300")), - ); + ) + .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```", + keepAlive: int.parse( + prefs!.getString( + "keepAlive") ?? + "300")), + ) + .timeout(const Duration( + seconds: 10)); var title = generated.response! + .replaceAll("\"", "") + .replaceAll("'", "") .replaceAll("*", "") .replaceAll("_", "") .trim(); @@ -501,7 +506,22 @@ Future prompt(BuildContext context, setLocalState(() { loading = false; }); - } catch (_) {} + } catch (_) { + try { + setLocalState(() { + loading = false; + }); + // ignore: use_build_context_synchronously + ScaffoldMessenger.of(context) + .showSnackBar(SnackBar( + content: Text(AppLocalizations.of( + // ignore: use_build_context_synchronously + context)! + .settingsHostInvalid( + "timeout")), + showCloseIcon: true)); + } catch (_) {} + } break; } } diff --git a/lib/worker/update.dart b/lib/worker/update.dart index ab7ae5e..a9c5f7e 100644 --- a/lib/worker/update.dart +++ b/lib/worker/update.dart @@ -35,13 +35,12 @@ Future updatesSupported(Function setState, ]; if (!(Platform.isWindows || Platform.isLinux || Platform.isMacOS)) { if ((await InstallReferrer.referrer != - InstallationAppReferrer.androidManually) && - !(installerApps + InstallationAppReferrer.androidManually) || + (installerApps .contains((await InstallReferrer.app).packageName ?? ""))) { returnValue = false; if (await InstallReferrer.referrer == - InstallationAppReferrer.androidDebug || - await InstallReferrer.referrer == InstallationAppReferrer.iosDebug) { + InstallationAppReferrer.androidDebug) { returnValue = true; } } @@ -60,54 +59,61 @@ Future updatesSupported(Function setState, } void checkUpdate(Function setState) async { - setState(() { - updateChecked = true; - updateLoading = true; - }); - - if (!await updatesSupported(setState)) { - setState(() { - updateStatus = "notAvailable"; - updateLoading = false; - }); - return; - } - - var repo = repoUrl.split("/"); - - currentVersion = (await PackageInfo.fromPlatform()).version; - // currentVersion = "1.0.0"; - - String? version; try { - var request = await http - .get(Uri.parse( - "https://api.github.com/repos/${repo[3]}/${repo[4]}/releases")) - .timeout(const Duration(seconds: 5)); - if (request.statusCode == 403) { + setState(() { + updateChecked = true; + updateLoading = true; + }); + + if (!await updatesSupported(setState)) { setState(() { - updateStatus = "rateLimit"; + updateStatus = "notAvailable"; updateLoading = false; }); return; } - version = jsonDecode(request.body)[0]["tag_name"]; - updateChangeLog = jsonDecode(request.body)[0]["body"]; - updateUrl = jsonDecode(request.body)[0]["html_url"]; - } catch (_) { + + var repo = repoUrl.split("/"); + + currentVersion = (await PackageInfo.fromPlatform()).version; + // currentVersion = "1.0.0"; + + String? version; + try { + var request = await http + .get(Uri.parse( + "https://api.github.com/repos/${repo[3]}/${repo[4]}/releases")) + .timeout(const Duration(seconds: 5)); + if (request.statusCode == 403) { + setState(() { + updateStatus = "rateLimit"; + updateLoading = false; + }); + return; + } + version = jsonDecode(request.body)[0]["tag_name"]; + updateChangeLog = jsonDecode(request.body)[0]["body"]; + updateUrl = jsonDecode(request.body)[0]["html_url"]; + } catch (_) { + setState(() { + updateStatus = "error"; + updateLoading = false; + }); + return; + } + + latestVersion = version; + updateStatus = "ok"; + + setState(() { + updateLoading = false; + }); + } catch (e) { setState(() { updateStatus = "error"; updateLoading = false; }); - return; } - - latestVersion = version; - updateStatus = "ok"; - - setState(() { - updateLoading = false; - }); } void updateDialog(BuildContext context, Function title) {