Skip to content

Commit

Permalink
add stream token calculate
Browse files Browse the repository at this point in the history
Signed-off-by: oilbeater <[email protected]>
  • Loading branch information
oilbeater committed Sep 10, 2024
1 parent f0018dc commit 161e5bb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"wrangler": "^3.60.3"
},
"dependencies": {
"gpt-tokenizer": "^2.2.1",
"hono": "^4.5.5"
}
}
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Hono, Context } from 'hono'
import { encodeChat } from 'gpt-tokenizer'

type Bindings = {
MALACCA: AnalyticsEngineDataset,
Expand Down Expand Up @@ -39,7 +40,7 @@ async function handleChat(c: Context) {
return c.text('Internal Server Error', 500)
}
const decoder = new TextDecoder('utf-8');
let prompt_tokens = 0;
let prompt_tokens = encodeChat(body['messages']).length;
let completion_tokens = 0;

if (response.status == 200) {
Expand Down

0 comments on commit 161e5bb

Please sign in to comment.