fix: Improve reply prompt (#7588)
Co-authored-by: Sojan Jose <sojan@chatwoot.com>
This commit is contained in:
@@ -18,10 +18,6 @@ module Enterprise::Integrations::OpenaiProcessorService
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def prompt_from_file(file_name)
|
|
||||||
Rails.root.join('enterprise/lib/enterprise/integrations/openai_prompts', "#{file_name}.txt").read
|
|
||||||
end
|
|
||||||
|
|
||||||
def labels_with_messages
|
def labels_with_messages
|
||||||
conversation = find_conversation
|
conversation = find_conversation
|
||||||
|
|
||||||
@@ -47,7 +43,7 @@ module Enterprise::Integrations::OpenaiProcessorService
|
|||||||
model: self.class::GPT_MODEL,
|
model: self.class::GPT_MODEL,
|
||||||
messages: [
|
messages: [
|
||||||
{ role: 'system',
|
{ role: 'system',
|
||||||
content: prompt_from_file('summary') },
|
content: prompt_from_file('summary', enterprise: true) },
|
||||||
{ role: 'user', content: conversation_messages }
|
{ role: 'user', content: conversation_messages }
|
||||||
]
|
]
|
||||||
}.to_json
|
}.to_json
|
||||||
@@ -62,7 +58,7 @@ module Enterprise::Integrations::OpenaiProcessorService
|
|||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
role: 'system',
|
role: 'system',
|
||||||
content: prompt_from_file('label_suggestion')
|
content: prompt_from_file('label_suggestion', enterprise: true)
|
||||||
},
|
},
|
||||||
{ role: 'user', content: content }
|
{ role: 'user', content: content }
|
||||||
]
|
]
|
||||||
|
|||||||
1
lib/integrations/openai/openai_prompts/reply.txt
Normal file
1
lib/integrations/openai/openai_prompts/reply.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Please suggest a reply to the following conversation between support agents and customer. Don't expose that you are an AI model, respond "Couldn't generate the reply" in cases where you can't answer. Reply in the user\'s language.
|
||||||
1
lib/integrations/openai/openai_prompts/summary.txt
Normal file
1
lib/integrations/openai/openai_prompts/summary.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Please summarize the key points from the following conversation between support agents and customer as bullet points for the next support agent looking into the conversation. Reply in the user\'s language.
|
||||||
@@ -10,63 +10,45 @@ class Integrations::Openai::ProcessorService < Integrations::OpenaiBaseService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def rephrase_message
|
def rephrase_message
|
||||||
make_api_call(rephrase_body)
|
make_api_call(build_api_call_body("#{AGENT_INSTRUCTION} Please rephrase the following response. " \
|
||||||
|
"#{LANGUAGE_INSTRUCTION}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def fix_spelling_grammar_message
|
def fix_spelling_grammar_message
|
||||||
make_api_call(fix_spelling_grammar_body)
|
make_api_call(build_api_call_body("#{AGENT_INSTRUCTION} Please fix the spelling and grammar of the following response. " \
|
||||||
|
"#{LANGUAGE_INSTRUCTION}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def shorten_message
|
def shorten_message
|
||||||
make_api_call(shorten_body)
|
make_api_call(build_api_call_body("#{AGENT_INSTRUCTION} Please shorten the following response. " \
|
||||||
|
"#{LANGUAGE_INSTRUCTION}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def expand_message
|
def expand_message
|
||||||
make_api_call(expand_body)
|
make_api_call(build_api_call_body("#{AGENT_INSTRUCTION} Please expand the following response. " \
|
||||||
|
"#{LANGUAGE_INSTRUCTION}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_friendly_message
|
def make_friendly_message
|
||||||
make_api_call(make_friendly_body)
|
make_api_call(build_api_call_body("#{AGENT_INSTRUCTION} Please make the following response more friendly. " \
|
||||||
|
"#{LANGUAGE_INSTRUCTION}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_formal_message
|
def make_formal_message
|
||||||
make_api_call(make_formal_body)
|
make_api_call(build_api_call_body("#{AGENT_INSTRUCTION} Please make the following response more formal. " \
|
||||||
|
"#{LANGUAGE_INSTRUCTION}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def simplify_message
|
def simplify_message
|
||||||
make_api_call(simplify_body)
|
make_api_call(build_api_call_body("#{AGENT_INSTRUCTION} Please simplify the following response. " \
|
||||||
|
"#{LANGUAGE_INSTRUCTION}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def rephrase_body
|
def prompt_from_file(file_name, enterprise: false)
|
||||||
build_api_call_body("#{AGENT_INSTRUCTION} Please rephrase the following response. " \
|
path = enterprise ? 'enterprise/lib/enterprise/integrations/openai_prompts' : 'lib/integrations/openai/openai_prompts'
|
||||||
"#{LANGUAGE_INSTRUCTION}")
|
Rails.root.join(path, "#{file_name}.txt").read
|
||||||
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
|
end
|
||||||
|
|
||||||
def build_api_call_body(system_content, user_content = event['data']['content'])
|
def build_api_call_body(system_content, user_content = event['data']['content'])
|
||||||
@@ -136,8 +118,7 @@ class Integrations::Openai::ProcessorService < Integrations::OpenaiBaseService
|
|||||||
model: GPT_MODEL,
|
model: GPT_MODEL,
|
||||||
messages: [
|
messages: [
|
||||||
{ role: 'system',
|
{ role: 'system',
|
||||||
content: 'Please summarize the key points from the following conversation between support agents and ' \
|
content: prompt_from_file('summary', enterprise: false) },
|
||||||
'customer as bullet points for the next support agent looking into the conversation. Reply in the user\'s language.' },
|
|
||||||
{ role: 'user', content: conversation_messages }
|
{ role: 'user', content: conversation_messages }
|
||||||
]
|
]
|
||||||
}.to_json
|
}.to_json
|
||||||
@@ -148,7 +129,7 @@ class Integrations::Openai::ProcessorService < Integrations::OpenaiBaseService
|
|||||||
model: GPT_MODEL,
|
model: GPT_MODEL,
|
||||||
messages: [
|
messages: [
|
||||||
{ role: 'system',
|
{ role: 'system',
|
||||||
content: 'Please suggest a reply to the following conversation between support agents and customer. Reply in the user\'s language.' }
|
content: prompt_from_file('reply', enterprise: false) }
|
||||||
].concat(conversation_messages(in_array_format: true))
|
].concat(conversation_messages(in_array_format: true))
|
||||||
}.to_json
|
}.to_json
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ RSpec.describe Integrations::Openai::ProcessorService do
|
|||||||
'model' => 'gpt-3.5-turbo',
|
'model' => 'gpt-3.5-turbo',
|
||||||
'messages' => [
|
'messages' => [
|
||||||
{ role: 'system',
|
{ role: 'system',
|
||||||
content: 'Please suggest a reply to the following conversation between support agents and customer. Reply in the user\'s language.' },
|
content: Rails.root.join('lib/integrations/openai/openai_prompts/reply.txt').read },
|
||||||
{ role: 'user', content: customer_message.content },
|
{ role: 'user', content: customer_message.content },
|
||||||
{ role: 'assistant', content: agent_message.content }
|
{ role: 'assistant', content: agent_message.content }
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user