Skip to content

Commit

Permalink
🐛 fix: clean up gpt-3.5 model (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx authored Dec 12, 2023
1 parent 4a8dfa5 commit 9616783
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/chains/__tests__/summaryTitle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('chainSummaryTitle', () => {
role: 'user',
},
],
model: LanguageModel.GPT3_5_16K,
model: LanguageModel.GPT4_PREVIEW,
});

// Verify that getMessagesTokenCount was called with the correct messages
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('chainSummaryTitle', () => {
role: 'user',
},
],
model: 'gpt-3.5-turbo-16k',
// No model specified since the token count is below the limit
});

// Verify that getMessagesTokenCount was called with the correct messages
Expand Down
7 changes: 4 additions & 3 deletions src/chains/summaryTitle.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ModelTokens } from '@/const/modelTokens';
import { chatHelpers } from '@/store/chat/helpers';
import { globalHelpers } from '@/store/global/helpers';
import { LanguageModel } from '@/types/llm';
Expand All @@ -20,11 +21,11 @@ export const chainSummaryTitle = async (
role: 'user',
},
];
// 如果超过 4k,则使用 GPT3.5 16K 模型
// 如果超过 16k,则使用 GPT-4-turbo 模型
const tokens = await chatHelpers.getMessagesTokenCount(finalMessages);
let model: LanguageModel | undefined = undefined;
if (tokens > 4000) {
model = LanguageModel.GPT3_5_16K;
if (tokens > ModelTokens[LanguageModel.GPT3_5]) {
model = LanguageModel.GPT4_PREVIEW;
}

return {
Expand Down
4 changes: 1 addition & 3 deletions src/const/modelTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { LanguageModel } from '@/types/llm';

// refs to: https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo
export const ModelTokens: Record<LanguageModel, number> = {
[LanguageModel.GPT3_5]: 4096,
[LanguageModel.GPT3_5_1106]: 16_385,
[LanguageModel.GPT3_5_16K]: 16_385,
[LanguageModel.GPT3_5]: 16_385,
[LanguageModel.GPT4]: 8196,
[LanguageModel.GPT4_PREVIEW]: 128_000,
[LanguageModel.GPT4_VISION_PREVIEW]: 128_000,
Expand Down
16 changes: 0 additions & 16 deletions src/store/global/selectors/__snapshots__/settings.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ exports[`settingsSelectors > CUSTOM_MODELS > duplicate naming model 1`] = `
"displayName": "gpt-3.5-turbo",
"name": "gpt-3.5-turbo",
},
{
"displayName": "gpt-3.5-turbo-1106",
"name": "gpt-3.5-turbo-1106",
},
{
"displayName": "gpt-3.5-turbo-16k",
"name": "gpt-3.5-turbo-16k",
},
{
"displayName": "gpt-4",
"name": "gpt-4",
Expand All @@ -56,14 +48,6 @@ exports[`settingsSelectors > CUSTOM_MODELS > only add the model 1`] = `
"displayName": "gpt-3.5-turbo",
"name": "gpt-3.5-turbo",
},
{
"displayName": "gpt-3.5-turbo-1106",
"name": "gpt-3.5-turbo-1106",
},
{
"displayName": "gpt-3.5-turbo-16k",
"name": "gpt-3.5-turbo-16k",
},
{
"displayName": "gpt-4",
"name": "gpt-4",
Expand Down
2 changes: 0 additions & 2 deletions src/types/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ export enum LanguageModel {
* GPT 3.5 Turbo
*/
GPT3_5 = 'gpt-3.5-turbo',
GPT3_5_1106 = 'gpt-3.5-turbo-1106',
GPT3_5_16K = 'gpt-3.5-turbo-16k',
/**
* GPT 4
*/
Expand Down

0 comments on commit 9616783

Please sign in to comment.