"Updated BotAssistantsReqModel, RequestHelper, AiChatState, BotAssistantsPage, CreateBotAssistantsPage, and CreateBotAssistantsState with various changes to fields, methods, and UI components."
This commit is contained in:
parent
dfd57937fb
commit
a2c8b5ddac
|
|
@ -11,6 +11,7 @@ class BotAssistantsReqModel {
|
|||
final String? youtubeLink;
|
||||
final List<String>? webLinks;
|
||||
final bool isPrivate;
|
||||
final bool? deleteImage;
|
||||
|
||||
BotAssistantsReqModel(
|
||||
{required this.type,
|
||||
|
|
@ -22,6 +23,7 @@ class BotAssistantsReqModel {
|
|||
this.files,
|
||||
this.youtubeLink,
|
||||
this.webLinks,
|
||||
this.deleteImage,
|
||||
this.isPrivate = true});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
|
|
@ -35,6 +37,9 @@ class BotAssistantsReqModel {
|
|||
if (youtubeLink != null) {
|
||||
data['youtubeLink'] = youtubeLink;
|
||||
}
|
||||
if (deleteImage != null) {
|
||||
data['deleteImage'] = deleteImage;
|
||||
}
|
||||
if (webLinks != null) {
|
||||
data['webLinks'] = webLinks;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -231,14 +231,14 @@ class RequestHelper {
|
|||
static String placeholder(int id) => '$baseUrl/ai/chat/$id/placeholder';
|
||||
static String tools() => '$baseUrl/ai/tool';
|
||||
static String usersAssistants({final bool personal = false}) =>
|
||||
'$baseUrl/ai/bot/user${_urlConcatGenerator([
|
||||
'$baseUrl/ai/user/bot${_urlConcatGenerator([
|
||||
MapEntry('personal', personal),
|
||||
])}';
|
||||
static String createAssistants() => '$baseUrl/ai/bot';
|
||||
static String updateAssistants(int id) => '$baseUrl/ai/bot/$id';
|
||||
static String getAssistant(int id) => '$baseUrl/ai/bot/user/$id';
|
||||
static String deleteAssistant(int id) => '$baseUrl/ai/bot/user/$id';
|
||||
static String nameOfAssistant() => '$baseUrl/ai/bot/name';
|
||||
static String createAssistants() => '$baseUrl/ai/user/bot';
|
||||
static String updateAssistants(int id) => '$baseUrl/ai/user/bot/$id';
|
||||
static String getAssistant(int id) => '$baseUrl/ai/user/bot/$id';
|
||||
static String deleteAssistant(int id) => '$baseUrl/ai/user/bot/$id';
|
||||
static String nameOfAssistant() => '$baseUrl/ai/user/bot/name';
|
||||
|
||||
static String _urlConcatGenerator(List<MapEntry<String, dynamic>> additions) {
|
||||
String result = '';
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ class AiChatState extends CoreProvier {
|
|||
// }
|
||||
|
||||
final req = await AiApiService.initial(
|
||||
url: '${isAssistants ? '/custom' : ''}/${bot.id}/${bot.name}'
|
||||
url: '${isAssistants ? '/user' : ''}/${bot.id}/${bot.name}'
|
||||
.toLowerCase(),
|
||||
message: message,
|
||||
chatId: chatId,
|
||||
|
|
|
|||
|
|
@ -187,8 +187,10 @@ class _BotAssistantsPageState extends State<BotAssistantsPage> {
|
|||
return Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 32),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white, borderRadius: DesignConfig.lowBorderRadius),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: const Color(0xffe0e0e0)),
|
||||
color: Colors.white,
|
||||
borderRadius: DesignConfig.lowBorderRadius),
|
||||
child: Column(
|
||||
children: [
|
||||
if (state.isMyAssistants)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import 'package:didvan/models/ai/bots_model.dart';
|
|||
import 'package:didvan/models/ai/file_create_assistants_model.dart';
|
||||
import 'package:didvan/models/enums.dart';
|
||||
import 'package:didvan/models/view/action_sheet_data.dart';
|
||||
import 'package:didvan/models/view/alert_data.dart';
|
||||
import 'package:didvan/services/media/media.dart';
|
||||
import 'package:didvan/utils/action_sheet.dart';
|
||||
import 'package:didvan/utils/extension.dart';
|
||||
|
|
@ -104,7 +105,8 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
resultFiles.add(file.file!);
|
||||
}
|
||||
}
|
||||
await state.createAssistants(
|
||||
|
||||
final success = await state.createAssistants(
|
||||
id: widget.id,
|
||||
data: BotAssistantsReqModel(
|
||||
type: selectedBotType,
|
||||
|
|
@ -116,11 +118,19 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
// youtubeLink: youtubeLink,
|
||||
isPrivate: isPrivate,
|
||||
files: resultFiles,
|
||||
deleteImage: assistant != null
|
||||
? assistant!.image == null
|
||||
: image.value == null,
|
||||
image: image.value));
|
||||
|
||||
if (success) {
|
||||
context.read<BotAssistantsState>().getMyAssissmant();
|
||||
context.read<CreateBotAssistantsState>().assistant = null;
|
||||
Navigator.pop(context);
|
||||
} else {
|
||||
ActionSheetUtils(context).showAlert(AlertData(
|
||||
message: 'مشکلی در ارتباط با سرور پیش آمده دوباره تلاش کنید',
|
||||
aLertType: ALertType.error));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -193,6 +203,7 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
child: CustomDropdown<String>(
|
||||
closedHeaderPadding: const EdgeInsets.all(12),
|
||||
items: botModels,
|
||||
enabled: assistant == null,
|
||||
initialItem: botModels[0],
|
||||
hideSelectedFieldWhenExpanded: false,
|
||||
decoration: CustomDropdownDecoration(
|
||||
|
|
@ -286,12 +297,14 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
if (value.isEmpty) {
|
||||
return;
|
||||
}
|
||||
if (assistant == null) {
|
||||
_timer?.cancel();
|
||||
_timer =
|
||||
Timer(const Duration(seconds: 1), () async {
|
||||
await state.getAssistantsName(name: value);
|
||||
_formNameKey.currentState!.validate();
|
||||
});
|
||||
}
|
||||
},
|
||||
validator: (value) {
|
||||
String? result;
|
||||
|
|
@ -299,7 +312,8 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
result = 'نام نباید خالی باشد';
|
||||
} else if (value.length < 4) {
|
||||
result = 'نام نباید کمتر از 4 حرف باشد';
|
||||
} else if (!state.successName) {
|
||||
} else if (assistant == null &&
|
||||
!state.successName) {
|
||||
result =
|
||||
'اسم دیگری انتخاب کنید این اسم موجود است';
|
||||
}
|
||||
|
|
@ -312,7 +326,6 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
const SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
|
|
@ -420,7 +433,6 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
},
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(
|
||||
height: 24,
|
||||
),
|
||||
|
|
@ -454,27 +466,34 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
const SizedBox(
|
||||
height: 24,
|
||||
),
|
||||
if (assistant == null)
|
||||
Column(
|
||||
children: [
|
||||
if (selectedBotType == 'text')
|
||||
Column(
|
||||
children: [
|
||||
title(text: 'پایگاه دانش', isRequired: false),
|
||||
title(
|
||||
text: 'پایگاه دانش', isRequired: false),
|
||||
if (files.length != 3)
|
||||
SizedBox(
|
||||
height: 48,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Theme.of(context)
|
||||
backgroundColor:
|
||||
Theme.of(context)
|
||||
.colorScheme
|
||||
.disabledBackground,
|
||||
shape: const RoundedRectangleBorder(
|
||||
shape:
|
||||
const RoundedRectangleBorder(
|
||||
borderRadius: DesignConfig
|
||||
.lowBorderRadius)),
|
||||
onPressed: () async {
|
||||
final picks =
|
||||
await MediaService.pickMultiFile();
|
||||
final picks = await MediaService
|
||||
.pickMultiFile();
|
||||
if (picks != null) {
|
||||
for (var file in picks.xFiles) {
|
||||
files.add(FileCreateAssistantsModel(
|
||||
files.add(
|
||||
FileCreateAssistantsModel(
|
||||
fromNetwork: false,
|
||||
file: file,
|
||||
url: null));
|
||||
|
|
@ -515,17 +534,20 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
return Stack(
|
||||
children: [
|
||||
Container(
|
||||
width: MediaQuery.sizeOf(context)
|
||||
width: MediaQuery.sizeOf(
|
||||
context)
|
||||
.width /
|
||||
5,
|
||||
height: MediaQuery.sizeOf(context)
|
||||
height: MediaQuery.sizeOf(
|
||||
context)
|
||||
.width /
|
||||
5,
|
||||
margin:
|
||||
const EdgeInsets.symmetric(
|
||||
margin: const EdgeInsets
|
||||
.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 12),
|
||||
padding: const EdgeInsets.all(8),
|
||||
padding: const EdgeInsets
|
||||
.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
|
|
@ -551,8 +573,9 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
.file!
|
||||
.path
|
||||
.isImage()
|
||||
? Image.file(File(
|
||||
files[index]
|
||||
? Image.file(
|
||||
File(files[
|
||||
index]
|
||||
.file!
|
||||
.path))
|
||||
: const Icon(
|
||||
|
|
@ -570,8 +593,10 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
.file!
|
||||
.name,
|
||||
textDirection:
|
||||
TextDirection.rtl,
|
||||
style: Theme.of(context)
|
||||
TextDirection
|
||||
.rtl,
|
||||
style: Theme.of(
|
||||
context)
|
||||
.textTheme
|
||||
.labelSmall!)
|
||||
],
|
||||
|
|
@ -586,14 +611,19 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
},
|
||||
child: Container(
|
||||
padding:
|
||||
const EdgeInsets.all(6),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Theme.of(context)
|
||||
const EdgeInsets
|
||||
.all(6),
|
||||
decoration:
|
||||
BoxDecoration(
|
||||
shape: BoxShape
|
||||
.circle,
|
||||
color: Theme.of(
|
||||
context)
|
||||
.colorScheme
|
||||
.error),
|
||||
child: const Icon(
|
||||
DidvanIcons.trash_solid,
|
||||
DidvanIcons
|
||||
.trash_solid,
|
||||
color: Colors.white,
|
||||
size: 18,
|
||||
),
|
||||
|
|
@ -629,14 +659,17 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
// height: 24,
|
||||
// ),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
title(text: 'لینک وب سایت', isRequired: false),
|
||||
title(
|
||||
text: 'لینک وب سایت', isRequired: false),
|
||||
Row(
|
||||
children: [
|
||||
if (countOfLink.length > 1)
|
||||
DidvanIconButton(
|
||||
icon: CupertinoIcons.minus_circle_fill,
|
||||
icon:
|
||||
CupertinoIcons.minus_circle_fill,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
countOfLink.removeLast();
|
||||
|
|
@ -683,7 +716,8 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
children: [
|
||||
Icon(
|
||||
DidvanIcons.info_circle_light,
|
||||
color: Theme.of(context).colorScheme.caption,
|
||||
color:
|
||||
Theme.of(context).colorScheme.caption,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
|
|
@ -691,7 +725,8 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
'دستیار شما با استناد بر اطلاعات ارائه شده در پایگاه دانش، پیام کاربران را ارزیابی میکند.',
|
||||
textAlign: TextAlign.right,
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.caption,
|
||||
color:
|
||||
Theme.of(context).colorScheme.caption,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
@ -699,6 +734,8 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
const SizedBox(
|
||||
height: 24,
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
|
|
@ -732,7 +769,7 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
value: !isPrivate,
|
||||
title: '',
|
||||
onChanged: (value) {
|
||||
isPrivate = value;
|
||||
isPrivate = !value;
|
||||
},
|
||||
),
|
||||
),
|
||||
|
|
@ -751,7 +788,7 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
children: [
|
||||
DidvanButton(
|
||||
title: state.loadingCreate
|
||||
? ''
|
||||
? ' '
|
||||
: 'ذخیره تغییرات',
|
||||
onPressed: () async =>
|
||||
onConfirm(state, selectedBotId),
|
||||
|
|
@ -795,13 +832,20 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
],
|
||||
),
|
||||
onConfirmed: () async {
|
||||
final success =
|
||||
await state.deleteAssistants(
|
||||
id: widget.id!);
|
||||
if (success) {
|
||||
context
|
||||
.read<BotAssistantsState>()
|
||||
.getMyAssissmant();
|
||||
|
||||
context
|
||||
.read<
|
||||
CreateBotAssistantsState>()
|
||||
.assistant = null;
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
));
|
||||
},
|
||||
|
|
@ -812,7 +856,8 @@ class _CreateBotAssistantsPageState extends State<CreateBotAssistantsPage> {
|
|||
: Column(
|
||||
children: [
|
||||
DidvanButton(
|
||||
title: state.loadingCreate ? '' : 'ذخیره',
|
||||
title:
|
||||
state.loadingCreate ? ' ' : 'ذخیره',
|
||||
onPressed: () async =>
|
||||
onConfirm(state, selectedBotId)),
|
||||
if (state.loadingCreate)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class CreateBotAssistantsState extends CoreProvier {
|
|||
update();
|
||||
}
|
||||
|
||||
Future createAssistants(
|
||||
Future<bool> createAssistants(
|
||||
{required final BotAssistantsReqModel data, final int? id}) async {
|
||||
loadingCreate = true;
|
||||
update();
|
||||
|
|
@ -59,11 +59,12 @@ class CreateBotAssistantsState extends CoreProvier {
|
|||
appState = AppState.idle;
|
||||
loadingCreate = false;
|
||||
update();
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
appState = AppState.failed;
|
||||
loadingCreate = false;
|
||||
update();
|
||||
return false;
|
||||
}
|
||||
|
||||
Future getAnAssistant({required final int id}) async {
|
||||
|
|
@ -86,7 +87,7 @@ class CreateBotAssistantsState extends CoreProvier {
|
|||
update();
|
||||
}
|
||||
|
||||
Future deleteAssistants({required final int id}) async {
|
||||
Future<bool> deleteAssistants({required final int id}) async {
|
||||
loadingCreate = true;
|
||||
update();
|
||||
|
||||
|
|
@ -96,11 +97,12 @@ class CreateBotAssistantsState extends CoreProvier {
|
|||
appState = AppState.idle;
|
||||
loadingCreate = false;
|
||||
update();
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
appState = AppState.failed;
|
||||
loadingCreate = false;
|
||||
update();
|
||||
return false;
|
||||
}
|
||||
|
||||
Future getAssistantsName({required final String name}) async {
|
||||
|
|
|
|||
Loading…
Reference in New Issue