Added custom header option
This commit is contained in:
parent
8eb3dfb35e
commit
94820a300e
|
@ -130,7 +130,7 @@
|
||||||
"description": "Text displayed as description for new title input",
|
"description": "Text displayed as description for new title input",
|
||||||
"context": "Visible in the rename dialog"
|
"context": "Visible in the rename dialog"
|
||||||
},
|
},
|
||||||
"dialogEditMessageTitle": "Edit Message",
|
"dialogEditMessageTitle": "Edit message",
|
||||||
"@dialogEditMessageTitle": {
|
"@dialogEditMessageTitle": {
|
||||||
"description": "Title of the edit message dialog",
|
"description": "Title of the edit message dialog",
|
||||||
"context": "Visible in the edit message dialog"
|
"context": "Visible in the edit message dialog"
|
||||||
|
@ -181,6 +181,16 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"settingsHostHeaderTitle": "Set host header",
|
||||||
|
"@settingsHostHeader": {
|
||||||
|
"description": "Text displayed as description for host header input",
|
||||||
|
"context": "Visible in the settings view"
|
||||||
|
},
|
||||||
|
"settingsHostHeaderInvalid": "The entered text isn't a valid header JSON object",
|
||||||
|
"@settingsHostHeaderInvalid": {
|
||||||
|
"description": "Text displayed when the host header is invalid",
|
||||||
|
"context": "Visible in the settings view"
|
||||||
|
},
|
||||||
"settingsHostInvalidDetailed": "{type, select, url{The URL you entered is invalid. It isn't an a standardized URL format.} other{The host you entered is invalid. It cannot be reached. Please check the host and try again.}}",
|
"settingsHostInvalidDetailed": "{type, select, url{The URL you entered is invalid. It isn't an a standardized URL format.} other{The host you entered is invalid. It cannot be reached. Please check the host and try again.}}",
|
||||||
"@settingsHostInvalidDetailed": {
|
"@settingsHostInvalidDetailed": {
|
||||||
"description": "Text displayed when the host is invalid",
|
"description": "Text displayed when the host is invalid",
|
||||||
|
|
|
@ -674,8 +674,12 @@ class _MainAppState extends State<MainApp> {
|
||||||
chatAllowed = false;
|
chatAllowed = false;
|
||||||
|
|
||||||
String newId = const Uuid().v4();
|
String newId = const Uuid().v4();
|
||||||
llama.OllamaClient client =
|
llama.OllamaClient client = llama.OllamaClient(
|
||||||
llama.OllamaClient(baseUrl: "$host/api");
|
headers:
|
||||||
|
(jsonDecode(prefs!.getString("hostHeaders") ?? "{}")
|
||||||
|
as Map)
|
||||||
|
.cast<String, String>(),
|
||||||
|
baseUrl: "$host/api");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ((prefs!.getString("requestType") ?? "stream") ==
|
if ((prefs!.getString("requestType") ?? "stream") ==
|
||||||
|
@ -1242,7 +1246,6 @@ class _MainAppState extends State<MainApp> {
|
||||||
title: AppLocalizations.of(context)!
|
title: AppLocalizations.of(context)!
|
||||||
.dialogEnterNewTitle,
|
.dialogEnterNewTitle,
|
||||||
value: oldTitle,
|
value: oldTitle,
|
||||||
force: false,
|
|
||||||
uuid: jsonDecode(item)["uuid"]);
|
uuid: jsonDecode(item)["uuid"]);
|
||||||
var tmp = (prefs!.getStringList("chats") ?? []);
|
var tmp = (prefs!.getStringList("chats") ?? []);
|
||||||
for (var i = 0; i < tmp.length; i++) {
|
for (var i = 0; i < tmp.length; i++) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import 'package:flutter/services.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
import 'main.dart';
|
import 'main.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:ollama_app/worker_setter.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
import 'package:dartx/dartx.dart';
|
import 'package:dartx/dartx.dart';
|
||||||
|
@ -16,6 +16,7 @@ import 'package:url_launcher/url_launcher.dart';
|
||||||
import 'package:restart_app/restart_app.dart';
|
import 'package:restart_app/restart_app.dart';
|
||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:pick_or_save/pick_or_save.dart';
|
import 'package:pick_or_save/pick_or_save.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
class ScreenSettings extends StatefulWidget {
|
class ScreenSettings extends StatefulWidget {
|
||||||
const ScreenSettings({super.key});
|
const ScreenSettings({super.key});
|
||||||
|
@ -49,7 +50,11 @@ class _ScreenSettingsState extends State<ScreenSettings> {
|
||||||
http.Response request;
|
http.Response request;
|
||||||
try {
|
try {
|
||||||
request = await http
|
request = await http
|
||||||
.get(Uri.parse(tmpHost))
|
.get(
|
||||||
|
Uri.parse(tmpHost),
|
||||||
|
headers: (jsonDecode(prefs!.getString("hostHeaders") ?? "{}") as Map)
|
||||||
|
.cast<String, String>(),
|
||||||
|
)
|
||||||
.timeout(const Duration(seconds: 5), onTimeout: () {
|
.timeout(const Duration(seconds: 5), onTimeout: () {
|
||||||
return http.Response("Error", 408);
|
return http.Response("Error", 408);
|
||||||
});
|
});
|
||||||
|
@ -165,6 +170,29 @@ class _ScreenSettingsState extends State<ScreenSettings> {
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: AppLocalizations.of(context)!.settingsHost,
|
labelText: AppLocalizations.of(context)!.settingsHost,
|
||||||
hintText: "http://localhost:11434",
|
hintText: "http://localhost:11434",
|
||||||
|
prefixIcon: IconButton(
|
||||||
|
onPressed: () async {
|
||||||
|
HapticFeedback.selectionClick();
|
||||||
|
String tmp = await prompt(context,
|
||||||
|
placeholder:
|
||||||
|
"{\"Authorization\": \"Bearer ...\"}",
|
||||||
|
title: AppLocalizations.of(context)!
|
||||||
|
.settingsHostHeaderTitle,
|
||||||
|
value: (prefs!.getString("hostHeaders") ??
|
||||||
|
""), validator: (content) async {
|
||||||
|
try {
|
||||||
|
var tmp = jsonDecode(content);
|
||||||
|
tmp as Map<String, dynamic>;
|
||||||
|
return true;
|
||||||
|
} catch (_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
validatorError: AppLocalizations.of(context)!
|
||||||
|
.settingsHostHeaderInvalid);
|
||||||
|
prefs!.setString("hostHeaders", tmp);
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.add_rounded)),
|
||||||
suffixIcon: useHost
|
suffixIcon: useHost
|
||||||
? const SizedBox.shrink()
|
? const SizedBox.shrink()
|
||||||
: (hostLoading
|
: (hostLoading
|
||||||
|
|
|
@ -21,7 +21,12 @@ void setModel(BuildContext context, Function setState) {
|
||||||
bool loaded = false;
|
bool loaded = false;
|
||||||
Function? setModalState;
|
Function? setModalState;
|
||||||
void load() async {
|
void load() async {
|
||||||
var list = await llama.OllamaClient(baseUrl: "$host/api").listModels();
|
var list = await llama.OllamaClient(
|
||||||
|
headers:
|
||||||
|
(jsonDecode(prefs!.getString("hostHeaders") ?? "{}") as Map)
|
||||||
|
.cast<String, String>(),
|
||||||
|
baseUrl: "$host/api")
|
||||||
|
.listModels();
|
||||||
for (var i = 0; i < list.models!.length; i++) {
|
for (var i = 0; i < list.models!.length; i++) {
|
||||||
models.add(list.models![i].model!.split(":")[0]);
|
models.add(list.models![i].model!.split(":")[0]);
|
||||||
modelsReal.add(list.models![i].model!);
|
modelsReal.add(list.models![i].model!);
|
||||||
|
@ -284,15 +289,18 @@ Future<String> prompt(BuildContext context,
|
||||||
{String description = "",
|
{String description = "",
|
||||||
String value = "",
|
String value = "",
|
||||||
String title = "",
|
String title = "",
|
||||||
bool force = false,
|
|
||||||
String? valueIfCanceled,
|
String? valueIfCanceled,
|
||||||
TextInputType keyboard = TextInputType.text,
|
TextInputType keyboard = TextInputType.text,
|
||||||
Icon? prefixIcon,
|
Icon? prefixIcon,
|
||||||
int maxLines = 1,
|
int maxLines = 1,
|
||||||
String? uuid}) async {
|
String? uuid,
|
||||||
|
Future<bool> Function(String content)? validator,
|
||||||
|
String? validatorError,
|
||||||
|
String? placeholder}) async {
|
||||||
var returnText = (valueIfCanceled != null) ? valueIfCanceled : value;
|
var returnText = (valueIfCanceled != null) ? valueIfCanceled : value;
|
||||||
final TextEditingController controller = TextEditingController(text: value);
|
final TextEditingController controller = TextEditingController(text: value);
|
||||||
bool loading = false;
|
bool loading = false;
|
||||||
|
String? error;
|
||||||
await showModalBottomSheet(
|
await showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
|
@ -329,9 +337,25 @@ Future<String> prompt(BuildContext context,
|
||||||
maxLines: maxLines,
|
maxLines: maxLines,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
border: const OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
|
hintText: placeholder,
|
||||||
|
errorText: error,
|
||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
|
if (validator != null) {
|
||||||
|
setLocalState(() {
|
||||||
|
error = null;
|
||||||
|
});
|
||||||
|
bool valid =
|
||||||
|
await validator(controller.text);
|
||||||
|
if (!valid) {
|
||||||
|
setLocalState(() {
|
||||||
|
error = validatorError;
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
returnText = controller.text;
|
returnText = controller.text;
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.save_rounded)),
|
icon: const Icon(Icons.save_rounded)),
|
||||||
|
@ -381,10 +405,14 @@ Future<String> prompt(BuildContext context,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final generated =
|
final generated = await llama.OllamaClient(
|
||||||
await llama.OllamaClient(
|
headers: (jsonDecode(prefs!
|
||||||
baseUrl:
|
.getString(
|
||||||
"$host/api")
|
"hostHeaders") ??
|
||||||
|
"{}") as Map)
|
||||||
|
.cast<String,
|
||||||
|
String>(),
|
||||||
|
baseUrl: "$host/api")
|
||||||
.generateCompletion(
|
.generateCompletion(
|
||||||
request: llama
|
request: llama
|
||||||
.GenerateCompletionRequest(
|
.GenerateCompletionRequest(
|
||||||
|
|
Loading…
Reference in New Issue