feat: Add more options for AI reply suggestions (#7493)
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
class Integrations::Openai::ProcessorService < Integrations::OpenaiBaseService
|
||||
AGENT_INSTRUCTION = 'You are a helpful support agent.'.freeze
|
||||
LANGUAGE_INSTRUCTION = 'Reply in the user\'s language.'.freeze
|
||||
def reply_suggestion_message
|
||||
make_api_call(reply_suggestion_body)
|
||||
end
|
||||
@@ -11,16 +13,68 @@ class Integrations::Openai::ProcessorService < Integrations::OpenaiBaseService
|
||||
make_api_call(rephrase_body)
|
||||
end
|
||||
|
||||
def fix_spelling_grammar_message
|
||||
make_api_call(fix_spelling_grammar_body)
|
||||
end
|
||||
|
||||
def shorten_message
|
||||
make_api_call(shorten_body)
|
||||
end
|
||||
|
||||
def expand_message
|
||||
make_api_call(expand_body)
|
||||
end
|
||||
|
||||
def make_friendly_message
|
||||
make_api_call(make_friendly_body)
|
||||
end
|
||||
|
||||
def make_formal_message
|
||||
make_api_call(make_formal_body)
|
||||
end
|
||||
|
||||
def simplify_message
|
||||
make_api_call(simplify_body)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def rephrase_body
|
||||
build_api_call_body("#{AGENT_INSTRUCTION} Please rephrase the following response to a more #{event['data']['tone']} tone. " \
|
||||
"#{LANGUAGE_INSTRUCTION}")
|
||||
end
|
||||
|
||||
def fix_spelling_grammar_body
|
||||
build_api_call_body("#{AGENT_INSTRUCTION} Please fix the spelling and grammar of the following response. " \
|
||||
"#{LANGUAGE_INSTRUCTION}")
|
||||
end
|
||||
|
||||
def shorten_body
|
||||
build_api_call_body("#{AGENT_INSTRUCTION} Please shorten the following response. #{LANGUAGE_INSTRUCTION}")
|
||||
end
|
||||
|
||||
def expand_body
|
||||
build_api_call_body("#{AGENT_INSTRUCTION} Please expand the following response. #{LANGUAGE_INSTRUCTION}")
|
||||
end
|
||||
|
||||
def make_friendly_body
|
||||
build_api_call_body("#{AGENT_INSTRUCTION} Please make the following response more friendly. #{LANGUAGE_INSTRUCTION}")
|
||||
end
|
||||
|
||||
def make_formal_body
|
||||
build_api_call_body("#{AGENT_INSTRUCTION} Please make the following response more formal. #{LANGUAGE_INSTRUCTION}")
|
||||
end
|
||||
|
||||
def simplify_body
|
||||
build_api_call_body("#{AGENT_INSTRUCTION} Please simplify the following response. #{LANGUAGE_INSTRUCTION}")
|
||||
end
|
||||
|
||||
def build_api_call_body(system_content, user_content = event['data']['content'])
|
||||
{
|
||||
model: GPT_MODEL,
|
||||
messages: [
|
||||
{ role: 'system',
|
||||
content: "You are a helpful support agent. Please rephrase the following response to a more #{event['data']['tone']} tone. " \
|
||||
"Reply in the user's language." },
|
||||
{ role: 'user', content: event['data']['content'] }
|
||||
{ role: 'system', content: system_content },
|
||||
{ role: 'user', content: user_content }
|
||||
]
|
||||
}.to_json
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user