feat: 适配gpt-5-codex模型

This commit is contained in:
shaw
2025-09-16 09:01:41 +08:00
parent 646e62d6be
commit 51cb92d395
3 changed files with 19 additions and 2 deletions

View File

@@ -139,7 +139,7 @@ const handleResponses = async (req, res) => {
let requestedModel = req.body?.model || null
// 如果模型是 gpt-5 开头且后面还有内容(如 gpt-5-2025-08-07则覆盖为 gpt-5
if (requestedModel && requestedModel.startsWith('gpt-5-') && requestedModel !== 'gpt-5') {
if (requestedModel && requestedModel.startsWith('gpt-5-') && requestedModel !== 'gpt-5-codex') {
logger.info(`📝 Model ${requestedModel} detected, normalizing to gpt-5 for Codex API`)
requestedModel = 'gpt-5'
req.body.model = 'gpt-5' // 同时更新请求体中的模型

View File

@@ -265,6 +265,15 @@ class PricingService {
return this.pricingData[modelName]
}
// 特殊处理gpt-5-codex 回退到 gpt-5
if (modelName === 'gpt-5-codex' && !this.pricingData['gpt-5-codex']) {
const fallbackPricing = this.pricingData['gpt-5']
if (fallbackPricing) {
logger.info(`💰 Using gpt-5 pricing as fallback for ${modelName}`)
return fallbackPricing
}
}
// 对于Bedrock区域前缀模型如 us.anthropic.claude-sonnet-4-20250514-v1:0
// 尝试去掉区域前缀进行匹配
if (modelName.includes('.anthropic.') || modelName.includes('.claude')) {

View File

@@ -242,6 +242,14 @@ class CostCalculator {
* @returns {Object} 定价信息
*/
static getModelPricing(model = 'unknown') {
// 特殊处理gpt-5-codex 回退到 gpt-5如果没有专门定价
if (model === 'gpt-5-codex' && !MODEL_PRICING['gpt-5-codex']) {
const gpt5Pricing = MODEL_PRICING['gpt-5']
if (gpt5Pricing) {
console.log(`Using gpt-5 pricing as fallback for ${model}`)
return gpt5Pricing
}
}
return MODEL_PRICING[model] || MODEL_PRICING['unknown']
}
@@ -285,7 +293,7 @@ class CostCalculator {
* @returns {Object} 节省信息
*/
static calculateCacheSavings(usage, model = 'unknown') {
const pricing = this.getModelPricing(model)
const pricing = this.getModelPricing(model) // 已包含 gpt-5-codex 回退逻辑
const cacheReadTokens = usage.cache_read_input_tokens || 0
// 如果这些token不使用缓存需要按正常input价格计费