diff --git a/enterprise/lib/enterprise/integrations/openai_processor_service.rb b/enterprise/lib/enterprise/integrations/openai_processor_service.rb index 2b086f8d2..8cc481f43 100644 --- a/enterprise/lib/enterprise/integrations/openai_processor_service.rb +++ b/enterprise/lib/enterprise/integrations/openai_processor_service.rb @@ -18,10 +18,6 @@ module Enterprise::Integrations::OpenaiProcessorService 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 conversation = find_conversation @@ -47,7 +43,7 @@ module Enterprise::Integrations::OpenaiProcessorService model: self.class::GPT_MODEL, messages: [ { role: 'system', - content: prompt_from_file('summary') }, + content: prompt_from_file('summary', enterprise: true) }, { role: 'user', content: conversation_messages } ] }.to_json @@ -62,7 +58,7 @@ module Enterprise::Integrations::OpenaiProcessorService messages: [ { role: 'system', - content: prompt_from_file('label_suggestion') + content: prompt_from_file('label_suggestion', enterprise: true) }, { role: 'user', content: content } ] diff --git a/lib/integrations/openai/openai_prompts/reply.txt b/lib/integrations/openai/openai_prompts/reply.txt new file mode 100644 index 000000000..77ff0a72e --- /dev/null +++ b/lib/integrations/openai/openai_prompts/reply.txt @@ -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. diff --git a/lib/integrations/openai/openai_prompts/summary.txt b/lib/integrations/openai/openai_prompts/summary.txt new file mode 100644 index 000000000..1639b60bb --- /dev/null +++ b/lib/integrations/openai/openai_prompts/summary.txt @@ -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. diff --git a/lib/integrations/openai/processor_service.rb b/lib/integrations/openai/processor_service.rb index a52cd3561..f71d2a7ed 100644 --- a/lib/integrations/openai/processor_service.rb +++ b/lib/integrations/openai/processor_service.rb @@ -10,63 +10,45 @@ class Integrations::Openai::ProcessorService < Integrations::OpenaiBaseService end 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 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 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 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 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 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 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 private - def rephrase_body - build_api_call_body("#{AGENT_INSTRUCTION} Please rephrase the following response. " \ - "#{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}") + 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 end 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, messages: [ { role: 'system', - content: '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.' }, + content: prompt_from_file('summary', enterprise: false) }, { role: 'user', content: conversation_messages } ] }.to_json @@ -148,7 +129,7 @@ class Integrations::Openai::ProcessorService < Integrations::OpenaiBaseService model: GPT_MODEL, messages: [ { 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)) }.to_json end diff --git a/spec/lib/integrations/openai/processor_service_spec.rb b/spec/lib/integrations/openai/processor_service_spec.rb index 1a9a0a6d0..b0972d2ca 100644 --- a/spec/lib/integrations/openai/processor_service_spec.rb +++ b/spec/lib/integrations/openai/processor_service_spec.rb @@ -64,7 +64,7 @@ RSpec.describe Integrations::Openai::ProcessorService do 'model' => 'gpt-3.5-turbo', 'messages' => [ { 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: 'assistant', content: agent_message.content } ]