fix(integration): check truncated length (#12337)

This commit is contained in:
Michael Yang
2025-09-18 14:00:21 -07:00
committed by GitHub
parent 2717dce6fe
commit ceac416ec2
2 changed files with 113 additions and 66 deletions

View File

@@ -634,7 +634,7 @@ func (s *Server) EmbedHandler(c *gin.Context) {
ctxLen := min(opts.NumCtx, int(kvData.ContextLength()))
if len(tokens) > ctxLen {
if !truncate {
c.JSON(http.StatusBadRequest, gin.H{"error": "input length exceeds maximum context length"})
c.JSON(http.StatusBadRequest, gin.H{"error": "input exceeds maximum context length"})
return
}
@@ -646,6 +646,13 @@ func (s *Server) EmbedHandler(c *gin.Context) {
ctxLen--
}
slog.Info("", "ctxLen", ctxLen, "tokenCount", len(tokens))
if ctxLen <= 0 {
// return error if the truncated input would be empty or just special tokens
c.JSON(http.StatusBadRequest, gin.H{"error": "input after truncation exceeds maximum context length"})
return
}
tokens = tokens[:ctxLen]
s, err = r.Detokenize(c.Request.Context(), tokens)