"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:
parent
8380bacaa2
commit
fe84d36b2d
|
|
@ -6,8 +6,14 @@ class AiChatArgs {
|
|||
final ChatsModel? chat;
|
||||
final Prompts? prompts;
|
||||
final bool? attach;
|
||||
final String? assistantsName;
|
||||
final List<BotsModel>? isTool;
|
||||
|
||||
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});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,15 @@ class BotsModel {
|
|||
int? attachment;
|
||||
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) {
|
||||
id = json['id'];
|
||||
|
|
@ -40,4 +48,25 @@ class BotsModel {
|
|||
data['responseType'] = responseType;
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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/files_model.dart';
|
||||
|
||||
|
|
@ -10,11 +11,13 @@ class ChatsModel {
|
|||
String? createdAt;
|
||||
String? updatedAt;
|
||||
BotsModel? bot;
|
||||
BotAssistants? userBot;
|
||||
List<Prompts>? prompts;
|
||||
bool? isEditing;
|
||||
String? assistantsName;
|
||||
|
||||
ChatsModel({
|
||||
this.id,
|
||||
ChatsModel(
|
||||
{this.id,
|
||||
this.userId,
|
||||
this.botId,
|
||||
this.title,
|
||||
|
|
@ -24,7 +27,8 @@ class ChatsModel {
|
|||
this.bot,
|
||||
this.prompts,
|
||||
this.isEditing = false,
|
||||
});
|
||||
this.assistantsName,
|
||||
this.userBot});
|
||||
|
||||
ChatsModel.fromJson(Map<String, dynamic> json) {
|
||||
id = json['id'];
|
||||
|
|
@ -34,7 +38,18 @@ class ChatsModel {
|
|||
placeholder = json['placeholder'];
|
||||
createdAt = json['createdAt'];
|
||||
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) {
|
||||
prompts = <Prompts>[];
|
||||
json['prompts'].forEach((v) {
|
||||
|
|
|
|||
|
|
@ -201,8 +201,8 @@ class RequestHelper {
|
|||
static String deleteComment(int id) => '$baseUrl/comment/$id';
|
||||
static String reportComment(int id) => '$baseUrl/comment/$id/report';
|
||||
static String widgetNews() => '$baseUrl/user/widget';
|
||||
static String aiChats() => '$baseUrl/ai/chat';
|
||||
static String aiArchived() => '$baseUrl/ai/chat${_urlConcatGenerator([
|
||||
static String aiChats() => '$baseUrl/ai/chat/v2';
|
||||
static String aiArchived() => '$baseUrl/ai/chat/v2${_urlConcatGenerator([
|
||||
const MapEntry('archived', true),
|
||||
])}';
|
||||
static String aiBots() => '$baseUrl/ai/bot/v2';
|
||||
|
|
@ -219,7 +219,7 @@ class RequestHelper {
|
|||
MapEntry('q', q),
|
||||
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 aiDeleteChats() => '$baseUrl/ai/chat';
|
||||
static String aiChangeChats(int id) => '$baseUrl/ai/chat/$id/title';
|
||||
|
|
|
|||
|
|
@ -85,7 +85,8 @@ class _AiChatPageState extends State<AiChatPage> {
|
|||
|
||||
state.message.clear();
|
||||
state.update();
|
||||
await state.postMessage(widget.args.bot);
|
||||
await state.postMessage(
|
||||
widget.args.bot, widget.args.assistantsName != null);
|
||||
}
|
||||
});
|
||||
super.initState();
|
||||
|
|
@ -142,6 +143,7 @@ class _AiChatPageState extends State<AiChatPage> {
|
|||
height: 12,
|
||||
),
|
||||
DidvanText(
|
||||
widget.args.assistantsName ??
|
||||
widget.args.bot.name.toString(),
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.bold,
|
||||
|
|
@ -233,6 +235,7 @@ class _AiChatPageState extends State<AiChatPage> {
|
|||
AiMessageBar(
|
||||
bot: widget.args.bot,
|
||||
attch: widget.args.attach,
|
||||
assistantsName: widget.args.assistantsName,
|
||||
),
|
||||
],
|
||||
)),
|
||||
|
|
@ -517,7 +520,7 @@ class _AiChatPageState extends State<AiChatPage> {
|
|||
textDirection:
|
||||
TextDirection.ltr,
|
||||
child: DidvanText(
|
||||
'${widget.args.bot.name}',
|
||||
'${widget.args.assistantsName ?? widget.args.bot.name}',
|
||||
maxLines: 1,
|
||||
overflow:
|
||||
TextOverflow.ellipsis,
|
||||
|
|
@ -590,8 +593,10 @@ class _AiChatPageState extends State<AiChatPage> {
|
|||
message.copyWith(error: false));
|
||||
state.file = file;
|
||||
state.update();
|
||||
await state
|
||||
.postMessage(widget.args.bot);
|
||||
await state.postMessage(
|
||||
widget.args.bot,
|
||||
widget.args.assistantsName !=
|
||||
null);
|
||||
},
|
||||
child: Icon(
|
||||
DidvanIcons.refresh_solid,
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ class AiChatState extends CoreProvier {
|
|||
update();
|
||||
}
|
||||
|
||||
Future<void> postMessage(BotsModel bot) async {
|
||||
Future<void> postMessage(BotsModel bot, bool isAssistants) async {
|
||||
onResponsing = true;
|
||||
final uploadedFile = file;
|
||||
file = null;
|
||||
|
|
@ -157,7 +157,8 @@ class AiChatState extends CoreProvier {
|
|||
// }
|
||||
|
||||
final req = await AiApiService.initial(
|
||||
url: '/${bot.id}/${bot.name}'.toLowerCase(),
|
||||
url: '${isAssistants ? '/custom' : ''}/${bot.id}/${bot.name}'
|
||||
.toLowerCase(),
|
||||
message: message,
|
||||
chatId: chatId,
|
||||
file: uploadedFile,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:didvan/config/design_config.dart';
|
||||
import 'package:didvan/config/theme_data.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/routes/routes.dart';
|
||||
import 'package:didvan/views/ai/bot_assistants_state.dart';
|
||||
|
|
@ -222,8 +223,13 @@ class _BotAssistantsPageState extends State<BotAssistantsPage> {
|
|||
const SizedBox(
|
||||
height: 12,
|
||||
),
|
||||
const DidvanButton(
|
||||
DidvanButton(
|
||||
title: 'استفاده از دستیار',
|
||||
onPressed: () => Navigator.pushNamed(context, Routes.aiChat,
|
||||
arguments: AiChatArgs(
|
||||
bot: assistants.bot!.copyWith(
|
||||
id: assistants.id, image: assistants.image),
|
||||
assistantsName: assistants.name)),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -217,8 +217,10 @@ class _HistoryAiChatPageState extends State<HistoryAiChatPage> {
|
|||
onTap: () {
|
||||
// if (state.chatsToDelete.isEmpty) {
|
||||
navigatorKey.currentState!.pushNamed(Routes.aiChat,
|
||||
arguments:
|
||||
AiChatArgs(bot: chat.bot!, chat: chat));
|
||||
arguments: AiChatArgs(
|
||||
bot: chat.bot!,
|
||||
chat: chat,
|
||||
assistantsName: chat.assistantsName));
|
||||
// } else {
|
||||
// if (state.chatsToDelete.contains(chat.id)) {
|
||||
// state.chatsToDelete.remove(chat.id!);
|
||||
|
|
@ -277,6 +279,7 @@ class _HistoryAiChatPageState extends State<HistoryAiChatPage> {
|
|||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
DidvanText(
|
||||
chat.assistantsName ??
|
||||
chat.bot!.name.toString(),
|
||||
fontWeight: FontWeight.bold,
|
||||
// fontSize: 18,
|
||||
|
|
|
|||
|
|
@ -40,8 +40,10 @@ typedef _Fn = void Function();
|
|||
|
||||
class AiMessageBar extends StatefulWidget {
|
||||
final BotsModel bot;
|
||||
final String? assistantsName;
|
||||
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);
|
||||
|
||||
@override
|
||||
|
|
@ -516,7 +518,8 @@ class _AiMessageBarState extends State<AiMessageBar> {
|
|||
state.message.clear();
|
||||
openAttach = false;
|
||||
state.update();
|
||||
await state.postMessage(widget.bot);
|
||||
await state.postMessage(
|
||||
widget.bot, widget.assistantsName != null);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -38,9 +38,12 @@ import 'package:path/path.dart' as p;
|
|||
|
||||
class AiMessageBarIOS extends StatefulWidget {
|
||||
final BotsModel bot;
|
||||
final String? assistantsName;
|
||||
|
||||
const AiMessageBarIOS({
|
||||
super.key,
|
||||
required this.bot,
|
||||
this.assistantsName,
|
||||
});
|
||||
|
||||
@override
|
||||
|
|
@ -308,9 +311,10 @@ class _AiMessageBarIOSState extends State<AiMessageBarIOS> {
|
|||
messageText.value =
|
||||
state
|
||||
.message.text;
|
||||
await state
|
||||
.postMessage(
|
||||
widget.bot);
|
||||
await state.postMessage(
|
||||
widget.bot,
|
||||
widget.assistantsName !=
|
||||
null);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -351,7 +351,10 @@ class _HoshanDrawerState extends State<HoshanDrawer> {
|
|||
child: InkWell(
|
||||
onTap: () {
|
||||
navigatorKey.currentState!.pushNamed(Routes.aiChat,
|
||||
arguments: AiChatArgs(bot: chat.bot!, chat: chat));
|
||||
arguments: AiChatArgs(
|
||||
bot: chat.bot!,
|
||||
chat: chat,
|
||||
assistantsName: chat.assistantsName));
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
|
|
|
|||
Loading…
Reference in New Issue