fix(bom-costing): bound GPT-5 reasoning time

This commit is contained in:
WuYongJie 2026-08-04 16:43:59 +08:00
parent 608da97538
commit b3fd61dadb
3 changed files with 28 additions and 1 deletions

View File

@ -97,6 +97,7 @@ BOM_COSTING_MARKET_TIMEOUT_MS=60000
BOM_COSTING_AI_TIMEOUT_MS=300000
BOM_COSTING_AI_MAX_IMAGES=20
BOM_COSTING_AI_MAX_TOKENS=24000
BOM_COSTING_AI_REASONING_EFFORT=low
BOM_COSTING_MODELING_PROVIDER=
# 素材库白底图回传

View File

@ -228,7 +228,7 @@ describe('BOM 多模态分析器', () => {
name: '多模态模型',
baseUrl: 'https://ai.example.com/v1',
apiKey: 'test-ai-key',
model: 'vision-model',
model: 'gpt-5.6-luna',
extra: null,
isActive: true,
sortOrder: 0,
@ -710,6 +710,9 @@ describe('BOM 多模态分析器', () => {
message.content.some((content) => content.type === 'image_url'),
),
).toBe(false)
expect(requestBody).toMatchObject({
reasoning_effort: 'low',
})
expect(output.trace).toMatchObject({
imageCount: 4,
factBatchCount: 0,

View File

@ -28,6 +28,13 @@ export interface BomCostingMultimodalCallResult {
export type BomCostingMultimodalOperation = 'IMAGE_FACTS' | 'SYNTHESIS'
const BOM_COSTING_REASONING_EFFORTS = new Set([
'minimal',
'low',
'medium',
'high',
])
export function readBomCostingBoundedInteger(
value: string | undefined,
fallback: number,
@ -44,6 +51,20 @@ function getAiServiceType() {
return process.env.BOM_COSTING_AI_SERVICE_TYPE?.trim() || 'prompt-optimizer'
}
function getBomCostingReasoningEffort(model: string) {
const configured = process.env.BOM_COSTING_AI_REASONING_EFFORT
?.trim()
.toLowerCase()
if (configured && BOM_COSTING_REASONING_EFFORTS.has(configured)) {
return configured
}
// The configured GPT-5-compatible gateway terminates long, non-streaming
// reasoning around two minutes. BOM synthesis is structured extraction, not
// an open-ended reasoning task, so keep the default response bounded.
return /^gpt-5(?:[.-]|$)/i.test(model) ? 'low' : undefined
}
export async function getBomCostingMultimodalProviderConfig():
Promise<BomCostingMultimodalProviderConfig | null> {
const active = await providerConfigService.getActive(getAiServiceType())
@ -280,6 +301,7 @@ export async function callBomCostingMultimodalModel(input: {
timeoutMs: number
}): Promise<BomCostingMultimodalCallResult> {
const endpoint = `${input.config.baseUrl.replace(/\/+$/, '')}/chat/completions`
const reasoningEffort = getBomCostingReasoningEffort(input.config.model)
const startedAt = Date.now()
let response: Response
try {
@ -299,6 +321,7 @@ export async function callBomCostingMultimodalModel(input: {
temperature: 0.1,
max_tokens: input.maxTokens,
stream: true,
...(reasoningEffort ? { reasoning_effort: reasoningEffort } : {}),
}),
cache: 'no-store',
signal: AbortSignal.timeout(input.timeoutMs),