Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Style] Add GitHub action for linter and pre-commit hook formater #412

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ debug
lib
build
node_modules
3rdparty
.eslintrc.cjs
5 changes: 3 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
rules: {
"@typescript-eslint/no-explicit-any": "off"
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": "off"
}
};
27 changes: 27 additions & 0 deletions .github/workflows/linter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Linter

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'

- name: Install dependencies
run: npm install

- name: Run lint
run: npm run lint
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
6 changes: 6 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"./**/*.{js,ts,jsx,tsx,json,html,css,md}": [
"eslint --fix",
"prettier --write"
]
}
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dist
debug
lib
build
node_modules
3rdparty
.eslintrc.cjs
136 changes: 129 additions & 7 deletions package-lock.json

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

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
"type": "module",
"scripts": {
"build": "rollup -c && ./cleanup-index-js.sh",
"lint": "npx eslint .",
"test": "yarn jest"
"lint": "npx eslint ./src/ && npx prettier ./src --check",
"test": "yarn jest",
"format": "prettier --write \"./src/\"",
"prepare": "husky"
},
"files": [
"lib"
Expand Down Expand Up @@ -36,7 +38,11 @@
"@webgpu/types": "^0.1.24",
"buffer": "^5.7.1",
"eslint": "^8.41.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"husky": "^9.0.11",
"jest": "^29.7.0",
"prettier": "3.2.5",
"process": "^0.11.10",
"rollup": "^2.56.2",
"rollup-plugin-ignore": "^1.0.10",
Expand Down
50 changes: 34 additions & 16 deletions src/cache_util.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import * as tvmjs from "tvmjs";
import {
AppConfig,
ModelRecord,
prebuiltAppConfig,
} from "./config";
import { AppConfig, ModelRecord, prebuiltAppConfig } from "./config";

function findModelRecord(modelId: string, appConfig?: AppConfig): ModelRecord {
const matchedItem = appConfig?.model_list.find(
item => item.model_id == modelId
(item) => item.model_id == modelId,
);
if (matchedItem !== undefined) {
return matchedItem;
}
throw Error("Cannot find model_url for " + modelId);
}

export async function hasModelInCache(modelId: string, appConfig?: AppConfig): Promise<boolean> {
export async function hasModelInCache(
modelId: string,
appConfig?: AppConfig,
): Promise<boolean> {
if (appConfig === undefined) {
appConfig = prebuiltAppConfig;
}
Expand All @@ -25,7 +24,10 @@ export async function hasModelInCache(modelId: string, appConfig?: AppConfig): P
return tvmjs.hasNDArrayInCache(modelUrl, "webllm/model", cacheType);
}

export async function deleteModelAllInfoInCache(modelId: string, appConfig?: AppConfig) {
export async function deleteModelAllInfoInCache(
modelId: string,
appConfig?: AppConfig,
) {
// function to delete model all information in cache
if (appConfig === undefined) {
appConfig = prebuiltAppConfig;
Expand All @@ -34,30 +36,43 @@ export async function deleteModelAllInfoInCache(modelId: string, appConfig?: App
await deleteModelInCache(modelId, appConfig);
// delete wasm in cache
await deleteModelWasmInCache(modelId, appConfig);
// delete chat config
// delete chat config
await deleteChatConfigInCache(modelId, appConfig);
}


export async function deleteModelInCache(modelId: string, appConfig?: AppConfig) {
export async function deleteModelInCache(
modelId: string,
appConfig?: AppConfig,
) {
// delete the model NDArray In Cache
if (appConfig === undefined) {
appConfig = prebuiltAppConfig;
}
const modelRecord = findModelRecord(modelId, appConfig);
let modelCache: tvmjs.ArtifactCacheTemplate;
if (appConfig.useIndexedDBCache) {
tvmjs.deleteNDArrayCache(modelRecord.model_url, "webllm/model", "indexeddb");
tvmjs.deleteNDArrayCache(
modelRecord.model_url,
"webllm/model",
"indexeddb",
);
modelCache = new tvmjs.ArtifactIndexedDBCache("webllm/model");
} else {
tvmjs.deleteNDArrayCache(modelRecord.model_url, "webllm/model", "cache");
modelCache = new tvmjs.ArtifactCache("webllm/model");
}
await modelCache.deleteInCache(new URL("tokenizer.model", modelRecord.model_url).href);
await modelCache.deleteInCache(new URL("tokenizer.json", modelRecord.model_url).href);
await modelCache.deleteInCache(
new URL("tokenizer.model", modelRecord.model_url).href,
);
await modelCache.deleteInCache(
new URL("tokenizer.json", modelRecord.model_url).href,
);
}

export async function deleteChatConfigInCache(modelId: string, appConfig?: AppConfig) {
export async function deleteChatConfigInCache(
modelId: string,
appConfig?: AppConfig,
) {
// delete the chat configuration in Cache
if (appConfig === undefined) {
appConfig = prebuiltAppConfig;
Expand All @@ -73,7 +88,10 @@ export async function deleteChatConfigInCache(modelId: string, appConfig?: AppCo
await configCache.deleteInCache(configUrl);
}

export async function deleteModelWasmInCache(modelId: string, appConfig?: AppConfig) {
export async function deleteModelWasmInCache(
modelId: string,
appConfig?: AppConfig,
) {
// delete the wasm in Cache
if (appConfig === undefined) {
appConfig = prebuiltAppConfig;
Expand Down
Loading
Loading