Skip to content

Commit 41af4a7

Browse files
author
Filip Trplan
committed
fix: prevent countTokens from counting images
1 parent 72ffc62 commit 41af4a7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/lib/tokenizer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { countTokens } from "gpt-tokenizer/model/gpt-4o"
33
import type { Message } from "~/services/copilot/create-chat-completions"
44

55
export const getTokenCount = (messages: Array<Message>) => {
6-
const input = messages.filter((m) => m.role !== "assistant")
6+
const input = messages.filter(
7+
(m) => m.role !== "assistant" && typeof m.content === "string",
8+
)
9+
console.log(input)
710
const output = messages.filter((m) => m.role === "assistant")
811

912
const inputTokens = countTokens(input)

0 commit comments

Comments
 (0)