From c7580486cb78cba938db8a51bc558c4a90e9a529 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Fri, 1 Mar 2024 13:17:28 +0100 Subject: [PATCH] [ADD] web_editor: add "correct" button to the AI Copywriter This adds a button to the AI Copywriter that allows the user to correct the selected text without altering it otherwise. task-3776377 closes odoo/odoo#156067 Signed-off-by: David Monjoie (dmo) --- .../src/js/wysiwyg/widgets/chatgpt_alternatives_dialog.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/chatgpt_alternatives_dialog.js b/addons/web_editor/static/src/js/wysiwyg/widgets/chatgpt_alternatives_dialog.js index bf768dfb341..236186b099b 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/chatgpt_alternatives_dialog.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/chatgpt_alternatives_dialog.js @@ -13,6 +13,7 @@ export class ChatGPTAlternativesDialog extends ChatGPTDialog { }; static defaultProps = { alternativesModes: { + correct: 'Correct', short: 'Shorten', long: 'Lengthen', friendly: 'Friendly', @@ -33,6 +34,7 @@ export class ChatGPTAlternativesDialog extends ChatGPTDialog { 'Your goal is to help the user write alternatives to that text.\n' + 'Conditions:\n' + '- You must respect the format (wrapping the alternative between and )\n' + + '- You must detect the language of the text given to you and respond in that language\n' + '- Do not write HTML\n' + '- You must suggest one and only one alternative per answer\n' + '- Your answer must be different every time, never repeat yourself\n' + @@ -72,9 +74,12 @@ export class ChatGPTAlternativesDialog extends ChatGPTDialog { if (this.state.alternativesMode && !messageIndex) { query += ` Make it more ${this.state.alternativesMode} than your last answer.`; } + if (this.state.alternativesMode === 'correct') { + query = 'Simply correct the text, without altering its meaning in any way. Preserve whatever language the user wrote their text in.'; + } await this._generate(query, (content, isError) => { if (this.state.currentBatchId === batchId) { - const alternative = content.replace(/.*/, '').replace(/<\/generated_text>.*/, ''); + const alternative = content.replace(/^[\s\S]*/, '').replace(/<\/generated_text>[\s\S]*$/, ''); if (isError) { wasError = true; } else {