From cbac216157ef0efa683d20572fe7d9d1f5f70591 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Thu, 26 Oct 2023 12:20:23 +0200 Subject: [PATCH] [IMP] web_editor: make better chatgpt alternatives, avoiding intro text Sometimes, ChatGPT includes a little intro text (eg, "Sure, here are some alternatives:") to its answer. This avoids this as much as possible by improving the system prompt and asking to wrap the answer in tags that we then remove. task-3572397 Part-of: odoo/odoo#139857 --- .../widgets/chatgpt_alternatives_dialog.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) 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 1c4479d0287..d1a10a238ce 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 @@ -28,15 +28,15 @@ export class ChatGPTAlternativesDialog extends ChatGPTDialog { selectedMessage: null, conversationHistory: [{ role: 'system', - content: 'You are a helpful assistant, your goal is to help the user write alternatives to their text.', - }, - { - role: 'user', - content: 'Consider the following text : \n' + this.props.originalText, - }, - { - role: 'assistant', - content: 'Thanks for this text, what do you need me to do with it?', + content: 'The user wrote the following text:\n' + + '' + this.props.originalText + '\n' + + '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' + + '- 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' + + '- You must respect whatever extra conditions the user gives you\n', }], messages: [], alternativesMode: '', @@ -66,8 +66,8 @@ export class ChatGPTAlternativesDialog extends ChatGPTDialog { if (this.state.alternativesMode && !messageIndex) { query += ` Make it more ${this.state.alternativesMode} than your last answer.`; } - query += messageIndex ? '' : 'The original text was : \n' + this.props.originalText; await this._generate(query, (content, isError) => { + const alternative = content.replace(/.*/, '').replace(/<\/generated_text>.*/, ''); if (isError) { wasError = true; } else { @@ -79,11 +79,11 @@ export class ChatGPTAlternativesDialog extends ChatGPTDialog { content, }); } - this.state.messages = [...this.state.messages, { + this.state.messages.push({ author: 'assistant', - text: content, + text: alternative, isError, - }]; + }); }).catch(() => { wasError = true; this.state.messages = [];