Fixes described in #29
This commit is contained in:
parent
9f4e27758e
commit
0086ec63bc
|
@ -297,6 +297,16 @@
|
||||||
"description": "Text displayed as description for system message input",
|
"description": "Text displayed as description for system message input",
|
||||||
"context": "Visible in the settings view"
|
"context": "Visible in the settings view"
|
||||||
},
|
},
|
||||||
|
"settingsUseSystem": "Use system message",
|
||||||
|
"@settingsUseSystem": {
|
||||||
|
"description": "Text displayed as description for use system message toggle",
|
||||||
|
"context": "Visible in the settings view"
|
||||||
|
},
|
||||||
|
"settingsUseSystemDescription": "Disables setting the system message above and use the one of the model instead. Can be useful for models with model files",
|
||||||
|
"@settingsUseSystemDescription": {
|
||||||
|
"description": "Description of the use system message toggle",
|
||||||
|
"context": "Visible in the settings view by long pressing the toggle"
|
||||||
|
},
|
||||||
"settingsDisableMarkdown": "Disable markdown",
|
"settingsDisableMarkdown": "Disable markdown",
|
||||||
"@settingsDisableMarkdown": {
|
"@settingsDisableMarkdown": {
|
||||||
"description": "Text displayed as description for disable markdown toggle",
|
"description": "Text displayed as description for disable markdown toggle",
|
||||||
|
|
|
@ -566,6 +566,7 @@ class _MainAppState extends State<MainApp> {
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(jsonDecode(item)["title"],
|
child: Text(jsonDecode(item)["title"],
|
||||||
softWrap: false,
|
softWrap: false,
|
||||||
|
maxLines: 1,
|
||||||
overflow: TextOverflow.fade,
|
overflow: TextOverflow.fade,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontWeight: FontWeight.w500)),
|
fontWeight: FontWeight.w500)),
|
||||||
|
|
|
@ -26,7 +26,8 @@ Widget toggle(BuildContext context, String text, bool value,
|
||||||
{bool disabled = false,
|
{bool disabled = false,
|
||||||
void Function()? onDisabledTap,
|
void Function()? onDisabledTap,
|
||||||
void Function()? onLongTap,
|
void Function()? onLongTap,
|
||||||
void Function()? onDoubleTap}) {
|
void Function()? onDoubleTap,
|
||||||
|
Widget? icon}) {
|
||||||
var space = ""; // Invisible character: U+2063
|
var space = ""; // Invisible character: U+2063
|
||||||
var spacePlus = " $space";
|
var spacePlus = " $space";
|
||||||
return InkWell(
|
return InkWell(
|
||||||
|
@ -49,12 +50,19 @@ Widget toggle(BuildContext context, String text, bool value,
|
||||||
padding: const EdgeInsets.only(top: 4, bottom: 4),
|
padding: const EdgeInsets.only(top: 4, bottom: 4),
|
||||||
child: Stack(children: [
|
child: Stack(children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(left: 16, right: 16, top: 12),
|
padding: EdgeInsets.only(
|
||||||
|
left: (icon == null) ? 16 : 32, right: 16, top: 12),
|
||||||
child: Divider(
|
child: Divider(
|
||||||
color: (Theme.of(context).brightness == Brightness.light)
|
color: (Theme.of(context).brightness == Brightness.light)
|
||||||
? Colors.grey[300]
|
? Colors.grey[300]
|
||||||
: Colors.grey[900])),
|
: Colors.grey[900])),
|
||||||
Row(mainAxisSize: MainAxisSize.max, children: [
|
Row(mainAxisSize: MainAxisSize.max, children: [
|
||||||
|
(icon != null)
|
||||||
|
? Padding(
|
||||||
|
padding: const EdgeInsets.only(right: 8),
|
||||||
|
child: icon,
|
||||||
|
)
|
||||||
|
: const SizedBox.shrink(),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(text + spacePlus,
|
child: Text(text + spacePlus,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
|
|
|
@ -66,6 +66,23 @@ class _ScreenSettingsBehaviorState extends State<ScreenSettingsBehavior> {
|
||||||
),
|
),
|
||||||
border: const OutlineInputBorder())),
|
border: const OutlineInputBorder())),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
|
toggle(
|
||||||
|
context,
|
||||||
|
AppLocalizations.of(context)!.settingsUseSystem,
|
||||||
|
(prefs!.getBool("useSystem") ?? true),
|
||||||
|
(value) {
|
||||||
|
selectionHaptic();
|
||||||
|
prefs!.setBool("useSystem", value);
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.info_outline_rounded),
|
||||||
|
onLongTap: () {
|
||||||
|
selectionHaptic();
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
|
content: Text(AppLocalizations.of(context)!
|
||||||
|
.settingsUseSystemDescription),
|
||||||
|
showCloseIcon: true));
|
||||||
|
}),
|
||||||
toggle(
|
toggle(
|
||||||
context,
|
context,
|
||||||
AppLocalizations.of(context)!.settingsDisableMarkdown,
|
AppLocalizations.of(context)!.settingsDisableMarkdown,
|
||||||
|
|
|
@ -25,9 +25,9 @@ Future<List<llama.Message>> getHistory([String? addToSystem]) async {
|
||||||
system += "\n$addToSystem";
|
system += "\n$addToSystem";
|
||||||
}
|
}
|
||||||
|
|
||||||
List<llama.Message> history = [
|
List<llama.Message> history = (prefs!.getBool("useSystem") ?? true)
|
||||||
llama.Message(role: llama.MessageRole.system, content: system)
|
? [llama.Message(role: llama.MessageRole.system, content: system)]
|
||||||
];
|
: [];
|
||||||
List<llama.Message> history2 = [];
|
List<llama.Message> history2 = [];
|
||||||
images = [];
|
images = [];
|
||||||
for (var i = 0; i < messages.length; i++) {
|
for (var i = 0; i < messages.length; i++) {
|
||||||
|
@ -53,6 +53,52 @@ Future<List<llama.Message>> getHistory([String? addToSystem]) async {
|
||||||
return history;
|
return history;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<String> getTitleAi(List history) async {
|
||||||
|
final generated = await (llama.OllamaClient(
|
||||||
|
headers: (jsonDecode(prefs!.getString("hostHeaders") ?? "{}") as Map)
|
||||||
|
.cast<String, String>(),
|
||||||
|
baseUrl: "$host/api"))
|
||||||
|
.generateChatCompletion(
|
||||||
|
request: llama.GenerateChatCompletionRequest(
|
||||||
|
model: model!,
|
||||||
|
messages: [
|
||||||
|
const llama.Message(
|
||||||
|
role: llama.MessageRole.system,
|
||||||
|
content:
|
||||||
|
"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!"),
|
||||||
|
llama.Message(
|
||||||
|
role: llama.MessageRole.user, content: jsonEncode(history))
|
||||||
|
],
|
||||||
|
keepAlive: int.parse(prefs!.getString("keepAlive") ?? "300")),
|
||||||
|
)
|
||||||
|
.timeout(const Duration(seconds: 10));
|
||||||
|
var title = generated.message!.content
|
||||||
|
.replaceAll("\"", "")
|
||||||
|
.replaceAll("'", "")
|
||||||
|
.replaceAll("*", "")
|
||||||
|
.replaceAll("_", "")
|
||||||
|
.replaceAll("\n", " ")
|
||||||
|
.trim();
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setTitleAi(List history) async {
|
||||||
|
try {
|
||||||
|
var title = await getTitleAi(history);
|
||||||
|
var tmp = (prefs!.getStringList("chats") ?? []);
|
||||||
|
for (var i = 0; i < tmp.length; i++) {
|
||||||
|
if (jsonDecode((prefs!.getStringList("chats") ?? [])[i])["uuid"] ==
|
||||||
|
chatUuid) {
|
||||||
|
var tmp2 = jsonDecode(tmp[i]);
|
||||||
|
tmp2["title"] = title;
|
||||||
|
tmp[i] = jsonEncode(tmp2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prefs!.setStringList("chats", tmp);
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
Future<String> send(String value, BuildContext context, Function setState,
|
Future<String> send(String value, BuildContext context, Function setState,
|
||||||
{void Function(String currentText, bool done)? onStream,
|
{void Function(String currentText, bool done)? onStream,
|
||||||
String? addToSystem}) async {
|
String? addToSystem}) async {
|
||||||
|
@ -210,37 +256,7 @@ Future<String> send(String value, BuildContext context, Function setState,
|
||||||
|
|
||||||
if (newChat && (prefs!.getBool("generateTitles") ?? true)) {
|
if (newChat && (prefs!.getBool("generateTitles") ?? true)) {
|
||||||
void setTitle() async {
|
void setTitle() async {
|
||||||
history = await getHistory();
|
await setTitleAi(await getHistory());
|
||||||
|
|
||||||
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")),
|
|
||||||
)
|
|
||||||
.timeout(const Duration(seconds: 10));
|
|
||||||
var title = generated.response!
|
|
||||||
.replaceAll("\"", "")
|
|
||||||
.replaceAll("'", "")
|
|
||||||
.replaceAll("*", "")
|
|
||||||
.replaceAll("_", "")
|
|
||||||
.trim();
|
|
||||||
var tmp = (prefs!.getStringList("chats") ?? []);
|
|
||||||
for (var i = 0; i < tmp.length; i++) {
|
|
||||||
if (jsonDecode((prefs!.getStringList("chats") ?? [])[i])["uuid"] ==
|
|
||||||
chatUuid) {
|
|
||||||
var tmp2 = jsonDecode(tmp[i]);
|
|
||||||
tmp2["title"] = title;
|
|
||||||
tmp[i] = jsonEncode(tmp2);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
prefs!.setStringList("chats", tmp);
|
|
||||||
} catch (_) {}
|
|
||||||
|
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,10 @@ import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
import 'package:ollama_app/worker/desktop.dart';
|
import 'desktop.dart';
|
||||||
import 'haptic.dart';
|
import 'haptic.dart';
|
||||||
import '../main.dart';
|
import '../main.dart';
|
||||||
|
import 'sender.dart';
|
||||||
|
|
||||||
import 'package:dartx/dartx.dart';
|
import 'package:dartx/dartx.dart';
|
||||||
import 'package:ollama_dart/ollama_dart.dart' as llama;
|
import 'package:ollama_dart/ollama_dart.dart' as llama;
|
||||||
|
@ -518,58 +519,8 @@ Future<String> prompt(BuildContext context,
|
||||||
[])[i])["uuid"] ==
|
[])[i])["uuid"] ==
|
||||||
uuid) {
|
uuid) {
|
||||||
try {
|
try {
|
||||||
List history = [];
|
var title = await getTitleAi(
|
||||||
var tmp = jsonDecode(jsonDecode(
|
await getHistory());
|
||||||
(prefs!.getStringList(
|
|
||||||
"chats") ??
|
|
||||||
[])[i])["messages"]);
|
|
||||||
for (var j = 0;
|
|
||||||
j < tmp.length;
|
|
||||||
j++) {
|
|
||||||
if (tmp[j]["type"] != null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
history
|
|
||||||
.add(tmp[j]["content"]);
|
|
||||||
}
|
|
||||||
if (history.isEmpty) {
|
|
||||||
controller
|
|
||||||
.text = AppLocalizations
|
|
||||||
.of(context)!
|
|
||||||
.imageOnlyConversation;
|
|
||||||
setLocalState(() {
|
|
||||||
loading = false;
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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```",
|
|
||||||
keepAlive: int.parse(
|
|
||||||
prefs!.getString(
|
|
||||||
"keepAlive") ??
|
|
||||||
"300")),
|
|
||||||
)
|
|
||||||
.timeout(const Duration(
|
|
||||||
seconds: 10));
|
|
||||||
var title = generated.response!
|
|
||||||
.replaceAll("\"", "")
|
|
||||||
.replaceAll("'", "")
|
|
||||||
.replaceAll("*", "")
|
|
||||||
.replaceAll("_", "")
|
|
||||||
.trim();
|
|
||||||
controller.text = title;
|
controller.text = title;
|
||||||
setLocalState(() {
|
setLocalState(() {
|
||||||
loading = false;
|
loading = false;
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
"settingsDescriptionVoice",
|
"settingsDescriptionVoice",
|
||||||
"settingsDescriptionExport",
|
"settingsDescriptionExport",
|
||||||
"settingsDescriptionAbout",
|
"settingsDescriptionAbout",
|
||||||
|
"settingsUseSystem",
|
||||||
|
"settingsUseSystemDescription",
|
||||||
"settingsPreloadModels",
|
"settingsPreloadModels",
|
||||||
"settingsVoiceTtsNotSupported",
|
"settingsVoiceTtsNotSupported",
|
||||||
"settingsVoiceTtsNotSupportedDescription",
|
"settingsVoiceTtsNotSupportedDescription",
|
||||||
|
@ -17,6 +19,8 @@
|
||||||
"settingsDescriptionVoice",
|
"settingsDescriptionVoice",
|
||||||
"settingsDescriptionExport",
|
"settingsDescriptionExport",
|
||||||
"settingsDescriptionAbout",
|
"settingsDescriptionAbout",
|
||||||
|
"settingsUseSystem",
|
||||||
|
"settingsUseSystemDescription",
|
||||||
"settingsPreloadModels",
|
"settingsPreloadModels",
|
||||||
"settingsVoiceTtsNotSupported",
|
"settingsVoiceTtsNotSupported",
|
||||||
"settingsVoiceTtsNotSupportedDescription",
|
"settingsVoiceTtsNotSupportedDescription",
|
||||||
|
|
Loading…
Reference in New Issue