refactor: use liquid
This commit is contained in:
@@ -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