Skip to content

Commit

Permalink
fix: 🐛 add fallback for token encoder & assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Dec 3, 2024
1 parent e861545 commit e89d84e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ async function choicesToLogitBias(
if (!choices?.length) return undefined
const { encode } = await resolveTokenEncoder(model, {
disableFallback: true,
})
}) || {}
if (!encode) {
trace.error(
`unabled to compute logit bias, no token encoder found for ${model}`
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/encoders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from "node:path"
import { addLineNumbers, indexToLineNumber } from "./liner"
import { resolveFileContent } from "./file"
import type { EncodeOptions } from "gpt-tokenizer/GptEncoding"
import { assert } from "./util"

/**
* Resolves the appropriate token encoder based on the given model ID.
Expand All @@ -31,6 +32,7 @@ export async function resolveTokenEncoder(
decode,
default: api,
} = await import(`gpt-tokenizer/model/${module}`)
assert(!!encode)
const { modelName } = api
const size =
api.bytePairEncodingCoreProcessor?.mergeableBytePairRankCount +
Expand All @@ -50,6 +52,7 @@ export async function resolveTokenEncoder(
decode,
default: api,
} = await import("gpt-tokenizer/model/gpt-4o")
assert(!!encode)
const { modelName, vocabularySize } = api
return Object.freeze<Tokenizer>({
model: modelName,
Expand Down

0 comments on commit e89d84e

Please sign in to comment.