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.
156 lines
4.5 KiB
Dart
156 lines
4.5 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:fluffychat/pangea/config/environment.dart';
|
|
import 'package:fluffychat/pangea/controllers/language_detection_controller.dart';
|
|
import 'package:fluffychat/pangea/models/language_detection_model.dart';
|
|
import 'package:fluffychat/pangea/models/lemma.dart';
|
|
import 'package:fluffychat/pangea/models/pangea_match_model.dart';
|
|
import 'package:fluffychat/pangea/models/pangea_token_model.dart';
|
|
import 'package:fluffychat/pangea/repo/span_data_repo.dart';
|
|
import 'package:http/http.dart';
|
|
|
|
import '../constants/model_keys.dart';
|
|
import '../models/igc_text_data_model.dart';
|
|
import '../network/requests.dart';
|
|
import '../network/urls.dart';
|
|
|
|
class IgcRepo {
|
|
static Future<IGCTextData> getIGC(
|
|
String? accessToken, {
|
|
required IGCRequestBody igcRequest,
|
|
}) async {
|
|
final Requests req = Requests(
|
|
accessToken: accessToken,
|
|
choreoApiKey: Environment.choreoApiKey,
|
|
);
|
|
final Response res = await req.post(
|
|
url: PApiUrls.igcLite,
|
|
body: igcRequest.toJson(),
|
|
);
|
|
|
|
final Map<String, dynamic> json =
|
|
jsonDecode(utf8.decode(res.bodyBytes).toString());
|
|
|
|
final IGCTextData response = IGCTextData.fromJson(json);
|
|
|
|
return response;
|
|
}
|
|
|
|
static Future<IGCTextData> getMockData() async {
|
|
await Future.delayed(const Duration(seconds: 2));
|
|
|
|
final IGCTextData igcTextData = IGCTextData(
|
|
detections: LanguageDetectionResponse(
|
|
detections: [LanguageDetection(langCode: "en", confidence: 0.99)],
|
|
fullText: "This be a sample text",
|
|
),
|
|
tokens: [
|
|
PangeaToken(
|
|
text: PangeaTokenText(content: "This", offset: 0, length: 4),
|
|
lemma: Lemma(form: "This", text: "this", saveVocab: true),
|
|
pos: "DET",
|
|
morph: {},
|
|
),
|
|
PangeaToken(
|
|
text: PangeaTokenText(content: "be", offset: 5, length: 2),
|
|
lemma: Lemma(form: "be", text: "be", saveVocab: true),
|
|
pos: "VERB",
|
|
morph: {},
|
|
),
|
|
PangeaToken(
|
|
text: PangeaTokenText(content: "a", offset: 8, length: 1),
|
|
lemma: Lemma(form: "a", text: "a", saveVocab: true),
|
|
pos: "DET",
|
|
morph: {},
|
|
),
|
|
PangeaToken(
|
|
text: PangeaTokenText(content: "sample", offset: 10, length: 6),
|
|
lemma: Lemma(form: "sample", text: "sample", saveVocab: true),
|
|
pos: "NOUN",
|
|
morph: {},
|
|
),
|
|
PangeaToken(
|
|
text: PangeaTokenText(content: "text", offset: 17, length: 4),
|
|
lemma: Lemma(form: "text", text: "text", saveVocab: true),
|
|
pos: "NOUN",
|
|
morph: {},
|
|
),
|
|
],
|
|
matches: [
|
|
PangeaMatch(
|
|
match: spanDataRepomockSpan,
|
|
status: PangeaMatchStatus.open,
|
|
),
|
|
],
|
|
originalInput: "This be a sample text",
|
|
fullTextCorrection: "This is a sample text",
|
|
userL1: "es",
|
|
userL2: "en",
|
|
enableIT: true,
|
|
enableIGC: true,
|
|
);
|
|
|
|
return igcTextData;
|
|
}
|
|
}
|
|
|
|
/// Previous text/audio message sent in chat
|
|
/// Contain message content, sender, and timestamp
|
|
class PreviousMessage {
|
|
String content;
|
|
String sender;
|
|
DateTime timestamp;
|
|
|
|
PreviousMessage({
|
|
required this.content,
|
|
required this.sender,
|
|
required this.timestamp,
|
|
});
|
|
|
|
factory PreviousMessage.fromJson(Map<String, dynamic> json) =>
|
|
PreviousMessage(
|
|
content: json[ModelKey.prevContent] ?? "",
|
|
sender: json[ModelKey.prevSender] ?? "",
|
|
timestamp: json[ModelKey.prevTimestamp] == null
|
|
? DateTime.now()
|
|
: DateTime.parse(json[ModelKey.prevTimestamp]),
|
|
);
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
ModelKey.prevContent: content,
|
|
ModelKey.prevSender: sender,
|
|
ModelKey.prevTimestamp: timestamp.toIso8601String(),
|
|
};
|
|
}
|
|
|
|
class IGCRequestBody {
|
|
String fullText;
|
|
String userL1;
|
|
String userL2;
|
|
bool enableIT;
|
|
bool enableIGC;
|
|
String userId;
|
|
List<PreviousMessage> prevMessages;
|
|
|
|
IGCRequestBody({
|
|
required this.fullText,
|
|
required this.userL1,
|
|
required this.userL2,
|
|
required this.enableIGC,
|
|
required this.enableIT,
|
|
required this.userId,
|
|
required this.prevMessages,
|
|
});
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
ModelKey.fullText: fullText,
|
|
ModelKey.userL1: userL1,
|
|
ModelKey.userL2: userL2,
|
|
"enable_it": enableIT,
|
|
"enable_igc": enableIGC,
|
|
ModelKey.userId: userId,
|
|
ModelKey.prevMessages:
|
|
jsonEncode(prevMessages.map((x) => x.toJson()).toList()),
|
|
};
|
|
}
|