Skip to content

Commit

Permalink
Donwload tiktokenizer model in prod Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcampagnolitg committed Dec 6, 2024
1 parent 5c7422b commit 6f818eb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ USER $user
RUN mkdir .sophia
# Generate the function schemas
RUN npm run functionSchemas
# Download the tiktokenizer model
RUN npm run initTiktokenizer

ENV NODE_ENV=production
ENV PORT=8080
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"watch": " node --env-file=variables/local.env -r ts-node/register src/cli/watch.ts",
"build": " tsc",
"build:dev": "tsc -project tsconfig.swc.json",
"initTiktokenizer": "node --env-file=variables/local.env -r ts-node/register src/initTiktokenizer.ts",
"functionSchemas": "node --env-file=variables/local.env -r ts-node/register src/generateFunctionSchemas.ts",
"start": " node -r ts-node/register src/index.ts",
"start:local": "node -r ts-node/register --env-file=variables/local.env --inspect=0.0.0.0:9229 src/index.ts",
Expand Down
7 changes: 7 additions & 0 deletions src/initTiktokenizer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { countTokens } from '#llm/tokens';

// node_modules is read-only for the sophia user in prod, so download in the docker build
countTokens('hi').catch((err) => {
console.error('Failed to download tiktoken model');
console.error(err);
}).finally(() => console.log('Done'));

0 comments on commit 6f818eb

Please sign in to comment.