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.
cloudsolutions-atoms/lib/modules/copilot/model/copilot_message_model.dart

124 lines
3.6 KiB
Dart

2 months ago
import 'package:flutter/foundation.dart';
enum CopilotRole { user, assistant }
class CopilotImage {
final String base64;
final String source;
final int page;
final String? fileLink;
final double? similarityScore;
CopilotImage({
required this.base64,
required this.source,
required this.page,
this.fileLink,
this.similarityScore,
});
factory CopilotImage.fromJson(Map<String, dynamic> json) => CopilotImage(
base64: json['image_base64'] ?? '',
source: json['source'] ?? '',
page: json['page'] is int ? json['page'] : int.tryParse('${json['page']}') ?? 0,
fileLink: json['file_link'],
similarityScore: (json['similarity_score'] as num?)?.toDouble(),
);
}
class CopilotMessage {
final String id;
final CopilotRole role;
String content;
2 months ago
String? documentAnswer;
String? websiteAnswer;
List<CopilotImage> images;
DateTime? timestamp;
bool isStreaming;
bool isError;
String? localAudioPath;
String? localImagePath;
List<Uint8List> ttsAudioClips;
2 months ago
CopilotMessage({
required this.id,
required this.role,
this.content = '',
this.documentAnswer,
this.websiteAnswer,
this.images = const [],
this.timestamp,
this.isStreaming = false,
this.isError = false,
this.localAudioPath,
this.localImagePath,
List<Uint8List>? ttsAudioClips,
}) : ttsAudioClips = ttsAudioClips ?? [];
2 months ago
factory CopilotMessage.fromHistoryJson(Map<String, dynamic> json) => CopilotMessage(
id: UniqueKey().toString(),
role: json['role'] == 'ai' ? CopilotRole.assistant : CopilotRole.user,
content: json['content'] ?? '',
documentAnswer: json['document_answer'],
websiteAnswer: json['website_answer'],
images: (json['images'] as List? ?? []).map((e) => CopilotImage.fromJson(e)).toList(),
timestamp: json['timestamp'] != null ? (DateTime.tryParse(json['timestamp'].toString()) ?? DateTime.now()) : DateTime.now(),
);
}
class CopilotStreamEvent {
final String type;
final CopilotStreamContent? content;
final String? transcriptionContent;
2 months ago
CopilotStreamEvent({required this.type, this.content, this.transcriptionContent});
2 months ago
factory CopilotStreamEvent.fromJson(Map<String, dynamic> json) => CopilotStreamEvent(
type: json['type'] ?? '',
content: json['content'] is Map<String, dynamic> ? CopilotStreamContent.fromJson(json['content']) : null,
transcriptionContent: json['content'] is String ? json['content'] : null,
2 months ago
);
}
class CopilotStreamContent {
final String? answer;
final String? documentAnswer;
final String? websiteAnswer;
final int? chunksUsed;
final List<CopilotImage> images;
CopilotStreamContent({
this.answer,
this.documentAnswer,
this.websiteAnswer,
this.chunksUsed,
this.images = const [],
});
factory CopilotStreamContent.fromJson(Map<String, dynamic> json) => CopilotStreamContent(
answer: json['answer'],
documentAnswer: json['document_answer'],
websiteAnswer: json['website_answer'],
chunksUsed: json['chunks_used'],
images: (json['images'] as List? ?? []).map((e) => CopilotImage.fromJson(e)).toList(),
);
}
class CopilotHistoryItem {
final String threadId;
final String firstHumanMessage;
1 month ago
final String updatedAt;
2 months ago
CopilotHistoryItem({
required this.threadId,
required this.firstHumanMessage,
required this.updatedAt,
});
factory CopilotHistoryItem.fromJson(Map<String, dynamic> json) => CopilotHistoryItem(
threadId: json['threadId'] ?? '',
firstHumanMessage: json['firstHumanMessage'] ?? '',
1 month ago
updatedAt: json['updatedAt'] ?? '',
2 months ago
);
}