From ab86f62fcc6dbc313e41b987bf34efce4e5ba8e2 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Sun, 15 Sep 2024 21:11:20 -0700 Subject: [PATCH] chore: Update GPT Model (#10111) Update the open AI model, as 3.5 is being deprecated. Provide as option to swap out models via environment variables. --- lib/integrations/openai_base_service.rb | 9 +++++---- .../openai/processor_service_spec.rb | 18 +++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/integrations/openai_base_service.rb b/lib/integrations/openai_base_service.rb index 1e8b42485..908e496a7 100644 --- a/lib/integrations/openai_base_service.rb +++ b/lib/integrations/openai_base_service.rb @@ -1,10 +1,11 @@ class Integrations::OpenaiBaseService - # 3.5 support 16,385 tokens + # gpt-4o-mini supports 128,000 tokens # 1 token is approx 4 characters - # 16385 * 4 = 65540 characters, sticking to 50,000 to be safe - TOKEN_LIMIT = 50_000 + # sticking with 120000 to be safe + # 120000 * 4 = 480,000 characters (rounding off downwards to 400,000 to be safe) + TOKEN_LIMIT = 400_000 API_URL = 'https://api.openai.com/v1/chat/completions'.freeze - GPT_MODEL = 'gpt-3.5-turbo'.freeze + GPT_MODEL = ENV.fetch('OPENAI_GPT_MODEL', 'gpt-4o-mini').freeze ALLOWED_EVENT_NAMES = %w[rephrase summarize reply_suggestion fix_spelling_grammar shorten expand make_friendly make_formal simplify].freeze CACHEABLE_EVENTS = %w[].freeze diff --git a/spec/lib/integrations/openai/processor_service_spec.rb b/spec/lib/integrations/openai/processor_service_spec.rb index ec0a7bc91..8bbf5d5fb 100644 --- a/spec/lib/integrations/openai/processor_service_spec.rb +++ b/spec/lib/integrations/openai/processor_service_spec.rb @@ -35,7 +35,7 @@ RSpec.describe Integrations::Openai::ProcessorService do it 'returns the rephrased message using the tone in data' do request_body = { - 'model' => 'gpt-3.5-turbo', + 'model' => 'gpt-4o-mini', 'messages' => [ { 'role' => 'system', @@ -61,7 +61,7 @@ RSpec.describe Integrations::Openai::ProcessorService do it 'returns the suggested reply' do request_body = { - 'model' => 'gpt-3.5-turbo', + 'model' => 'gpt-4o-mini', 'messages' => [ { role: 'system', content: Rails.root.join('lib/integrations/openai/openai_prompts/reply.txt').read }, @@ -88,7 +88,7 @@ RSpec.describe Integrations::Openai::ProcessorService do it 'returns the summarized message' do request_body = { - 'model' => 'gpt-3.5-turbo', + 'model' => 'gpt-4o-mini', 'messages' => [ { 'role' => 'system', 'content' => summary_prompt }, @@ -127,7 +127,7 @@ RSpec.describe Integrations::Openai::ProcessorService do it 'returns the corrected text' do request_body = { - 'model' => 'gpt-3.5-turbo', + 'model' => 'gpt-4o-mini', 'messages' => [ { 'role' => 'system', 'content' => 'You are a helpful support agent. Please fix the spelling and grammar of the following response. ' \ 'Ensure that the reply should be in user language.' }, @@ -149,7 +149,7 @@ RSpec.describe Integrations::Openai::ProcessorService do it 'returns the shortened text' do request_body = { - 'model' => 'gpt-3.5-turbo', + 'model' => 'gpt-4o-mini', 'messages' => [ { 'role' => 'system', 'content' => 'You are a helpful support agent. Please shorten the following response. ' \ 'Ensure that the reply should be in user language.' }, @@ -171,7 +171,7 @@ RSpec.describe Integrations::Openai::ProcessorService do it 'returns the expanded text' do request_body = { - 'model' => 'gpt-3.5-turbo', + 'model' => 'gpt-4o-mini', 'messages' => [ { 'role' => 'system', 'content' => 'You are a helpful support agent. Please expand the following response. ' \ 'Ensure that the reply should be in user language.' }, @@ -193,7 +193,7 @@ RSpec.describe Integrations::Openai::ProcessorService do it 'returns the friendly text' do request_body = { - 'model' => 'gpt-3.5-turbo', + 'model' => 'gpt-4o-mini', 'messages' => [ { 'role' => 'system', 'content' => 'You are a helpful support agent. Please make the following response more friendly. ' \ 'Ensure that the reply should be in user language.' }, @@ -215,7 +215,7 @@ RSpec.describe Integrations::Openai::ProcessorService do it 'returns the formal text' do request_body = { - 'model' => 'gpt-3.5-turbo', + 'model' => 'gpt-4o-mini', 'messages' => [ { 'role' => 'system', 'content' => 'You are a helpful support agent. Please make the following response more formal. ' \ 'Ensure that the reply should be in user language.' }, @@ -237,7 +237,7 @@ RSpec.describe Integrations::Openai::ProcessorService do it 'returns the simplified text' do request_body = { - 'model' => 'gpt-3.5-turbo', + 'model' => 'gpt-4o-mini', 'messages' => [ { 'role' => 'system', 'content' => 'You are a helpful support agent. Please simplify the following response. ' \ 'Ensure that the reply should be in user language.' },