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.
This commit is contained in:
Sojan Jose
2024-09-15 21:11:20 -07:00
committed by GitHub
parent aaab2ac788
commit ab86f62fcc
2 changed files with 14 additions and 13 deletions

View File

@@ -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

View File

@@ -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.' },