diff --git a/lib/integrations/openai/openai_prompts/fix_spelling_grammar.txt b/lib/integrations/openai/openai_prompts/fix_spelling_grammar.liquid
similarity index 100%
rename from lib/integrations/openai/openai_prompts/fix_spelling_grammar.txt
rename to lib/integrations/openai/openai_prompts/fix_spelling_grammar.liquid
diff --git a/lib/integrations/openai/openai_prompts/improve.txt b/lib/integrations/openai/openai_prompts/improve.liquid
similarity index 95%
rename from lib/integrations/openai/openai_prompts/improve.txt
rename to lib/integrations/openai/openai_prompts/improve.liquid
index 7d1947bdf..c60a89d38 100644
--- a/lib/integrations/openai/openai_prompts/improve.txt
+++ b/lib/integrations/openai/openai_prompts/improve.liquid
@@ -1,11 +1,11 @@
You are an expert customer support message optimizer. Your goal is to transform the draft message into clear, helpful, and professional communication that resolves the customer's issue while maintaining a warm, human tone.
CONTEXT:
-- Contact Name: %{contact_name}
+- Contact Name: {{ contact_name }}
- Recent Conversation History:
-%{conversation_history}
+{{ conversation_history }}
- Current Draft:
-%{draft_message}
+{{ draft_message }}
YOUR TASK:
Improve this draft message by:
diff --git a/lib/integrations/openai/openai_prompts/reply.txt b/lib/integrations/openai/openai_prompts/reply.liquid
similarity index 100%
rename from lib/integrations/openai/openai_prompts/reply.txt
rename to lib/integrations/openai/openai_prompts/reply.liquid
diff --git a/lib/integrations/openai/openai_prompts/summary.txt b/lib/integrations/openai/openai_prompts/summary.liquid
similarity index 100%
rename from lib/integrations/openai/openai_prompts/summary.txt
rename to lib/integrations/openai/openai_prompts/summary.liquid
diff --git a/lib/integrations/openai/openai_prompts/tone_rewrite.liquid b/lib/integrations/openai/openai_prompts/tone_rewrite.liquid
new file mode 100644
index 000000000..2f88da0bc
--- /dev/null
+++ b/lib/integrations/openai/openai_prompts/tone_rewrite.liquid
@@ -0,0 +1,31 @@
+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:
+
+{% case tone %}
+{% when 'friendly' %}
+Warm, approachable, and personable. Use conversational language, positive words, and show empathy. May include phrases like "Happy to help!" or "I'd be glad to..."
+{% when 'confident' %}
+Assertive and assured. Use definitive language, avoid hedging words like "maybe" or "I think". Be direct and authoritative while remaining helpful.
+{% when 'straightforward' %}
+Clear, direct, and to-the-point. Remove unnecessary words, get straight to the information or solution. No fluff or extra pleasantries.
+{% when 'casual' %}
+Relaxed and informal. Use contractions, simpler words, and a conversational style. Friendly but less formal than professional tone.
+{% when 'professional' %}
+Formal, polished, and business-appropriate. Use complete sentences, proper grammar, and maintain respectful distance. Avoid slang or overly casual language.
+{% else %}
+Warm, approachable, and personable. Use conversational language, positive words, and show empathy. May include phrases like "Happy to help!" or "I'd be glad to..."
+{% endcase %}
+
+
+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/openai_prompts/tone_rewrite.txt b/lib/integrations/openai/openai_prompts/tone_rewrite.txt
deleted file mode 100644
index 200a8c652..000000000
--- a/lib/integrations/openai/openai_prompts/tone_rewrite.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-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 e24dbde02..a6c413c04 100644
--- a/lib/integrations/openai/processor_service.rb
+++ b/lib/integrations/openai/processor_service.rb
@@ -12,39 +12,39 @@ class Integrations::Openai::ProcessorService < Integrations::LlmBaseService
end
def confident_message
- tone_instruction = determine_tone_instruction('confident')
- make_api_call(build_api_call_body(tone_rewrite_prompt(tone_instruction)))
+ make_api_call(build_api_call_body(tone_rewrite_prompt('confident')))
end
def straightforward_message
- tone_instruction = determine_tone_instruction('straightforward')
- make_api_call(build_api_call_body(tone_rewrite_prompt(tone_instruction)))
+ make_api_call(build_api_call_body(tone_rewrite_prompt('straightforward')))
end
def casual_message
- tone_instruction = determine_tone_instruction('casual')
- make_api_call(build_api_call_body(tone_rewrite_prompt(tone_instruction)))
+ make_api_call(build_api_call_body(tone_rewrite_prompt('casual')))
end
def friendly_message
- tone_instruction = determine_tone_instruction('friendly')
- make_api_call(build_api_call_body(tone_rewrite_prompt(tone_instruction)))
+ make_api_call(build_api_call_body(tone_rewrite_prompt('friendly')))
end
def professional_message
- tone_instruction = determine_tone_instruction('professional')
- make_api_call(build_api_call_body(tone_rewrite_prompt(tone_instruction)))
+ make_api_call(build_api_call_body(tone_rewrite_prompt('professional')))
end
private
def prompt_from_file(file_name, enterprise: false)
path = enterprise ? 'enterprise/lib/enterprise/integrations/openai_prompts' : 'lib/integrations/openai/openai_prompts'
- Rails.root.join(path, "#{file_name}.txt").read
+ Rails.root.join(path, "#{file_name}.liquid").read
end
- def tone_rewrite_prompt(tone_instruction)
- format(prompt_from_file('tone_rewrite'), tone_instruction)
+ def render_liquid_template(template_content, variables = {})
+ Liquid::Template.parse(template_content).render(variables)
+ end
+
+ def tone_rewrite_prompt(tone)
+ template = prompt_from_file('tone_rewrite')
+ render_liquid_template(template, 'tone' => tone)
end
def fix_spelling_grammar_prompt
@@ -133,26 +133,6 @@ class Integrations::Openai::ProcessorService < Integrations::LlmBaseService
].concat(conversation_messages(in_array_format: true))
}.to_json
end
-
- def determine_tone_instruction(tone)
- case tone
- when 'friendly'
- 'Warm, approachable, and personable. Use conversational language, positive words, and show empathy. ' \
- 'May include phrases like \"Happy to help!\" or \"I\'d be glad to...\"'
- when 'confident'
- 'Assertive and assured. Use definitive language, avoid hedging words like \"maybe\" or \"I think\". ' \
- 'Be direct and authoritative while remaining helpful.'
- when 'straightforward'
- 'Clear, direct, and to-the-point. Remove unnecessary words, get straight to the information or solution. No fluff or extra pleasantries.'
- when 'casual'
- 'Relaxed and informal. Use contractions, simpler words, and a conversational style. Friendly but less formal than professional tone.'
- when 'professional'
- 'Formal, polished, and business-appropriate. Use complete sentences, proper grammar, ' \
- 'and maintain respectful distance. Avoid slang or overly casual language.'
- else
- determine_tone_instruction('friendly')
- end
- end
end
Integrations::Openai::ProcessorService.prepend_mod_with('Integrations::OpenaiProcessorService')