Files
langchaingo/internal/numutil/num.go
T
Sergey Kozyrenko 058e344d90 fix(vertex,bedrock): saturate max tokens instead of wrapping to a negative limit
WithMaxTokens above MaxInt32 wrapped: 3_000_000_000 became -1294967296 on the
Vertex generation config (max output tokens, candidate count and top-k) and on
the Converse inference config. The googleai adapter already saturated, so the
same call succeeded there and failed on the sibling doors.

The saturating conversion moves to internal/numutil so the three doors share one
implementation. The Vertex generation config is extracted into a function so the
conversion has a seam a test can reach.

Not changed: the thinking-budget conversion in googleai, where GetTokens is
already clamped to MaxReasoningTokens and cannot overflow.

PAGI-132
2026-08-23 00:32:07 +07:00

15 lines
205 B
Go

package numutil
import "math"
func SaturateInt32(i int) int32 {
switch {
case i > math.MaxInt32:
return math.MaxInt32
case i < math.MinInt32:
return math.MinInt32
default:
return int32(i)
}
}