Skip to content

Commit fdd94eb

Browse files
committed
feat: Add token estimation and manual approval to state
1 parent a32ad7a commit fdd94eb

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/lib/state.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ export interface State {
77
accountType: string
88
models?: ModelsResponse
99
vsCodeVersion?: string
10+
11+
estimateToken: boolean
12+
manualApprove: boolean
1013
}
1114

1215
export const state: State = {
1316
accountType: "individual",
17+
estimateToken: true,
18+
manualApprove: false,
1419
}

src/lib/tokenizer.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { countTokens } from "gpt-tokenizer/model/gpt-4o"
2+
3+
import type { Message } from "~/services/copilot/create-chat-completions"
4+
5+
export const getTokenLength = (messages: Array<Message>) => {
6+
const input = messages.filter((m) => m.role !== "assistant")
7+
const output = messages.filter((m) => m.role === "assistant")
8+
9+
const inputTokens = countTokens(input)
10+
const outputTokens = countTokens(output)
11+
12+
return {
13+
input: inputTokens,
14+
output: outputTokens,
15+
}
16+
}

0 commit comments

Comments
 (0)