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:
@@ -1,10 +1,11 @@
|
|||||||
class Integrations::OpenaiBaseService
|
class Integrations::OpenaiBaseService
|
||||||
# 3.5 support 16,385 tokens
|
# gpt-4o-mini supports 128,000 tokens
|
||||||
# 1 token is approx 4 characters
|
# 1 token is approx 4 characters
|
||||||
# 16385 * 4 = 65540 characters, sticking to 50,000 to be safe
|
# sticking with 120000 to be safe
|
||||||
TOKEN_LIMIT = 50_000
|
# 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
|
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
|
ALLOWED_EVENT_NAMES = %w[rephrase summarize reply_suggestion fix_spelling_grammar shorten expand make_friendly make_formal simplify].freeze
|
||||||
CACHEABLE_EVENTS = %w[].freeze
|
CACHEABLE_EVENTS = %w[].freeze
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ RSpec.describe Integrations::Openai::ProcessorService do
|
|||||||
|
|
||||||
it 'returns the rephrased message using the tone in data' do
|
it 'returns the rephrased message using the tone in data' do
|
||||||
request_body = {
|
request_body = {
|
||||||
'model' => 'gpt-3.5-turbo',
|
'model' => 'gpt-4o-mini',
|
||||||
'messages' => [
|
'messages' => [
|
||||||
{
|
{
|
||||||
'role' => 'system',
|
'role' => 'system',
|
||||||
@@ -61,7 +61,7 @@ RSpec.describe Integrations::Openai::ProcessorService do
|
|||||||
|
|
||||||
it 'returns the suggested reply' do
|
it 'returns the suggested reply' do
|
||||||
request_body = {
|
request_body = {
|
||||||
'model' => 'gpt-3.5-turbo',
|
'model' => 'gpt-4o-mini',
|
||||||
'messages' => [
|
'messages' => [
|
||||||
{ role: 'system',
|
{ role: 'system',
|
||||||
content: Rails.root.join('lib/integrations/openai/openai_prompts/reply.txt').read },
|
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
|
it 'returns the summarized message' do
|
||||||
request_body = {
|
request_body = {
|
||||||
'model' => 'gpt-3.5-turbo',
|
'model' => 'gpt-4o-mini',
|
||||||
'messages' => [
|
'messages' => [
|
||||||
{ 'role' => 'system',
|
{ 'role' => 'system',
|
||||||
'content' => summary_prompt },
|
'content' => summary_prompt },
|
||||||
@@ -127,7 +127,7 @@ RSpec.describe Integrations::Openai::ProcessorService do
|
|||||||
|
|
||||||
it 'returns the corrected text' do
|
it 'returns the corrected text' do
|
||||||
request_body = {
|
request_body = {
|
||||||
'model' => 'gpt-3.5-turbo',
|
'model' => 'gpt-4o-mini',
|
||||||
'messages' => [
|
'messages' => [
|
||||||
{ 'role' => 'system', 'content' => 'You are a helpful support agent. Please fix the spelling and grammar of the following response. ' \
|
{ '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.' },
|
'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
|
it 'returns the shortened text' do
|
||||||
request_body = {
|
request_body = {
|
||||||
'model' => 'gpt-3.5-turbo',
|
'model' => 'gpt-4o-mini',
|
||||||
'messages' => [
|
'messages' => [
|
||||||
{ 'role' => 'system', 'content' => 'You are a helpful support agent. Please shorten the following response. ' \
|
{ 'role' => 'system', 'content' => 'You are a helpful support agent. Please shorten the following response. ' \
|
||||||
'Ensure that the reply should be in user language.' },
|
'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
|
it 'returns the expanded text' do
|
||||||
request_body = {
|
request_body = {
|
||||||
'model' => 'gpt-3.5-turbo',
|
'model' => 'gpt-4o-mini',
|
||||||
'messages' => [
|
'messages' => [
|
||||||
{ 'role' => 'system', 'content' => 'You are a helpful support agent. Please expand the following response. ' \
|
{ 'role' => 'system', 'content' => 'You are a helpful support agent. Please expand the following response. ' \
|
||||||
'Ensure that the reply should be in user language.' },
|
'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
|
it 'returns the friendly text' do
|
||||||
request_body = {
|
request_body = {
|
||||||
'model' => 'gpt-3.5-turbo',
|
'model' => 'gpt-4o-mini',
|
||||||
'messages' => [
|
'messages' => [
|
||||||
{ 'role' => 'system', 'content' => 'You are a helpful support agent. Please make the following response more friendly. ' \
|
{ '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.' },
|
'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
|
it 'returns the formal text' do
|
||||||
request_body = {
|
request_body = {
|
||||||
'model' => 'gpt-3.5-turbo',
|
'model' => 'gpt-4o-mini',
|
||||||
'messages' => [
|
'messages' => [
|
||||||
{ 'role' => 'system', 'content' => 'You are a helpful support agent. Please make the following response more formal. ' \
|
{ '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.' },
|
'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
|
it 'returns the simplified text' do
|
||||||
request_body = {
|
request_body = {
|
||||||
'model' => 'gpt-3.5-turbo',
|
'model' => 'gpt-4o-mini',
|
||||||
'messages' => [
|
'messages' => [
|
||||||
{ 'role' => 'system', 'content' => 'You are a helpful support agent. Please simplify the following response. ' \
|
{ 'role' => 'system', 'content' => 'You are a helpful support agent. Please simplify the following response. ' \
|
||||||
'Ensure that the reply should be in user language.' },
|
'Ensure that the reply should be in user language.' },
|
||||||
|
|||||||
Reference in New Issue
Block a user