feat: add new OpenAI models with proper temperature parameter handling

- Add GPT 4.1 series and o1/o3/o4 models with temperature compatibility fixes

- Remove gpt-5/gpt-5-mini models due to organization verification restrictions

- Fix 400 errors for models that only support default temperature values
This commit is contained in:
akubesti
2025-09-11 16:38:01 +07:00
parent 238bcaff2b
commit 328b12ffbe
2 changed files with 36 additions and 10 deletions

View File

@@ -120,7 +120,11 @@ export const getAvailableChatModelProviders = async () => {
model: new ChatOpenAI({
apiKey: customOpenAiApiKey,
modelName: customOpenAiModelName,
temperature: 0.7,
...((() => {
const temperatureRestrictedModels = ['gpt-5-nano', 'o1', 'o3-mini', 'o4-mini'];
const isTemperatureRestricted = temperatureRestrictedModels.some(restrictedModel => customOpenAiModelName.includes(restrictedModel));
return isTemperatureRestricted ? {} : { temperature: 0.7 };
})()),
configuration: {
baseURL: customOpenAiApiUrl,
},

View File

@@ -26,6 +26,10 @@ const openaiChatModels: Record<string, string>[] = [
displayName: 'GPT-4 omni',
key: 'gpt-4o',
},
{
displayName: 'GPT-4o (2024-05-13)',
key: 'gpt-4o-2024-05-13',
},
{
displayName: 'GPT-4 omni mini',
key: 'gpt-4o-mini',
@@ -47,12 +51,20 @@ const openaiChatModels: Record<string, string>[] = [
key: 'gpt-5-nano',
},
{
displayName: 'GPT 5 mini',
key: 'gpt-5-mini',
displayName: 'GPT 5 Chat Latest',
key: 'gpt-5-chat-latest',
},
{
displayName: 'GPT 5',
key: 'gpt-5',
displayName: 'o1',
key: 'o1',
},
{
displayName: 'o3 Mini',
key: 'o3-mini',
},
{
displayName: 'o4 Mini',
key: 'o4-mini',
},
];
@@ -76,13 +88,23 @@ export const loadOpenAIChatModels = async () => {
const chatModels: Record<string, ChatModel> = {};
openaiChatModels.forEach((model) => {
// Models that only support temperature = 1
const temperatureRestrictedModels = ['gpt-5-nano', 'o1', 'o3-mini', 'o4-mini'];
const isTemperatureRestricted = temperatureRestrictedModels.some(restrictedModel => model.key.includes(restrictedModel));
const modelConfig: any = {
apiKey: openaiApiKey,
modelName: model.key,
};
// Only add temperature if the model supports it
if (!isTemperatureRestricted) {
modelConfig.temperature = 0.7;
}
chatModels[model.key] = {
displayName: model.displayName,
model: new ChatOpenAI({
apiKey: openaiApiKey,
modelName: model.key,
temperature: model.key.includes('gpt-5') ? 1 : 0.7,
}) as unknown as BaseChatModel,
model: new ChatOpenAI(modelConfig) as unknown as BaseChatModel,
};
});