From dd85520c35ee097220d3738bc56204b7c85f1d66 Mon Sep 17 00:00:00 2001 From: Linghui Gong Date: Fri, 19 Jul 2024 21:09:02 +0800 Subject: [PATCH] :sparkles: feat: add `gpt-4o-mini` in OpenAI Provider and set it as the default model (#3256) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :sparkles: feat: gpt-4o-mini to openai provider * ♻️ refactor: move gpt-4o-mini as default model * ✅ test: fix test * 🐛 fix: set gpt-4o-mini as default model * chore: improve code * chore: improve code --------- Co-authored-by: arvinxx --- .i18nrc.js | 2 +- .seorc.cjs | 2 +- src/config/modelProviders/openai.ts | 109 ++++++++++-------- src/const/settings/agent.ts | 3 +- src/const/settings/llm.ts | 2 +- src/database/client/schemas/session.ts | 3 +- .../openai/__snapshots__/index.test.ts.snap | 1 - .../__snapshots__/index.test.ts.snap | 2 +- src/locales/default/setting.ts | 6 - .../modelList/selectors/modelProvider.test.ts | 2 +- .../modelList/selectors/modelProvider.ts | 2 +- src/types/agent/index.ts | 2 +- 12 files changed, 70 insertions(+), 66 deletions(-) diff --git a/.i18nrc.js b/.i18nrc.js index 754554b1838d4..25624e3b6b2b8 100644 --- a/.i18nrc.js +++ b/.i18nrc.js @@ -23,7 +23,7 @@ module.exports = defineConfig({ 'vi-VN', ], temperature: 0, - modelName: 'gpt-3.5-turbo-0125', + modelName: 'gpt-4o-mini', splitToken: 2048, experimental: { jsonMode: true, diff --git a/.seorc.cjs b/.seorc.cjs index 8d8ada8cda0fd..5626a1ab0b161 100644 --- a/.seorc.cjs +++ b/.seorc.cjs @@ -2,7 +2,7 @@ const { defineConfig } = require('@lobehub/seo-cli'); module.exports = defineConfig({ entry: ['./docs/**/*.mdx'], - modelName: 'gpt-3.5-turbo-0125', + modelName: 'gpt-4o-mini', experimental: { jsonMode: true, }, diff --git a/src/config/modelProviders/openai.ts b/src/config/modelProviders/openai.ts index 87f39fa1b6acc..7d4483bc7739b 100644 --- a/src/config/modelProviders/openai.ts +++ b/src/config/modelProviders/openai.ts @@ -4,48 +4,40 @@ import { ModelProviderCard } from '@/types/llm'; const OpenAI: ModelProviderCard = { chatModels: [ { - description: 'GPT 3.5 Turbo,适用于各种文本生成和理解任务', - displayName: 'GPT-3.5 Turbo', + description: 'Currently points to gpt-4o-mini-2024-07-18', + displayName: 'GPT-4o mini', enabled: true, functionCall: true, - id: 'gpt-3.5-turbo', - tokens: 16_385, + id: 'gpt-4o-mini', + maxOutput: 16_385, + tokens: 128_000, + vision: true, }, { - displayName: 'GPT-3.5 Turbo (0125)', + description: 'Currently points to gpt-4o-2024-05-13', + displayName: 'GPT-4o', + enabled: true, functionCall: true, - id: 'gpt-3.5-turbo-0125', - tokens: 16_385, + id: 'gpt-4o', + tokens: 128_000, + vision: true, }, { - displayName: 'GPT-3.5 Turbo (1106)', + description: 'GPT-4 Turbo with Vision', + displayName: 'GPT-4 Turbo', + enabled: true, functionCall: true, - id: 'gpt-3.5-turbo-1106', - tokens: 16_385, - }, - { - displayName: 'GPT-3.5 Turbo Instruct', - id: 'gpt-3.5-turbo-instruct', - tokens: 4096, - }, - { - description: 'Currently points to gpt-3.5-turbo-16k-0613', - displayName: 'GPT-3.5 Turbo 16K', - id: 'gpt-3.5-turbo-16k', - legacy: true, - tokens: 16_385, - }, - { - displayName: 'GPT-3.5 Turbo (0613)', - id: 'gpt-3.5-turbo-0613', - legacy: true, - tokens: 4096, + id: 'gpt-4-turbo', + tokens: 128_000, + vision: true, }, { - displayName: 'GPT-3.5 Turbo 16K (0613)', - id: 'gpt-3.5-turbo-16k-0613', - legacy: true, - tokens: 16_385, + description: 'GPT-4 Turbo 视觉版 (240409)', + displayName: 'GPT-4 Turbo Vision (240409)', + functionCall: true, + id: 'gpt-4-turbo-2024-04-09', + tokens: 128_000, + vision: true, }, { description: 'Currently points to gpt-4-0125-preview', @@ -106,33 +98,50 @@ const OpenAI: ModelProviderCard = { tokens: 32_768, }, { - description: 'GPT-4 Turbo with Vision', - displayName: 'GPT-4 Turbo', - enabled: true, + description: 'GPT 3.5 Turbo,适用于各种文本生成和理解任务', + displayName: 'GPT-3.5 Turbo', functionCall: true, - id: 'gpt-4-turbo', - tokens: 128_000, - vision: true, + id: 'gpt-3.5-turbo', + tokens: 16_385, }, { - description: 'GPT-4 Turbo 视觉版 (240409)', - displayName: 'GPT-4 Turbo Vision (240409)', + displayName: 'GPT-3.5 Turbo (0125)', functionCall: true, - id: 'gpt-4-turbo-2024-04-09', - tokens: 128_000, - vision: true, + id: 'gpt-3.5-turbo-0125', + tokens: 16_385, }, { - description: 'Currently points to gpt-4o-2024-05-13', - displayName: 'GPT-4o', - enabled: true, + displayName: 'GPT-3.5 Turbo (1106)', functionCall: true, - id: 'gpt-4o', - tokens: 128_000, - vision: true, + id: 'gpt-3.5-turbo-1106', + tokens: 16_385, + }, + { + displayName: 'GPT-3.5 Turbo Instruct', + id: 'gpt-3.5-turbo-instruct', + tokens: 4096, + }, + { + description: 'Currently points to gpt-3.5-turbo-16k-0613', + displayName: 'GPT-3.5 Turbo 16K', + id: 'gpt-3.5-turbo-16k', + legacy: true, + tokens: 16_385, + }, + { + displayName: 'GPT-3.5 Turbo (0613)', + id: 'gpt-3.5-turbo-0613', + legacy: true, + tokens: 4096, + }, + { + displayName: 'GPT-3.5 Turbo 16K (0613)', + id: 'gpt-3.5-turbo-16k-0613', + legacy: true, + tokens: 16_385, }, ], - checkModel: 'gpt-3.5-turbo', + checkModel: 'gpt-4o-mini', enabled: true, id: 'openai', modelList: { showModelFetcher: true }, diff --git a/src/const/settings/agent.ts b/src/const/settings/agent.ts index fdbf1d375642a..4aac293f685de 100644 --- a/src/const/settings/agent.ts +++ b/src/const/settings/agent.ts @@ -1,4 +1,5 @@ import { DEFAULT_AGENT_META } from '@/const/meta'; +import { DEFAULT_MODEL } from '@/const/settings/llm'; import { ModelProvider } from '@/libs/agent-runtime'; import { LobeAgentChatConfig, LobeAgentConfig, LobeAgentTTSConfig } from '@/types/agent'; import { UserDefaultAgent } from '@/types/user/settings'; @@ -21,7 +22,7 @@ export const DEFAULT_AGENT_CHAT_CONFIG: LobeAgentChatConfig = { export const DEFAULT_AGENT_CONFIG: LobeAgentConfig = { chatConfig: DEFAULT_AGENT_CHAT_CONFIG, - model: 'gpt-3.5-turbo', + model: DEFAULT_MODEL, params: { frequency_penalty: 0, presence_penalty: 0, diff --git a/src/const/settings/llm.ts b/src/const/settings/llm.ts index 0a34a09f06441..c6446df684a97 100644 --- a/src/const/settings/llm.ts +++ b/src/const/settings/llm.ts @@ -111,6 +111,6 @@ export const DEFAULT_LLM_CONFIG: UserModelProviderConfig = { }, }; -export const DEFAULT_MODEL = 'gpt-3.5-turbo'; +export const DEFAULT_MODEL = 'gpt-4o-mini'; export const DEFAULT_PROVIDER = ModelProvider.OpenAI; diff --git a/src/database/client/schemas/session.ts b/src/database/client/schemas/session.ts index b388000472b05..b742e102c4258 100644 --- a/src/database/client/schemas/session.ts +++ b/src/database/client/schemas/session.ts @@ -1,5 +1,6 @@ import { z } from 'zod'; +import { DEFAULT_MODEL } from '@/const/settings'; import { AgentChatConfigSchema } from '@/types/agent'; import { LobeMetaDataSchema } from '@/types/meta'; @@ -26,7 +27,7 @@ const ttsSchema = z.object({ export const AgentSchema = z.object({ chatConfig: AgentChatConfigSchema, fewShots: fewShotsSchema.optional(), - model: z.string().default('gpt-3.5-turbo'), + model: z.string().default(DEFAULT_MODEL), params: z.object({ frequency_penalty: z.number().default(0).optional(), max_tokens: z.number().optional(), diff --git a/src/libs/agent-runtime/openai/__snapshots__/index.test.ts.snap b/src/libs/agent-runtime/openai/__snapshots__/index.test.ts.snap index 614f711cfc30d..4fcb10f81af01 100644 --- a/src/libs/agent-runtime/openai/__snapshots__/index.test.ts.snap +++ b/src/libs/agent-runtime/openai/__snapshots__/index.test.ts.snap @@ -5,7 +5,6 @@ exports[`LobeOpenAI > models > should get models 1`] = ` { "description": "GPT 3.5 Turbo,适用于各种文本生成和理解任务", "displayName": "GPT-3.5 Turbo", - "enabled": true, "functionCall": true, "id": "gpt-3.5-turbo", "tokens": 16385, diff --git a/src/libs/agent-runtime/openrouter/__snapshots__/index.test.ts.snap b/src/libs/agent-runtime/openrouter/__snapshots__/index.test.ts.snap index bb7291f5959b2..6c943f5e22090 100644 --- a/src/libs/agent-runtime/openrouter/__snapshots__/index.test.ts.snap +++ b/src/libs/agent-runtime/openrouter/__snapshots__/index.test.ts.snap @@ -33,7 +33,7 @@ This project is led by [qnguyen3](https://twitter.com/stablequan) and [teknium]( Updated by OpenAI to point to the [latest version of GPT-3.5](/models?q=openai/gpt-3.5). Training data up to Sep 2021.", "displayName": "OpenAI: GPT-3.5 Turbo", - "enabled": true, + "enabled": false, "functionCall": false, "id": "openai/gpt-3.5-turbo", "maxTokens": 4096, diff --git a/src/locales/default/setting.ts b/src/locales/default/setting.ts index e9323bf4e86ae..e419a3f613dc5 100644 --- a/src/locales/default/setting.ts +++ b/src/locales/default/setting.ts @@ -213,12 +213,6 @@ export default { }, model: { desc: '{{provider}} 模型', - list: { - 'gpt-3.5-turbo': 'GPT 3.5', - 'gpt-3.5-turbo-16k': 'GPT 3.5 (16K)', - 'gpt-4': 'GPT 4', - 'gpt-4-32k': 'GPT 4 (32K)', - }, title: '模型', }, presencePenalty: { diff --git a/src/store/user/slices/modelList/selectors/modelProvider.test.ts b/src/store/user/slices/modelList/selectors/modelProvider.test.ts index 7ec7024670bec..0f6045364fdb1 100644 --- a/src/store/user/slices/modelList/selectors/modelProvider.test.ts +++ b/src/store/user/slices/modelList/selectors/modelProvider.test.ts @@ -49,7 +49,7 @@ describe('modelProviderSelectors', () => { const s = merge(initialState, {}) as unknown as UserStore; const result = modelProviderSelectors.getDefaultEnabledModelsById('openai')(s); - expect(result).toEqual(['gpt-3.5-turbo', 'gpt-4-turbo', 'gpt-4o']); + expect(result).toEqual(['gpt-4o-mini', 'gpt-4o', 'gpt-4-turbo']); }); it('should return undefined for a non-existing provider', () => { diff --git a/src/store/user/slices/modelList/selectors/modelProvider.ts b/src/store/user/slices/modelList/selectors/modelProvider.ts index 2e76975c8d944..283d372212e86 100644 --- a/src/store/user/slices/modelList/selectors/modelProvider.ts +++ b/src/store/user/slices/modelList/selectors/modelProvider.ts @@ -49,7 +49,7 @@ export const getDefaultModeProviderById = (provider: string) => (s: UserStore) = /** * get the default enabled models for a provider * it's a default enabled model list by Lobe Chat - * e.g. openai is ['gpt-3.5-turbo','gpt-4-turbo'] + * e.g. openai is ['gpt-4o-mini','gpt-4o','gpt-4-turbo'] */ const getDefaultEnabledModelsById = (provider: string) => (s: UserStore) => { const modelProvider = getDefaultModeProviderById(provider)(s); diff --git a/src/types/agent/index.ts b/src/types/agent/index.ts index a0cd13daddb5a..fb3bdd83463e9 100644 --- a/src/types/agent/index.ts +++ b/src/types/agent/index.ts @@ -20,7 +20,7 @@ export interface LobeAgentConfig { fewShots?: FewShots; /** * 角色所使用的语言模型 - * @default gpt-3.5-turbo + * @default gpt-4o-mini */ model: string; /**