Fixed title generator, fixed updater (hopefully)

This commit is contained in:
JHubi1 2024-06-08 22:38:56 +02:00
parent da95e2d106
commit 5520987684
No known key found for this signature in database
GPG Key ID: 7BF82570CBBBD050
3 changed files with 106 additions and 79 deletions

View File

@ -1185,14 +1185,13 @@ class _MainAppState extends State<MainApp> {
final stream = client final stream = client
.generateChatCompletionStream( .generateChatCompletionStream(
request: llama.GenerateChatCompletionRequest( request: llama.GenerateChatCompletionRequest(
model: model!, model: model!,
messages: history, messages: history,
keepAlive: int.parse(prefs! keepAlive: int.parse(
.getString("keepAlive") ?? prefs!.getString("keepAlive") ??
"300") "300")),
),
) )
.timeout(const Duration(seconds: 15)); .timeout(const Duration(seconds: 30));
String text = ""; String text = "";
await for (final res in stream) { await for (final res in stream) {
@ -1221,14 +1220,13 @@ class _MainAppState extends State<MainApp> {
request = await client request = await client
.generateChatCompletion( .generateChatCompletion(
request: llama.GenerateChatCompletionRequest( request: llama.GenerateChatCompletionRequest(
model: model!, model: model!,
messages: history, messages: history,
keepAlive: int.parse(prefs! keepAlive: int.parse(
.getString("keepAlive") ?? prefs!.getString("keepAlive") ??
"300") "300")),
),
) )
.timeout(const Duration(seconds: 15)); .timeout(const Duration(seconds: 30));
if (chatAllowed) return; if (chatAllowed) return;
if (request.message!.content.trim() == "") { if (request.message!.content.trim() == "") {
throw Exception(); throw Exception();
@ -1297,17 +1295,20 @@ class _MainAppState extends State<MainApp> {
history = history.reversed.toList(); history = history.reversed.toList();
try { try {
final generated = await client.generateCompletion( final generated = await client
request: llama.GenerateCompletionRequest( .generateCompletion(
model: model!, request: llama.GenerateCompletionRequest(
prompt: model: model!,
"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```", prompt:
keepAlive: int.parse(prefs! "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```",
.getString("keepAlive") ?? keepAlive: int.parse(
"300") prefs!.getString("keepAlive") ??
), "300")),
); )
.timeout(const Duration(seconds: 10));
var title = generated.response! var title = generated.response!
.replaceAll("\"", "")
.replaceAll("'", "")
.replaceAll("*", "") .replaceAll("*", "")
.replaceAll("_", "") .replaceAll("_", "")
.trim(); .trim();

View File

@ -458,10 +458,11 @@ Future<String> prompt(BuildContext context,
for (var j = 0; for (var j = 0;
j < tmp.length; j < tmp.length;
j++) { j++) {
if (tmp[j]["text"] == null) { if (tmp[j]["type"] != null) {
continue; continue;
} }
history.add(tmp[j]["text"]); history
.add(tmp[j]["content"]);
} }
if (history.isEmpty) { if (history.isEmpty) {
controller controller
@ -482,18 +483,22 @@ Future<String> prompt(BuildContext context,
"{}") as Map) "{}") as Map)
.cast<String, String>(), .cast<String, String>(),
baseUrl: "$host/api", baseUrl: "$host/api",
).generateCompletion( )
request: llama .generateCompletion(
.GenerateCompletionRequest( request: llama.GenerateCompletionRequest(
model: model!, model: model!,
prompt: 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```", "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( keepAlive: int.parse(
prefs!.getString( prefs!.getString(
"keepAlive") ?? "keepAlive") ??
"300")), "300")),
); )
.timeout(const Duration(
seconds: 10));
var title = generated.response! var title = generated.response!
.replaceAll("\"", "")
.replaceAll("'", "")
.replaceAll("*", "") .replaceAll("*", "")
.replaceAll("_", "") .replaceAll("_", "")
.trim(); .trim();
@ -501,7 +506,22 @@ Future<String> prompt(BuildContext context,
setLocalState(() { setLocalState(() {
loading = false; 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; break;
} }
} }

View File

@ -35,13 +35,12 @@ Future<bool> updatesSupported(Function setState,
]; ];
if (!(Platform.isWindows || Platform.isLinux || Platform.isMacOS)) { if (!(Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
if ((await InstallReferrer.referrer != if ((await InstallReferrer.referrer !=
InstallationAppReferrer.androidManually) && InstallationAppReferrer.androidManually) ||
!(installerApps (installerApps
.contains((await InstallReferrer.app).packageName ?? ""))) { .contains((await InstallReferrer.app).packageName ?? ""))) {
returnValue = false; returnValue = false;
if (await InstallReferrer.referrer == if (await InstallReferrer.referrer ==
InstallationAppReferrer.androidDebug || InstallationAppReferrer.androidDebug) {
await InstallReferrer.referrer == InstallationAppReferrer.iosDebug) {
returnValue = true; returnValue = true;
} }
} }
@ -60,54 +59,61 @@ Future<bool> updatesSupported(Function setState,
} }
void checkUpdate(Function setState) async { 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 { try {
var request = await http setState(() {
.get(Uri.parse( updateChecked = true;
"https://api.github.com/repos/${repo[3]}/${repo[4]}/releases")) updateLoading = true;
.timeout(const Duration(seconds: 5)); });
if (request.statusCode == 403) {
if (!await updatesSupported(setState)) {
setState(() { setState(() {
updateStatus = "rateLimit"; updateStatus = "notAvailable";
updateLoading = false; updateLoading = false;
}); });
return; return;
} }
version = jsonDecode(request.body)[0]["tag_name"];
updateChangeLog = jsonDecode(request.body)[0]["body"]; var repo = repoUrl.split("/");
updateUrl = jsonDecode(request.body)[0]["html_url"];
} catch (_) { 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(() { setState(() {
updateStatus = "error"; updateStatus = "error";
updateLoading = false; updateLoading = false;
}); });
return;
} }
latestVersion = version;
updateStatus = "ok";
setState(() {
updateLoading = false;
});
} }
void updateDialog(BuildContext context, Function title) { void updateDialog(BuildContext context, Function title) {