You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.0 KiB
Dart
73 lines
2.0 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:fluffychat/pangea/constants/model_keys.dart';
|
|
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
import '../constants/pangea_event_types.dart';
|
|
|
|
class BotOptionsModel {
|
|
int? languageLevel;
|
|
String topic;
|
|
List<String> keywords;
|
|
bool safetyModeration;
|
|
|
|
BotOptionsModel({
|
|
this.languageLevel,
|
|
this.topic = "General Conversation",
|
|
this.keywords = const [],
|
|
this.safetyModeration = true,
|
|
});
|
|
|
|
factory BotOptionsModel.fromJson(json) {
|
|
return BotOptionsModel(
|
|
languageLevel: json[ModelKey.languageLevel],
|
|
topic: json[ModelKey.conversationTopic] ?? "General Conversation",
|
|
keywords: (json[ModelKey.keywords] ?? []).cast<String>(),
|
|
safetyModeration: json[ModelKey.safetyModeration] ?? true,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
final data = <String, dynamic>{};
|
|
try {
|
|
// data[ModelKey.isConversationBotChat] = isConversationBotChat;
|
|
data[ModelKey.languageLevel] = languageLevel;
|
|
data[ModelKey.conversationTopic] = topic;
|
|
data[ModelKey.keywords] = keywords;
|
|
data[ModelKey.safetyModeration] = safetyModeration;
|
|
return data;
|
|
} catch (e, s) {
|
|
debugger(when: kDebugMode);
|
|
ErrorHandler.logError(e: e, s: s);
|
|
return data;
|
|
}
|
|
}
|
|
|
|
//TODO: define enum with all possible values
|
|
updateBotOption(String key, dynamic value) {
|
|
switch (key) {
|
|
case ModelKey.languageLevel:
|
|
languageLevel = value;
|
|
break;
|
|
case ModelKey.conversationTopic:
|
|
topic = value;
|
|
break;
|
|
case ModelKey.keywords:
|
|
keywords = value;
|
|
break;
|
|
case ModelKey.safetyModeration:
|
|
safetyModeration = value;
|
|
break;
|
|
default:
|
|
throw Exception('Invalid key for bot options - $key');
|
|
}
|
|
}
|
|
|
|
StateEvent get toStateEvent => StateEvent(
|
|
content: toJson(),
|
|
type: PangeaEventTypes.botOptions,
|
|
);
|
|
}
|