"Updated AI chat models and views to include assistants' names and IDs, added new fields to BotsModel and ChatsModel, and modified RequestHelper and AiChatState to accommodate these changes."

This commit is contained in:
OkaykOrhmn 2024-11-14 10:39:24 +03:30
parent 8380bacaa2
commit fe84d36b2d
11 changed files with 110 additions and 35 deletions

View File

@ -6,8 +6,14 @@ class AiChatArgs {
final ChatsModel? chat; final ChatsModel? chat;
final Prompts? prompts; final Prompts? prompts;
final bool? attach; final bool? attach;
final String? assistantsName;
final List<BotsModel>? isTool; final List<BotsModel>? isTool;
AiChatArgs( AiChatArgs(
{required this.bot, this.chat, this.prompts, this.attach, this.isTool}); {required this.bot,
this.chat,
this.prompts,
this.attach,
this.isTool,
this.assistantsName});
} }

View File

@ -8,7 +8,15 @@ class BotsModel {
int? attachment; int? attachment;
bool? editable; bool? editable;
BotsModel({this.id, this.name, this.image}); BotsModel(
{this.id,
this.name,
this.image,
this.attachment,
this.attachmentType,
this.description,
this.editable,
this.responseType});
BotsModel.fromJson(Map<String, dynamic> json) { BotsModel.fromJson(Map<String, dynamic> json) {
id = json['id']; id = json['id'];
@ -40,4 +48,25 @@ class BotsModel {
data['responseType'] = responseType; data['responseType'] = responseType;
return data; return data;
} }
BotsModel copyWith(
{int? id,
String? name,
String? image,
String? responseType,
String? description,
List<String>? attachmentType,
int? attachment,
bool? editable}) {
return BotsModel(
id: id ?? this.id,
name: name ?? this.name,
image: image ?? this.image,
responseType: responseType ?? this.responseType,
description: description ?? this.description,
attachmentType: attachmentType ?? this.attachmentType,
attachment: attachment ?? this.attachment,
editable: editable ?? this.editable,
);
}
} }

View File

@ -1,3 +1,4 @@
import 'package:didvan/models/ai/bot_assistants_model.dart';
import 'package:didvan/models/ai/bots_model.dart'; import 'package:didvan/models/ai/bots_model.dart';
import 'package:didvan/models/ai/files_model.dart'; import 'package:didvan/models/ai/files_model.dart';
@ -10,21 +11,24 @@ class ChatsModel {
String? createdAt; String? createdAt;
String? updatedAt; String? updatedAt;
BotsModel? bot; BotsModel? bot;
BotAssistants? userBot;
List<Prompts>? prompts; List<Prompts>? prompts;
bool? isEditing; bool? isEditing;
String? assistantsName;
ChatsModel({ ChatsModel(
this.id, {this.id,
this.userId, this.userId,
this.botId, this.botId,
this.title, this.title,
this.placeholder, this.placeholder,
this.createdAt, this.createdAt,
this.updatedAt, this.updatedAt,
this.bot, this.bot,
this.prompts, this.prompts,
this.isEditing = false, this.isEditing = false,
}); this.assistantsName,
this.userBot});
ChatsModel.fromJson(Map<String, dynamic> json) { ChatsModel.fromJson(Map<String, dynamic> json) {
id = json['id']; id = json['id'];
@ -34,7 +38,18 @@ class ChatsModel {
placeholder = json['placeholder']; placeholder = json['placeholder'];
createdAt = json['createdAt']; createdAt = json['createdAt'];
updatedAt = json['updatedAt']; updatedAt = json['updatedAt'];
bot = json['bot'] != null ? BotsModel.fromJson(json['bot']) : null; userBot = json['userBot'] != null
? BotAssistants.fromJson(json['userBot'])
: null;
bot = json['bot'] != null
? BotsModel.fromJson(json['bot'])
: userBot?.bot?.copyWith(
id: userBot?.id,
image: userBot?.image,
);
if (userBot != null) {
assistantsName = userBot!.name;
}
if (json['prompts'] != null) { if (json['prompts'] != null) {
prompts = <Prompts>[]; prompts = <Prompts>[];
json['prompts'].forEach((v) { json['prompts'].forEach((v) {

View File

@ -201,8 +201,8 @@ class RequestHelper {
static String deleteComment(int id) => '$baseUrl/comment/$id'; static String deleteComment(int id) => '$baseUrl/comment/$id';
static String reportComment(int id) => '$baseUrl/comment/$id/report'; static String reportComment(int id) => '$baseUrl/comment/$id/report';
static String widgetNews() => '$baseUrl/user/widget'; static String widgetNews() => '$baseUrl/user/widget';
static String aiChats() => '$baseUrl/ai/chat'; static String aiChats() => '$baseUrl/ai/chat/v2';
static String aiArchived() => '$baseUrl/ai/chat${_urlConcatGenerator([ static String aiArchived() => '$baseUrl/ai/chat/v2${_urlConcatGenerator([
const MapEntry('archived', true), const MapEntry('archived', true),
])}'; ])}';
static String aiBots() => '$baseUrl/ai/bot/v2'; static String aiBots() => '$baseUrl/ai/bot/v2';
@ -219,7 +219,7 @@ class RequestHelper {
MapEntry('q', q), MapEntry('q', q),
const MapEntry('archived', true), const MapEntry('archived', true),
])}'; ])}';
static String aiAChat(int id) => '$baseUrl/ai/chat/$id'; static String aiAChat(int id) => '$baseUrl/ai/chat/$id/v2';
static String aiChatId() => '$baseUrl/ai/chat/id'; static String aiChatId() => '$baseUrl/ai/chat/id';
static String aiDeleteChats() => '$baseUrl/ai/chat'; static String aiDeleteChats() => '$baseUrl/ai/chat';
static String aiChangeChats(int id) => '$baseUrl/ai/chat/$id/title'; static String aiChangeChats(int id) => '$baseUrl/ai/chat/$id/title';

View File

@ -85,7 +85,8 @@ class _AiChatPageState extends State<AiChatPage> {
state.message.clear(); state.message.clear();
state.update(); state.update();
await state.postMessage(widget.args.bot); await state.postMessage(
widget.args.bot, widget.args.assistantsName != null);
} }
}); });
super.initState(); super.initState();
@ -142,7 +143,8 @@ class _AiChatPageState extends State<AiChatPage> {
height: 12, height: 12,
), ),
DidvanText( DidvanText(
widget.args.bot.name.toString(), widget.args.assistantsName ??
widget.args.bot.name.toString(),
fontSize: 17, fontSize: 17,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
@ -233,6 +235,7 @@ class _AiChatPageState extends State<AiChatPage> {
AiMessageBar( AiMessageBar(
bot: widget.args.bot, bot: widget.args.bot,
attch: widget.args.attach, attch: widget.args.attach,
assistantsName: widget.args.assistantsName,
), ),
], ],
)), )),
@ -517,7 +520,7 @@ class _AiChatPageState extends State<AiChatPage> {
textDirection: textDirection:
TextDirection.ltr, TextDirection.ltr,
child: DidvanText( child: DidvanText(
'${widget.args.bot.name}', '${widget.args.assistantsName ?? widget.args.bot.name}',
maxLines: 1, maxLines: 1,
overflow: overflow:
TextOverflow.ellipsis, TextOverflow.ellipsis,
@ -590,8 +593,10 @@ class _AiChatPageState extends State<AiChatPage> {
message.copyWith(error: false)); message.copyWith(error: false));
state.file = file; state.file = file;
state.update(); state.update();
await state await state.postMessage(
.postMessage(widget.args.bot); widget.args.bot,
widget.args.assistantsName !=
null);
}, },
child: Icon( child: Icon(
DidvanIcons.refresh_solid, DidvanIcons.refresh_solid,

View File

@ -133,7 +133,7 @@ class AiChatState extends CoreProvier {
update(); update();
} }
Future<void> postMessage(BotsModel bot) async { Future<void> postMessage(BotsModel bot, bool isAssistants) async {
onResponsing = true; onResponsing = true;
final uploadedFile = file; final uploadedFile = file;
file = null; file = null;
@ -157,7 +157,8 @@ class AiChatState extends CoreProvier {
// } // }
final req = await AiApiService.initial( final req = await AiApiService.initial(
url: '/${bot.id}/${bot.name}'.toLowerCase(), url: '${isAssistants ? '/custom' : ''}/${bot.id}/${bot.name}'
.toLowerCase(),
message: message, message: message,
chatId: chatId, chatId: chatId,
file: uploadedFile, file: uploadedFile,

View File

@ -1,6 +1,7 @@
import 'package:didvan/config/design_config.dart'; import 'package:didvan/config/design_config.dart';
import 'package:didvan/config/theme_data.dart'; import 'package:didvan/config/theme_data.dart';
import 'package:didvan/constants/app_icons.dart'; import 'package:didvan/constants/app_icons.dart';
import 'package:didvan/models/ai/ai_chat_args.dart';
import 'package:didvan/models/ai/bot_assistants_model.dart'; import 'package:didvan/models/ai/bot_assistants_model.dart';
import 'package:didvan/routes/routes.dart'; import 'package:didvan/routes/routes.dart';
import 'package:didvan/views/ai/bot_assistants_state.dart'; import 'package:didvan/views/ai/bot_assistants_state.dart';
@ -222,8 +223,13 @@ class _BotAssistantsPageState extends State<BotAssistantsPage> {
const SizedBox( const SizedBox(
height: 12, height: 12,
), ),
const DidvanButton( DidvanButton(
title: 'استفاده از دستیار', title: 'استفاده از دستیار',
onPressed: () => Navigator.pushNamed(context, Routes.aiChat,
arguments: AiChatArgs(
bot: assistants.bot!.copyWith(
id: assistants.id, image: assistants.image),
assistantsName: assistants.name)),
) )
], ],
), ),

View File

@ -217,8 +217,10 @@ class _HistoryAiChatPageState extends State<HistoryAiChatPage> {
onTap: () { onTap: () {
// if (state.chatsToDelete.isEmpty) { // if (state.chatsToDelete.isEmpty) {
navigatorKey.currentState!.pushNamed(Routes.aiChat, navigatorKey.currentState!.pushNamed(Routes.aiChat,
arguments: arguments: AiChatArgs(
AiChatArgs(bot: chat.bot!, chat: chat)); bot: chat.bot!,
chat: chat,
assistantsName: chat.assistantsName));
// } else { // } else {
// if (state.chatsToDelete.contains(chat.id)) { // if (state.chatsToDelete.contains(chat.id)) {
// state.chatsToDelete.remove(chat.id!); // state.chatsToDelete.remove(chat.id!);
@ -277,7 +279,8 @@ class _HistoryAiChatPageState extends State<HistoryAiChatPage> {
MainAxisAlignment.spaceBetween, MainAxisAlignment.spaceBetween,
children: [ children: [
DidvanText( DidvanText(
chat.bot!.name.toString(), chat.assistantsName ??
chat.bot!.name.toString(),
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
// fontSize: 18, // fontSize: 18,
), ),

View File

@ -40,8 +40,10 @@ typedef _Fn = void Function();
class AiMessageBar extends StatefulWidget { class AiMessageBar extends StatefulWidget {
final BotsModel bot; final BotsModel bot;
final String? assistantsName;
final bool? attch; final bool? attch;
const AiMessageBar({Key? key, required this.bot, this.attch}) const AiMessageBar(
{Key? key, required this.bot, this.attch, this.assistantsName})
: super(key: key); : super(key: key);
@override @override
@ -516,7 +518,8 @@ class _AiMessageBarState extends State<AiMessageBar> {
state.message.clear(); state.message.clear();
openAttach = false; openAttach = false;
state.update(); state.update();
await state.postMessage(widget.bot); await state.postMessage(
widget.bot, widget.assistantsName != null);
}, },
), ),
); );

View File

@ -38,9 +38,12 @@ import 'package:path/path.dart' as p;
class AiMessageBarIOS extends StatefulWidget { class AiMessageBarIOS extends StatefulWidget {
final BotsModel bot; final BotsModel bot;
final String? assistantsName;
const AiMessageBarIOS({ const AiMessageBarIOS({
super.key, super.key,
required this.bot, required this.bot,
this.assistantsName,
}); });
@override @override
@ -308,9 +311,10 @@ class _AiMessageBarIOSState extends State<AiMessageBarIOS> {
messageText.value = messageText.value =
state state
.message.text; .message.text;
await state await state.postMessage(
.postMessage( widget.bot,
widget.bot); widget.assistantsName !=
null);
}, },
), ),
), ),

View File

@ -351,7 +351,10 @@ class _HoshanDrawerState extends State<HoshanDrawer> {
child: InkWell( child: InkWell(
onTap: () { onTap: () {
navigatorKey.currentState!.pushNamed(Routes.aiChat, navigatorKey.currentState!.pushNamed(Routes.aiChat,
arguments: AiChatArgs(bot: chat.bot!, chat: chat)); arguments: AiChatArgs(
bot: chat.bot!,
chat: chat,
assistantsName: chat.assistantsName));
}, },
child: Row( child: Row(
children: [ children: [