Browse Source

修改音乐播放

newdev_shunjiawei
tanlongsheng 2 years ago
parent
commit
cd5fcfc66b
  1. 10
      lib/modules/chat/controllers/chat_controller.dart
  2. 12
      lib/modules/chat/models/message_model.dart
  3. 14
      lib/modules/chat/views/chat_view.dart
  4. 76
      lib/modules/chat/views/weather_day_card.dart

10
lib/modules/chat/controllers/chat_controller.dart

@ -397,7 +397,7 @@ class ChatController extends GetxController {
if (_shouldCancelAiResponse) return; if (_shouldCancelAiResponse) return;
Logger.info('chat ${chunk}'); Logger.info('chat ${chunk}');
if (chunk is Map) { if (chunk is Map) {
_updateIntermediateMessage(data: chunk); _updateIntermediateMessage(meta: chunk);
if (chunk['card_spotify'] != null) { if (chunk['card_spotify'] != null) {
play(chunk['card_spotify']); play(chunk['card_spotify']);
} }
@ -465,14 +465,14 @@ class ChatController extends GetxController {
} }
// 更新中间状态的消息 // 更新中间状态的消息
void _updateIntermediateMessage({Map? data, String? content}) { void _updateIntermediateMessage({Map? meta, String? content}) {
final index = final index =
messages.indexWhere((m) => m.isIntermediate && m.role == 'assistant'); messages.indexWhere((m) => m.isIntermediate && m.role == 'assistant');
if (index != -1) { if (index != -1) {
if (data != null) { if (meta != null) {
Map messagesData = messages[index].data ?? {}; Map messagesData = messages[index].meta ?? {};
messages[index] = messages[index].copyWith( messages[index] = messages[index].copyWith(
data: {...messagesData, ...data}, meta: {...messagesData, ...meta},
); );
} }
messages[index] = messages[index].copyWith( messages[index] = messages[index].copyWith(

12
lib/modules/chat/models/message_model.dart

@ -1,7 +1,7 @@
class Message { class Message {
final String role; // 'user' or 'assistant' final String role; // 'user' or 'assistant'
final String content; final String content;
final Map? data; final Map? meta;
final DateTime timestamp; final DateTime timestamp;
final bool isIntermediate; // 中间状态标记,替代isLoading final bool isIntermediate; // 中间状态标记,替代isLoading
@ -9,7 +9,7 @@ class Message {
required this.role, required this.role,
required this.content, required this.content,
required this.timestamp, required this.timestamp,
this.data, this.meta,
this.isIntermediate = false, // 默认不是中间状态 this.isIntermediate = false, // 默认不是中间状态
}); });
@ -18,7 +18,7 @@ class Message {
return Message( return Message(
role: json['role'] as String, role: json['role'] as String,
content: json['content'] as String, content: json['content'] as String,
data: json['data'], meta: json['meta'],
timestamp: DateTime.parse(json['timestamp'] as String), timestamp: DateTime.parse(json['timestamp'] as String),
isIntermediate: json['isIntermediate'] as bool? ?? false, isIntermediate: json['isIntermediate'] as bool? ?? false,
); );
@ -29,7 +29,7 @@ class Message {
return { return {
'role': role, 'role': role,
'content': content, 'content': content,
'data': data, 'meta': meta,
'timestamp': timestamp.toIso8601String(), 'timestamp': timestamp.toIso8601String(),
'isIntermediate': isIntermediate, 'isIntermediate': isIntermediate,
}; };
@ -49,14 +49,14 @@ class Message {
Message copyWith({ Message copyWith({
String? role, String? role,
String? content, String? content,
Map? data, Map? meta,
DateTime? timestamp, DateTime? timestamp,
bool? isIntermediate, bool? isIntermediate,
}) { }) {
return Message( return Message(
role: role ?? this.role, role: role ?? this.role,
content: content ?? this.content, content: content ?? this.content,
data: data ?? this.data, meta: meta ?? this.meta,
timestamp: timestamp ?? this.timestamp, timestamp: timestamp ?? this.timestamp,
isIntermediate: isIntermediate ?? this.isIntermediate, isIntermediate: isIntermediate ?? this.isIntermediate,
); );

14
lib/modules/chat/views/chat_view.dart

@ -355,16 +355,16 @@ class ChatView extends GetView<ChatController> {
), ),
); );
} }
if (message.data != null) { if (message.meta != null) {
if (message.data?['card_weather'] != null) { if (message.meta?['card_weather'] != null) {
box = WeatherDayCard(message.data?['card_weather'], isDarkMode); box = WeatherDayCard(message.meta?['card_weather'], isDarkMode);
} }
if (message.data?['card_spotify'] != null) { if (message.meta?['card_spotify'] != null) {
box = ChatMusicCard(message.data?['card_spotify'], isDarkMode); box = ChatMusicCard(message.meta?['card_spotify'], isDarkMode);
} }
if (message.data?['card_navigation'] != null) { if (message.meta?['card_navigation'] != null) {
box = ChatNavigationCard( box = ChatNavigationCard(
message.data?['card_navigation'], message.content, isDarkMode); message.meta?['card_navigation'], message.content, isDarkMode);
} }
} }
return box; return box;

76
lib/modules/chat/views/weather_day_card.dart

@ -17,7 +17,7 @@ class WeatherDayCard extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
data?['date'], data?['city'],
style: TextStyle( style: TextStyle(
color: isDarkMode ? Colors.white : Colors.black, color: isDarkMode ? Colors.white : Colors.black,
fontSize: 10.sp, fontSize: 10.sp,
@ -47,43 +47,43 @@ class WeatherDayCard extends StatelessWidget {
fontSize: 14.sp, fontSize: 14.sp,
), ),
), ),
// Row( Row(
// children: [ children: [
// Text( Text(
// '最\n高', '湿\n度',
// style: TextStyle( style: TextStyle(
// color: isDarkMode ? Colors.white : Colors.black, color: isDarkMode ? Colors.white : Colors.black,
// fontSize: 10.sp, fontSize: 10.sp,
// height: 1, height: 1,
// ), ),
// ), ),
// 5.horizontalSpace, 5.horizontalSpace,
// Text( Text(
// '${data?['maxTemperature']}°', '${data?['humidity']}',
// style: TextStyle( style: TextStyle(
// color: isDarkMode ? Colors.white : Colors.black, color: isDarkMode ? Colors.white : Colors.black,
// fontSize: 20.sp, fontSize: 20.sp,
// ), ),
// ), ),
// 10.horizontalSpace, 10.horizontalSpace,
// Text( Text(
// '最\n低', '风\n力',
// style: TextStyle( style: TextStyle(
// color: isDarkMode ? Colors.white : Colors.black, color: isDarkMode ? Colors.white : Colors.black,
// fontSize: 10.sp, fontSize: 10.sp,
// height: 1, height: 1,
// ), ),
// ), ),
// 5.horizontalSpace, 5.horizontalSpace,
// Text( Text(
// '${data?['minTemperature']}°', '${data?['windForce']}',
// style: TextStyle( style: TextStyle(
// color: isDarkMode ? Colors.white : Colors.black, color: isDarkMode ? Colors.white : Colors.black,
// fontSize: 20.sp, fontSize: 20.sp,
// ), ),
// ), ),
// ], ],
// ), ),
], ],
), ),
], ],

Loading…
Cancel
Save