fix: 修复temperature参数传递问题

This commit is contained in:
shaw
2025-10-12 18:35:28 +08:00
parent 40b7c68694
commit 45dab2af40

View File

@@ -975,18 +975,10 @@ class DroidRelayService {
processedBody.stream = true processedBody.stream = true
} }
const hasTemperatureField = Object.prototype.hasOwnProperty.call(processedBody, 'temperature')
// Anthropic 端点:处理 thinking 字段 // Anthropic 端点:处理 thinking 字段
if (endpointType === 'anthropic') { if (endpointType === 'anthropic') {
const hasTemperatureField = Object.prototype.hasOwnProperty.call(processedBody, 'temperature')
const hasValidTemperature =
processedBody.temperature !== undefined && processedBody.temperature !== null
const hasValidTopP = processedBody.top_p !== undefined && processedBody.top_p !== null
if (hasValidTemperature && hasValidTopP) {
// Claude API 仅允许 temperature 或 top_p 其一,同时优先保留 temperature
delete processedBody.top_p
}
if (this.systemPrompt) { if (this.systemPrompt) {
const promptBlock = { type: 'text', text: this.systemPrompt } const promptBlock = { type: 'text', text: this.systemPrompt }
if (Array.isArray(processedBody.system)) { if (Array.isArray(processedBody.system)) {
@@ -1064,6 +1056,16 @@ class DroidRelayService {
} }
} }
// 处理 temperature 和 top_p 参数
const hasValidTemperature =
processedBody.temperature !== undefined && processedBody.temperature !== null
const hasValidTopP = processedBody.top_p !== undefined && processedBody.top_p !== null
if (hasValidTemperature && hasValidTopP) {
// 仅允许 temperature 或 top_p 其一,同时优先保留 temperature
delete processedBody.top_p
}
return processedBody return processedBody
} }