@dqbd/tiktoken
Advanced tools
Comparing version 1.0.0-alpha.4 to 1.0.0-alpha.5
{ | ||
"name": "@dqbd/tiktoken", | ||
"version": "1.0.0-alpha.4", | ||
"version": "1.0.0-alpha.5", | ||
"description": "Javascript bindings for tiktoken", | ||
@@ -22,6 +22,2 @@ "license": "MIT", | ||
}, | ||
"./bundler": { | ||
"types": "./tiktoken.d.ts", | ||
"default": "./tiktoken.js" | ||
}, | ||
"./init": { | ||
@@ -46,6 +42,2 @@ "types": "./init.d.ts", | ||
}, | ||
"./lite/bundler": { | ||
"types": "./lite/tiktoken.d.ts", | ||
"default": "./lite/tiktoken.js" | ||
}, | ||
"./lite/init": { | ||
@@ -52,0 +44,0 @@ "types": "./lite/init.d.ts", |
@@ -138,69 +138,2 @@ # ⏳ tiktoken | ||
#### Next.js 12 | ||
Using the older Next.js 12 version? Use the `@dqbd/tiktoken/bundler` or `@dqbd/tiktoken/lite/bundler` instead alongside the following `next.config.json` and `tsconfig.json` configurations: | ||
```javascript | ||
// next.config.json | ||
const config = { | ||
webpack(config, { isServer, dev }) { | ||
config.experiments = { | ||
asyncWebAssembly: true, | ||
topLevelAwait: true, | ||
layers: true, | ||
}; | ||
return config; | ||
}, | ||
}; | ||
``` | ||
```json | ||
// tsconfig.json | ||
{ | ||
"compilerOptions": { | ||
"moduleResolution": "node16" | ||
} | ||
} | ||
``` | ||
Usage in pages: | ||
```typescript | ||
import { get_encoding } from "@dqbd/tiktoken/bundler"; | ||
import { useState } from "react"; | ||
const encoding = get_encoding("cl100k_base"); | ||
export default function Home() { | ||
const [input, setInput] = useState("hello world"); | ||
const tokens = encoding.encode(input); | ||
return ( | ||
<div> | ||
<input | ||
type="text" | ||
value={input} | ||
onChange={(e) => setInput(e.target.value)} | ||
/> | ||
<div>{tokens.toString()}</div> | ||
</div> | ||
); | ||
} | ||
``` | ||
Usage in API routes: | ||
```typescript | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import { get_encoding } from "@dqbd/tiktoken/bundler"; | ||
export default function handler(req: NextApiRequest, res: NextApiResponse) { | ||
const encoding = get_encoding("cl100k_base"); | ||
const tokens = encoding.encode("hello world"); | ||
encoding.free(); | ||
res.status(200).json({ tokens }); | ||
} | ||
``` | ||
### [Vercel Edge Runtime](#vercel-edge-runtime) | ||
@@ -207,0 +140,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5047860
193