More null checks for llamacpp logprobs parser

This commit is contained in:
Cohee
2024-12-20 22:00:36 +02:00
parent 1dd97c139e
commit 4232f6c5f4

View File

@ -1039,11 +1039,13 @@ export function parseTextgenLogprobs(token, logprobs) {
return { token, topLogprobs: candidates }; return { token, topLogprobs: candidates };
} }
case LLAMACPP: { case LLAMACPP: {
/** @type {Record<string, number>[]} */
if (!logprobs?.length) { if (!logprobs?.length) {
return null; return null;
} }
const candidates = logprobs[0].probs.map(x => [x.tok_str, x.prob]); const candidates = logprobs?.[0]?.probs?.map(x => [x.tok_str, x.prob]);
if (!candidates) {
return null;
}
return { token, topLogprobs: candidates }; return { token, topLogprobs: candidates };
} }
default: default: