Fix GPT-5 API compatibility and add AIUsageLog migration

- Add AIUsageLog table migration for token tracking
- Fix GPT-5 temperature parameter (not supported, like o-series)
- Add usesNewTokenParam() and supportsTemperature() functions
- Add GPT-5+ category to model selection UI
- Update model sorting to show GPT-5+ first

GPT-5 and newer models use max_completion_tokens and don't support
custom temperature values, similar to reasoning models.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-03 15:04:16 +01:00
parent c0ce6f9f1f
commit 3986da172f
8 changed files with 423 additions and 41 deletions

View File

@@ -25,6 +25,12 @@ const REASONING_MODEL_PREFIXES = ['o1', 'o3', 'o4']
*/
const NEW_TOKEN_PARAM_PREFIXES = ['o1', 'o3', 'o4', 'gpt-5', 'gpt-6', 'gpt-7']
/**
* Models that don't support custom temperature values.
* These only accept the default temperature (1).
*/
const NO_TEMPERATURE_PREFIXES = ['o1', 'o3', 'o4', 'gpt-5', 'gpt-6', 'gpt-7']
/**
* Check if a model is a reasoning model (o1, o3, o4 series)
* These models have additional restrictions (no temperature, no json_object, etc.)
@@ -51,6 +57,19 @@ export function usesNewTokenParam(model: string): boolean {
)
}
/**
* Check if a model supports custom temperature values.
* Newer models (o-series, GPT-5+) only accept default temperature (1).
*/
export function supportsTemperature(model: string): boolean {
const modelLower = model.toLowerCase()
return !NO_TEMPERATURE_PREFIXES.some(prefix =>
modelLower.startsWith(prefix) ||
modelLower.includes(`/${prefix}`) ||
modelLower.includes(`-${prefix}`)
)
}
// ─── Chat Completion Parameter Builder ───────────────────────────────────────
type MessageRole = 'system' | 'user' | 'assistant' | 'developer'
@@ -113,8 +132,8 @@ export function buildCompletionParams(
}
}
// Reasoning models don't support temperature
if (!isReasoning && options.temperature !== undefined) {
// Newer models (o-series, GPT-5+) don't support custom temperature
if (supportsTemperature(model) && options.temperature !== undefined) {
params.temperature = options.temperature
}