From f9095cfc6438424a792ff0ec2425dbb895a7e765 Mon Sep 17 00:00:00 2001 From: alceil <47685349+alceil@users.noreply.github.com> Date: Wed, 3 May 2023 12:59:36 +0530 Subject: [PATCH] feat: AI - improve writing (#2257) * feat: AI - Improve writing * fix: new line in result * formatted code --- frontend/appflowy_flutter/assets/translations/en.json | 1 + .../plugins/openai/widgets/smart_edit_action.dart | 11 ++++++++++- .../openai/widgets/smart_edit_node_widget.dart | 4 +++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/frontend/appflowy_flutter/assets/translations/en.json b/frontend/appflowy_flutter/assets/translations/en.json index ce5b2ef9e4..444d1e87af 100644 --- a/frontend/appflowy_flutter/assets/translations/en.json +++ b/frontend/appflowy_flutter/assets/translations/en.json @@ -363,6 +363,7 @@ "smartEditFixSpelling": "Fix spelling", "warning": "⚠️ AI responses can be inaccurate or misleading.", "smartEditSummarize": "Summarize", + "smartEditImproveWriting":"Improve Writing", "smartEditCouldNotFetchResult": "Could not fetch result from OpenAI", "smartEditCouldNotFetchKey": "Could not fetch OpenAI key", "smartEditDisabled": "Connect OpenAI in Settings", diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/openai/widgets/smart_edit_action.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/openai/widgets/smart_edit_action.dart index 053aaaa739..2e4a05b87b 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/openai/widgets/smart_edit_action.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/openai/widgets/smart_edit_action.dart @@ -5,7 +5,8 @@ import 'package:easy_localization/easy_localization.dart'; enum SmartEditAction { summarize, - fixSpelling; + fixSpelling, + improveWriting; String get toInstruction { switch (this) { @@ -13,6 +14,8 @@ enum SmartEditAction { return 'Tl;dr'; case SmartEditAction.fixSpelling: return 'Correct this to standard English:'; + case SmartEditAction.improveWriting: + return 'Rewrite this in your own words:'; } } @@ -22,6 +25,8 @@ enum SmartEditAction { return '$input\n\nTl;dr'; case SmartEditAction.fixSpelling: return 'Correct this to standard English:\n\n$input'; + case SmartEditAction.improveWriting: + return 'Rewrite this:\n\n$input'; } } @@ -31,6 +36,8 @@ enum SmartEditAction { return SmartEditAction.summarize; case 1: return SmartEditAction.fixSpelling; + case 2: + return SmartEditAction.improveWriting; } return SmartEditAction.fixSpelling; } @@ -41,6 +48,8 @@ enum SmartEditAction { return LocaleKeys.document_plugins_smartEditSummarize.tr(); case SmartEditAction.fixSpelling: return LocaleKeys.document_plugins_smartEditFixSpelling.tr(); + case SmartEditAction.improveWriting: + return LocaleKeys.document_plugins_smartEditImproveWriting.tr(); } } } diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/openai/widgets/smart_edit_node_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/openai/widgets/smart_edit_node_widget.dart index 151ccc60d2..2c157f6ddc 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/openai/widgets/smart_edit_node_widget.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/openai/widgets/smart_edit_node_widget.dart @@ -356,7 +356,9 @@ class _SmartEditInputState extends State<_SmartEditInput> { }, onProcess: (response) async { setState(() { - this.result += response.choices.first.text; + if (response.choices.first.text != '\n') { + this.result += response.choices.first.text; + } }); }, onEnd: () async {