openai-chat-tokens
openai-chat-tokens copied to clipboard
Convert to ESModules & export everything
Hi!
While using this package, I needed to import some private types. There were also some imports that were very tricky to use, so I moved the package to ESModules for better compatibility. I also encountered an issue while using Jest; it seems like it's severely outdated as its ESModule support is experimental. Switching to Vitest made it work without having a config file.
With this change, instead of:
import type {
FunctionDef,
ObjectProp, // Module '"openai-chat-tokens/dist/functions.js"' declares 'ObjectProp' locally, but it is not exported.
} from "openai-chat-tokens/dist/functions.js"
It's now:
import type { FunctionDef, ObjectProp } from "openai-chat-tokens"
- Closes https://github.com/coderabbitai/openai-chat-tokens/pull/1
import { functionsTokensEstimate } from 'openai-chat-tokens';
type FunctionDef = Parameters<typeof functionsTokensEstimate>[0][number];
type ObjectProp = FunctionDef['parameters'];
Maybe you can try like this.
Yeah, that's true. I ended up re-publishing the package under https://github.com/coderabbitai/openai-chat-tokens to avoid dealing with more type aliases.