From 8716d38f22cc1e030bcd706272449982e922cce9 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 15 Dec 2025 20:18:41 +0530 Subject: [PATCH] feat: better grammar fix prompt --- .../openai/openai_prompts/fix_spelling_grammar.txt | 13 +++++++++++++ lib/integrations/openai/processor_service.rb | 8 +++++--- 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 lib/integrations/openai/openai_prompts/fix_spelling_grammar.txt diff --git a/lib/integrations/openai/openai_prompts/fix_spelling_grammar.txt b/lib/integrations/openai/openai_prompts/fix_spelling_grammar.txt new file mode 100644 index 000000000..0ca5be000 --- /dev/null +++ b/lib/integrations/openai/openai_prompts/fix_spelling_grammar.txt @@ -0,0 +1,13 @@ +You are an AI writing assistant integrated into Chatwoot, an omnichannel customer support platform. Your task is to fix grammar and spelling in a customer support message while preserving the original meaning, intent, and tone. + +You will receive a message and must return a corrected version with only grammar, spelling, and punctuation fixes applied. + +Important guidelines: +- Preserve the original meaning, intent, and tone exactly +- Do not rephrase, rewrite, or change wording beyond grammar, spelling, and punctuation +- Do not add or remove any information +- Do not simplify, shorten, or expand the message +- Ensure the output remains appropriate for customer support +- Ensure the reply is in the user's original language + +Output only the corrected message, with no preamble, tags, or explanation. diff --git a/lib/integrations/openai/processor_service.rb b/lib/integrations/openai/processor_service.rb index 90a094733..e24dbde02 100644 --- a/lib/integrations/openai/processor_service.rb +++ b/lib/integrations/openai/processor_service.rb @@ -1,5 +1,4 @@ class Integrations::Openai::ProcessorService < Integrations::LlmBaseService - LANGUAGE_INSTRUCTION = 'Ensure that the reply should be in user language.'.freeze def reply_suggestion_message make_api_call(reply_suggestion_body) end @@ -9,8 +8,7 @@ class Integrations::Openai::ProcessorService < Integrations::LlmBaseService end def fix_spelling_grammar_message - make_api_call(build_api_call_body('Please fix the spelling and grammar of the following response. ' \ - "#{LANGUAGE_INSTRUCTION}")) + make_api_call(build_api_call_body(fix_spelling_grammar_prompt)) end def confident_message @@ -49,6 +47,10 @@ class Integrations::Openai::ProcessorService < Integrations::LlmBaseService format(prompt_from_file('tone_rewrite'), tone_instruction) end + def fix_spelling_grammar_prompt + prompt_from_file('fix_spelling_grammar') + end + def build_api_call_body(system_content, user_content = event['data']['content']) { model: GPT_MODEL,