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
.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<MainApp> {
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<MainApp> {
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();

View File

@ -458,10 +458,11 @@ Future<String> 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<String> prompt(BuildContext context,
"{}") 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```",
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<String> 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;
}
}

View File

@ -35,13 +35,12 @@ Future<bool> 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<bool> 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) {