logprob: add bytes to logprobs (#13068)

This commit is contained in:
Parth Sareen
2025-11-13 13:49:25 -08:00
committed by GitHub
parent b48083f33f
commit c114987523
4 changed files with 312 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ func toAPILogprobs(logprobs []llm.Logprob) []api.Logprob {
result[i] = api.Logprob{
TokenLogprob: api.TokenLogprob{
Token: lp.Token,
Bytes: stringToByteInts(lp.Token),
Logprob: lp.Logprob,
},
}
@@ -20,6 +21,7 @@ func toAPILogprobs(logprobs []llm.Logprob) []api.Logprob {
for j, tlp := range lp.TopLogprobs {
result[i].TopLogprobs[j] = api.TokenLogprob{
Token: tlp.Token,
Bytes: stringToByteInts(tlp.Token),
Logprob: tlp.Logprob,
}
}
@@ -27,3 +29,16 @@ func toAPILogprobs(logprobs []llm.Logprob) []api.Logprob {
}
return result
}
func stringToByteInts(s string) []int {
if s == "" {
return nil
}
raw := []byte(s)
ints := make([]int, len(raw))
for i, b := range raw {
ints[i] = int(b)
}
return ints
}