Compare commits

...

11 Commits

Author SHA1 Message Date
di-sukharev
220d0b292f 1.1.47 2023-04-05 12:55:22 +08:00
di-sukharev
e5d3c8d4ff 1.1.46 2023-04-05 12:55:16 +08:00
di-sukharev
cbc8d61f99 feat(.yml): add GitHub Action to close stale issues using actions/stale@v4.1.1 2023-04-05 12:54:38 +08:00
di-sukharev
7fd357e78e 1.1.45 2023-04-05 12:45:01 +08:00
di-sukharev
5837d1fa2e 1.1.44 2023-04-05 12:44:54 +08:00
di-sukharev
36f282d8a5 Merge branch 'dev' 2023-04-05 12:44:30 +08:00
Raymond
9f65c450e3 build(esbuild.config.js): add esbuild configuration file and move build command to it (#82)
feat(package.json): add @dqbd/tiktoken dependency
fix(tokenCount.ts): uncomment Tiktoken import and encoding, and return token length instead of an approximation
2023-04-05 12:42:07 +08:00
di-sukharev
d5f53fec5a 1.1.43 2023-04-05 12:36:17 +08:00
di-sukharev
b6651a4c47 1.1.42 2023-04-05 12:36:13 +08:00
di-sukharev
2b10dc089c refactor(githook.ts): remove unused platform variable and switch statement
fix(githook.ts): change DEFAULT_SYMLINK_URL to use relative path instead of absolute path
2023-04-05 12:35:23 +08:00
di-sukharev
a5e60ac23c 1.1.41 2023-04-05 12:32:13 +08:00
6 changed files with 33 additions and 37 deletions

2
.yml Normal file
View File

@@ -0,0 +1,2 @@
- name: Close Stale Issues
uses: actions/stale@v4.1.1

14
esbuild.config.js Normal file
View File

@@ -0,0 +1,14 @@
import { build } from 'esbuild'
import fs from 'fs'
await build({
entryPoints: ['./src/cli.ts'],
bundle: true,
platform: 'node',
format: 'cjs',
outfile: './out/cli.cjs',
});
const wasmFile = fs.readFileSync('./node_modules/@dqbd/tiktoken/lite/tiktoken_bg.wasm')
fs.writeFileSync('./out/tiktoken_bg.wasm', wasmFile)

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "opencommit",
"version": "1.1.40",
"version": "1.1.47",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "opencommit",
"version": "1.1.40",
"version": "1.1.47",
"license": "MIT",
"dependencies": {
"@clack/prompts": "^0.6.1",

View File

@@ -1,6 +1,6 @@
{
"name": "opencommit",
"version": "1.1.40",
"version": "1.1.47",
"description": "GPT CLI to auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
"keywords": [
"git",
@@ -40,7 +40,7 @@
"watch": "npm run -S build -- --sourcemap --watch",
"start": "node ./out/cli.cjs",
"dev": "ts-node ./src/cli.ts",
"build": "rimraf out && esbuild ./src/cli.ts --bundle --outfile=out/cli.cjs --format=cjs --platform=node",
"build": "rimraf out && node esbuild.config.js",
"deploy": "npm run build && npm version patch && npm publish --tag latest",
"lint": "eslint src --ext ts && tsc --noEmit",
"format": "prettier --write src"
@@ -60,6 +60,7 @@
},
"dependencies": {
"@clack/prompts": "^0.6.1",
"@dqbd/tiktoken": "^1.0.2",
"axios": "^1.3.4",
"chalk": "^5.2.0",
"cleye": "^1.3.2",

View File

@@ -7,30 +7,8 @@ import chalk from 'chalk';
import { intro, outro } from '@clack/prompts';
import { COMMANDS } from '../CommandsEnum.js';
const platform = process.platform;
let separator = '';
switch (platform) {
// Windows
case 'win32':
separator = path.sep;
break;
// macOS
case 'darwin':
separator = '';
break;
// Linux and Android
case 'android':
case 'linux':
separator = '';
break;
default:
throw new Error(`Unsupported platform: ${platform}`);
}
const HOOK_NAME = 'prepare-commit-msg';
const DEFAULT_SYMLINK_URL = path.join(separator, '.git', 'hooks', HOOK_NAME);
const DEFAULT_SYMLINK_URL = path.join('.git', 'hooks', HOOK_NAME);
const getHooksPath = async (): Promise<string> => {
try {

View File

@@ -1,14 +1,15 @@
// import { Tiktoken } from '@dqbd/tiktoken/lite';
// import cl100k_base from '@dqbd/tiktoken/encoders/cl100k_base.json' assert { type: 'json' };
import { Tiktoken } from '@dqbd/tiktoken/lite';
import cl100k_base from '@dqbd/tiktoken/encoders/cl100k_base.json' assert { type: 'json' };
export function tokenCount(content: string): number {
// const encoding = new Tiktoken(
// cl100k_base.bpe_ranks,
// cl100k_base.special_tokens,
// cl100k_base.pat_str
// );
// const tokens = encoding.encode(content);
// encoding.free();
const encoding = new Tiktoken(
cl100k_base.bpe_ranks,
cl100k_base.special_tokens,
cl100k_base.pat_str
);
const tokens = encoding.encode(content);
encoding.free();
return tokens.length;
return content.length / 2.7;
//return content.length / 2.7;
}