Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

button to run IGC manually #220

Merged
merged 8 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3128,7 +3128,7 @@
"maybeLater": "Maybe Later",
"mainMenu": "Main Menu",
"toggleImmersionMode": "Immersion Mode",
"toggleImmersionModeDesc": "When enabled, all messages are displayed in your target language and you can click the message to access definitions and translations.",
"toggleImmersionModeDesc": "When enabled, all messages are displayed in your target language. This setting is most useful in language exchanges.",
"itToggleDescription": "This language learning tool will identify words in your base language and help you translate them to your target language. Though rare, the AI can make translation errors.",
"igcToggleDescription": "This language learning tool will identify common spelling, grammar and punctuation errors in your message and suggest corrections. Though rare, the AI can make correction errors.",
"sendOnEnterDescription": "Turn this off to be able to add line spaces in messages. When the toggle is off on the browser app, you can press Shift + Enter to start a new line. When the toggle is off on mobile apps, just Enter will start a new line.",
Expand Down Expand Up @@ -3948,6 +3948,11 @@
"roomDataMissing": "Some data may be missing from rooms in which you are not a member.",
"updatePhoneOS": "You may need to update your device's OS version.",
"wordsPerMinute": "Words per minute",
"autoIGCToolName": "Run Language Assistance Automatically",
"autoIGCToolDescription": "Automatically run language assistance after typing messages",
"runGrammarCorrection": "Run grammar correction",
"grammarCorrectionFailed": "Grammar correction failed",
"grammarCorrectionComplete": "Grammar correction complete",
"leaveRoomDescription": "The chat will be moved to the archive. Other users will be able to see that you have left the chat.",
"archiveSpaceDescription": "All chats within this space will be moved to the archive for yourself and other non-admin users.",
"leaveSpaceDescription": "All chats within this space will be moved to the archive. Other users will be able to see that you have left the space.",
Expand Down
2 changes: 1 addition & 1 deletion assets/l10n/intl_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3281,7 +3281,7 @@
"generateVocabulary": "Generar vocabulario basado en el título y la descripción",
"generatePrompts": "Generar preguntas basado en el título y la descripción",
"toggleImmersionMode": "Modo de inmersión",
"toggleImmersionModeDesc": "Cuando está habilitado, todos los mensajes se muestran en su idioma de destino y puede hacer clic en el mensaje para acceder a definiciones y traducciones.",
"toggleImmersionModeDesc": "Cuando está habilitado, todos los mensajes se muestran en su idioma de destino. Esta configuración es más útil en intercambios de idiomas.",
"subscribe": "Subscríbase",
"getAccess": "Activar herramientas",
"subscriptionDesc": "¡Enviar y recibir mensajes es gratis! Suscríbase para aceder a la traducción interactiva, la revisión gramatical y el análisis de aprendizaje.",
Expand Down
10 changes: 8 additions & 2 deletions lib/pages/chat/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:fluffychat/pages/chat/reactions_picker.dart';
import 'package:fluffychat/pages/chat/reply_display.dart';
import 'package:fluffychat/pangea/choreographer/widgets/has_error_button.dart';
import 'package:fluffychat/pangea/choreographer/widgets/language_permissions_warning_buttons.dart';
import 'package:fluffychat/pangea/choreographer/widgets/start_igc_button.dart';
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
import 'package:fluffychat/pangea/pages/class_analytics/measure_able.dart';
import 'package:fluffychat/utils/account_config.dart';
Expand Down Expand Up @@ -449,15 +450,20 @@ class ChatView extends StatelessWidget {
// #Pangea
// if (controller.dragging)
// Container(
// color: Theme.of(context)
// .scaffoldBackgroundColor
// color: Theme.of(context)
// .scaffoldBackgroundColor
// .withOpacity(0.9),
// alignment: Alignment.center,
// child: const Icon(
// Icons.upload_outlined,
// size: 100,
// ),
// ),
Positioned(
left: 20,
bottom: 75,
child: StartIGCButton(controller: controller),
),
// Pangea#
],
),
Expand Down
25 changes: 7 additions & 18 deletions lib/pages/chat/events/message_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,8 @@ class MessageContent extends StatelessWidget {
case MessageTypes.Notice:
case MessageTypes.Emote:
if (AppConfig.renderHtml &&
!event.redacted &&
event.isRichMessage
// #Pangea
&&
!(pangeaMessageEvent?.showRichText(
selected,
isOverlay: isOverlay,
highlighted: toolbarController?.highlighted ?? false,
) ??
false)
// Pangea#
) {
!event.redacted &&
event.isRichMessage) {
var html = event.formattedText;
if (event.messageType == MessageTypes.Emote) {
html = '* $html';
Expand Down Expand Up @@ -306,18 +296,17 @@ class MessageContent extends StatelessWidget {
decoration: event.redacted ? TextDecoration.lineThrough : null,
height: 1.3,
);
if (pangeaMessageEvent?.showRichText(
selected,
isOverlay: isOverlay,
highlighted: toolbarController?.highlighted ?? false,
) ??
false) {
if (immersionMode && pangeaMessageEvent != null) {
return PangeaRichText(
style: messageTextStyle,
pangeaMessageEvent: pangeaMessageEvent!,
immersionMode: immersionMode,
toolbarController: toolbarController,
);
} else if (pangeaMessageEvent != null) {
toolbarController?.toolbar?.textSelection.setMessageText(
pangeaMessageEvent!.body,
);
}
// Pangea#
return FutureBuilder<String>(
Expand Down
76 changes: 66 additions & 10 deletions lib/pangea/choreographer/controllers/choreographer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:fluffychat/pangea/enum/edit_type.dart';
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
import 'package:fluffychat/pangea/models/class_model.dart';
import 'package:fluffychat/pangea/models/it_step.dart';
import 'package:fluffychat/pangea/models/language_detection_model.dart';
import 'package:fluffychat/pangea/models/representation_content_model.dart';
import 'package:fluffychat/pangea/models/tokens_event_content_model.dart';
import 'package:fluffychat/pangea/utils/any_state_holder.dart';
Expand Down Expand Up @@ -51,7 +52,7 @@ class Choreographer {
// last checked by IGC or translation
String? _lastChecked;
ChoreoMode choreoMode = ChoreoMode.igc;
final StreamController stateListener = StreamController();
final StreamController stateListener = StreamController.broadcast();
StreamSubscription? trialStream;

Choreographer(this.pangeaController, this.chatController) {
Expand Down Expand Up @@ -93,7 +94,7 @@ class Choreographer {
}
}

void _sendWithIGC(BuildContext context) {
Future<void> _sendWithIGC(BuildContext context) async {
if (igc.canSendMessage) {
final PangeaRepresentation? originalWritten =
choreoRecord.includedIT && itController.sourceText != null
Expand All @@ -105,7 +106,6 @@ class Choreographer {
)
: null;

// PTODO - just put this in original message event
final PangeaRepresentation originalSent = PangeaRepresentation(
langCode: langCodeOfCurrentText ?? LanguageKeys.unknownLanguage,
text: currentText,
Expand All @@ -115,6 +115,22 @@ class Choreographer {
final ChoreoRecord? applicableChoreo =
isITandIGCEnabled && igc.igcTextData != null ? choreoRecord : null;

// if the message has not been processed to determine its language
// then run it through the language detection endpoint. If the detection
// confidence is high enough, use that language code as the message's language
// to save that pangea representation
if (applicableChoreo == null) {
final resp = await pangeaController.languageDetection.detectLanguage(
currentText,
pangeaController.languageController.userL2?.langCode,
pangeaController.languageController.userL1?.langCode,
);
final LanguageDetection? bestDetection = resp.bestDetection();
if (bestDetection != null) {
originalSent.langCode = bestDetection.langCode;
}
}

final UseType useType = useTypeCalculator(applicableChoreo);
debugPrint("use type in choreographer $useType");

Expand Down Expand Up @@ -205,14 +221,18 @@ class Choreographer {
textController.editType = EditType.keyboard;
}

Future<void> getLanguageHelp([bool tokensOnly = false]) async {
Future<void> getLanguageHelp([
bool tokensOnly = false,
bool manual = false,
]) async {
try {
if (errorService.isError) return;
final CanSendStatus canSendStatus =
pangeaController.subscriptionController.canSendStatus;

if (canSendStatus != CanSendStatus.subscribed ||
(!igcEnabled && !itEnabled)) {
(!igcEnabled && !itEnabled) ||
(!isAutoIGCEnabled && !manual && choreoMode != ChoreoMode.it)) {
return;
}

Expand Down Expand Up @@ -525,14 +545,50 @@ class Choreographer {
chatController.room,
);

bool get translationEnabled =>
pangeaController.permissionsController.isToolEnabled(
ToolSetting.translations,
chatController.room,
);
// bool get translationEnabled =>
// pangeaController.permissionsController.isToolEnabled(
// ToolSetting.translations,
// chatController.room,
// );

bool get isITandIGCEnabled =>
pangeaController.permissionsController.isWritingAssistanceEnabled(
chatController.room,
);

bool get isAutoIGCEnabled =>
pangeaController.permissionsController.isToolEnabled(
ToolSetting.autoIGC,
chatController.room,
);

AssistanceState get assistanceState {
if (currentText.isEmpty && itController.sourceText == null) {
return AssistanceState.noMessage;
}

if (igc.igcTextData?.matches.isNotEmpty ?? false) {
return AssistanceState.fetched;
}

if (isFetching) {
return AssistanceState.fetching;
}

if (igc.igcTextData == null) {
return AssistanceState.notFetched;
}

return AssistanceState.complete;
}
}

// assistance state is, user has not typed a message, user has typed a message and IGC has not run,
// IGC is running, IGC has run and there are remaining steps (either IT or IGC), or all steps are done
enum AssistanceState {
noMessage,
notFetched,
fetching,
fetched,
complete,
}
6 changes: 3 additions & 3 deletions lib/pangea/choreographer/widgets/language_display_toggle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class LanguageDisplayToggle extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (!controller.choreographer.translationEnabled) {
return const SizedBox();
}
// if (!controller.choreographer.translationEnabled) {
// return const SizedBox();
// }
return Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
Expand Down
9 changes: 5 additions & 4 deletions lib/pangea/choreographer/widgets/send_button.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'package:fluffychat/pangea/constants/colors.dart';
import 'package:flutter/material.dart';

import 'package:flutter_gen/gen_l10n/l10n.dart';

import 'package:fluffychat/pangea/constants/colors.dart';
import '../../../pages/chat/chat.dart';

class ChoreographerSendButton extends StatelessWidget {
Expand All @@ -16,7 +15,8 @@ class ChoreographerSendButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
// commit for cicd
return controller.choreographer.isFetching
return controller.choreographer.isFetching &&
controller.choreographer.isAutoIGCEnabled
? Container(
height: 56,
width: 56,
Expand All @@ -28,7 +28,8 @@ class ChoreographerSendButton extends StatelessWidget {
alignment: Alignment.center,
child: IconButton(
icon: const Icon(Icons.send_outlined),
color: controller.choreographer.igc.canSendMessage
color: controller.choreographer.igc.canSendMessage ||
!controller.choreographer.isAutoIGCEnabled
? null
: PangeaColors.igcError,
onPressed: () {
Expand Down
Loading
Loading