refactor: use liquid
This commit is contained in:
+3
-3
@@ -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:
|
||||
@@ -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:
|
||||
<tone_instruction>
|
||||
{% 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 %}
|
||||
</tone_instruction>
|
||||
|
||||
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.
|
||||
@@ -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:
|
||||
<tone_instruction>
|
||||
%s
|
||||
</tone_instruction>
|
||||
|
||||
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.
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user