From 24125e2d9a651aeeb77b53673250e3f16ae6b76f Mon Sep 17 00:00:00 2001 From: aakashb95 Date: Fri, 12 Dec 2025 14:39:58 +0530 Subject: [PATCH] move agent instruction for tone to file --- .../openai/openai_prompts/tone_rewrite.txt | 19 ++++++++++ lib/integrations/openai/processor_service.rb | 36 ++++++------------- 2 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 lib/integrations/openai/openai_prompts/tone_rewrite.txt diff --git a/lib/integrations/openai/openai_prompts/tone_rewrite.txt b/lib/integrations/openai/openai_prompts/tone_rewrite.txt new file mode 100644 index 000000000..200a8c652 --- /dev/null +++ b/lib/integrations/openai/openai_prompts/tone_rewrite.txt @@ -0,0 +1,19 @@ +You are an AI writing assistant integrated into Chatwoot, an omnichannel customer support platform. Your task is to rewrite customer support message to match a specific tone while preserving the original meaning and intent. + +Here is the tone to apply to the message you will receive: + +%s + + +Your task is to rewrite the message according to the specified tone instructions. + +Important guidelines: +- Preserve the core meaning and all important information from the original message +- Keep the rewritten message concise and appropriate for customer support +- Maintain helpfulness and respect regardless of tone +- Do not add information that wasn't in the original message +- Do not remove critical details or instructions +- Ensure that the reply should be in user language. + +Output only the rewritten message without any preamble, tags or explanation. + diff --git a/lib/integrations/openai/processor_service.rb b/lib/integrations/openai/processor_service.rb index 1814ac2d6..0f648cf22 100644 --- a/lib/integrations/openai/processor_service.rb +++ b/lib/integrations/openai/processor_service.rb @@ -1,25 +1,5 @@ class Integrations::Openai::ProcessorService < Integrations::LlmBaseService LANGUAGE_INSTRUCTION = 'Ensure that the reply should be in user language.'.freeze - AGENT_INSTRUCTION = <<~HEREDOC.freeze - You are an AI writing assistant integrated into Chatwoot, an omnichannel customer support platform. Your task is to rewrite customer support message to match a specific tone while preserving the original meaning and intent. - - Here is the tone to apply to the message you will receive: - - %s - - - Your task is to rewrite the message according to the specified tone instructions. - - Important guidelines: - - Preserve the core meaning and all important information from the original message - - Keep the rewritten message concise and appropriate for customer support - - Maintain helpfulness and respect regardless of tone - - Do not add information that wasn't in the original message - - Do not remove critical details or instructions - - #{LANGUAGE_INSTRUCTION} - - Output only the rewritten message without any preamble, tags or explanation. - HEREDOC def reply_suggestion_message make_api_call(reply_suggestion_body) end @@ -30,7 +10,7 @@ class Integrations::Openai::ProcessorService < Integrations::LlmBaseService def confident_message tone_instruction = determine_tone_instruction('confident') - make_api_call(build_api_call_body(format(AGENT_INSTRUCTION, tone_instruction))) + make_api_call(build_api_call_body(tone_rewrite_prompt(tone_instruction))) end def fix_spelling_grammar_message @@ -40,27 +20,27 @@ class Integrations::Openai::ProcessorService < Integrations::LlmBaseService def straightforward_message tone_instruction = determine_tone_instruction('straightforward') - make_api_call(build_api_call_body(format(AGENT_INSTRUCTION, tone_instruction))) + make_api_call(build_api_call_body(tone_rewrite_prompt(tone_instruction))) end def casual_message tone_instruction = determine_tone_instruction('casual') - make_api_call(build_api_call_body(format(AGENT_INSTRUCTION, tone_instruction))) + make_api_call(build_api_call_body(tone_rewrite_prompt(tone_instruction))) end def make_friendly_message tone_instruction = determine_tone_instruction('friendly') - make_api_call(build_api_call_body(format(AGENT_INSTRUCTION, tone_instruction))) + make_api_call(build_api_call_body(tone_rewrite_prompt(tone_instruction))) end def make_formal_message tone_instruction = determine_tone_instruction('formal') - make_api_call(build_api_call_body(format(AGENT_INSTRUCTION, tone_instruction))) + make_api_call(build_api_call_body(tone_rewrite_prompt(tone_instruction))) end def professional_message tone_instruction = determine_tone_instruction('professional') - make_api_call(build_api_call_body(format(AGENT_INSTRUCTION, tone_instruction))) + make_api_call(build_api_call_body(tone_rewrite_prompt(tone_instruction))) end private @@ -70,6 +50,10 @@ class Integrations::Openai::ProcessorService < Integrations::LlmBaseService Rails.root.join(path, "#{file_name}.txt").read end + def tone_rewrite_prompt(tone_instruction) + format(prompt_from_file('tone_rewrite'), tone_instruction) + end + def build_api_call_body(system_content, user_content = event['data']['content']) { model: GPT_MODEL,