diff --git a/.github/scripts/e2e-test-install-nitro-node.js b/.github/scripts/nitro-node/e2e-test-install-nitro-node.js similarity index 100% rename from .github/scripts/e2e-test-install-nitro-node.js rename to .github/scripts/nitro-node/e2e-test-install-nitro-node.js diff --git a/.github/workflows/build-nitro-node.yml b/.github/workflows/build-nitro-node.yml index cce5bc310..8a4c003d2 100644 --- a/.github/workflows/build-nitro-node.yml +++ b/.github/workflows/build-nitro-node.yml @@ -1,8 +1,8 @@ name: Build nitro-node on: - #schedule: - # - cron: "0 20 * * *" # At 8 PM UTC, which is 3 AM UTC+7 + schedule: + - cron: "0 20 * * *" # At 0:20 UTC, which is 7:20 AM UTC+7 push: branches: - main @@ -13,189 +13,20 @@ on: paths: [".github/workflows/build-nitro-node.yml", "nitro-node"] workflow_dispatch: -jobs: - ubuntu-amd64-non-cuda-build: - runs-on: ubuntu-latest - steps: - - name: Clone - id: checkout - uses: actions/checkout@v4 - with: - submodules: recursive +env: + LLM_MODEL_URL: https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf + WHISPER_MODEL_URL: https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-tiny-q5_1.bin - - uses: actions/setup-node@v4 - with: - node-version: 18 - - - name: Restore cached model file - id: cache-model-restore - uses: actions/cache/restore@v4 - with: - path: | - nitro-node/test/test_assets/*.gguf - key: ${{ runner.os }}-model-gguf - - - uses: suisei-cn/actions-download-file@v1.4.0 - id: download-model-file - name: Download model file - with: - url: "The model we are using is [tinyllama-1.1b](https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf)!" - target: nitro-node/test/test_assets/ - auto-match: true - retry-times: 3 - - - name: Save downloaded model file to cache - id: cache-model-save - uses: actions/cache/save@v4 - with: - path: | - nitro-node/test/test_assets/*.gguf - key: ${{ steps.cache-model-restore.outputs.cache-primary-key }} - - - name: Run tests - id: test_nitro_node - run: | - cd nitro-node - make clean test-ci - - #ubuntu-amd64-build: - # runs-on: ubuntu-18-04-cuda-11-7 - # steps: - # - name: Clone - # id: checkout - # uses: actions/checkout@v4 - # with: - # submodules: recursive - - # - uses: actions/setup-node@v4 - # with: - # node-version: 18 - - # - name: Restore cached model file - # id: cache-model-restore - # uses: actions/cache/restore@v4 - # with: - # path: | - # nitro-node/test/test_assets/*.gguf - # key: ${{ runner.os }}-model-gguf - - # - uses: suisei-cn/actions-download-file@v1.4.0 - # id: download-model-file - # name: Download model file - # with: - # url: "The model we are using is [tinyllama-1.1b](https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf)!" - # target: nitro-node/test/test_assets/ - # auto-match: true - # retry-times: 3 - - # - name: Save downloaded model file to cache - # id: cache-model-save - # uses: actions/cache/save@v4 - # with: - # path: | - # nitro-node/test/test_assets/*.gguf - # key: ${{ steps.cache-model-restore.outputs.cache-primary-key }} - - # - name: Run tests - # id: test_nitro_node - # run: | - # cd nitro-node - # make clean test-ci - - #ubuntu-amd64-cuda-build: - # runs-on: ubuntu-18-04-cuda-${{ matrix.cuda }} - # strategy: - # matrix: - # cuda: ["12-0", "11-7"] - - # steps: - # - name: Clone - # id: checkout - # uses: actions/checkout@v4 - # with: - # submodules: recursive - - # - uses: actions/setup-node@v4 - # with: - # node-version: 18 - - # - name: Restore cached model file - # id: cache-model-restore - # uses: actions/cache/restore@v4 - # with: - # path: | - # nitro-node/test/test_assets/*.gguf - # key: ${{ runner.os }}-model-gguf - - # - uses: suisei-cn/actions-download-file@v1.4.0 - # id: download-model-file - # name: Download model file - # with: - # url: "The model we are using is [tinyllama-1.1b](https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf)!" - # target: nitro-node/test/test_assets/ - # auto-match: true - # retry-times: 3 - - # - name: Save downloaded model file to cache - # id: cache-model-save - # uses: actions/cache/save@v4 - # with: - # path: | - # nitro-node/test/test_assets/*.gguf - # key: ${{ steps.cache-model-restore.outputs.cache-primary-key }} - - # - name: Run tests - # id: test_nitro_node - # run: | - # cd nitro-node - # make clean test-ci - - macOS-M-build: - runs-on: macos-14 - steps: - - name: Clone - id: checkout - uses: actions/checkout@v4 - with: - submodules: recursive - - - uses: actions/setup-node@v4 - with: - node-version: 18 - - - name: Restore cached model file - id: cache-model-restore - uses: actions/cache/restore@v4 - with: - path: | - nitro-node/test/test_assets/*.gguf - key: ${{ runner.os }}-model-gguf - - - uses: suisei-cn/actions-download-file@v1.4.0 - id: download-model-file - name: Download model file - with: - url: "The model we are using is [tinyllama-1.1b](https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf)!" - target: nitro-node/test/test_assets/ - auto-match: true - retry-times: 3 - - - name: Save downloaded model file to cache - id: cache-model-save - uses: actions/cache/save@v4 - with: - path: | - nitro-node/test/test_assets/*.gguf - key: ${{ steps.cache-model-restore.outputs.cache-primary-key }} - - - name: Run tests - id: test_nitro_node - run: | - cd nitro-node - make clean test-ci +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest - macOS-Intel-build: - runs-on: macos-latest steps: - name: Clone id: checkout @@ -219,7 +50,7 @@ jobs: id: download-model-file name: Download model file with: - url: "The model we are using is [tinyllama-1.1b](https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf)!" + url: "The model we are using is [tinyllama-1.1b](${{ env.LLM_MODEL_URL }})!" target: nitro-node/test/test_assets/ auto-match: true retry-times: 3 @@ -237,119 +68,3 @@ jobs: run: | cd nitro-node make clean test-ci - - #windows-amd64-build: - # runs-on: windows-latest - # steps: - # - name: Clone - - # id: checkout - # uses: actions/checkout@v4 - # with: - # submodules: recursive - - # - uses: actions/setup-node@v4 - # with: - # node-version: 18 - - # - name: Setup VSWhere.exe - # uses: warrenbuckley/Setup-VSWhere@v1 - # with: - # version: latest - # silent: true - # env: - # ACTIONS_ALLOW_UNSECURE_COMMANDS: true - - # - name: Restore cached model file - # id: cache-model-restore - # uses: actions/cache/restore@v4 - # with: - # path: | - # nitro-node/test/test_assets/*.gguf - # key: ${{ runner.os }}-model-gguf - - # - uses: suisei-cn/actions-download-file@v1.4.0 - # id: download-model-file - # name: Download model file - # with: - # url: "The model we are using is [tinyllama-1.1b](https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf)!" - # target: nitro-node/test/test_assets/ - # auto-match: true - # retry-times: 3 - - # - name: Save downloaded model file to cache - # id: cache-model-save - # uses: actions/cache/save@v4 - # with: - # path: | - # nitro-node/test/test_assets/*.gguf - # key: ${{ steps.cache-model-restore.outputs.cache-primary-key }} - - # - name: Run tests - # id: test_nitro_node - # run: | - # cd nitro-node - # make clean test-ci - - #windows-amd64-cuda-build: - # runs-on: windows-cuda-${{ matrix.cuda }} - # strategy: - # matrix: - # cuda: ["12-0", "11-7"] - - # steps: - # - name: Clone - # id: checkout - # uses: actions/checkout@v4 - # with: - # submodules: recursive - - # - uses: actions/setup-node@v4 - # with: - # node-version: 18 - - # - name: actions-setup-cmake - # uses: jwlawson/actions-setup-cmake@v1.14.1 - - # - name: Setup VSWhere.exe - # uses: warrenbuckley/Setup-VSWhere@v1 - # with: - # version: latest - # silent: true - # env: - # ACTIONS_ALLOW_UNSECURE_COMMANDS: true - - # - uses: actions/setup-dotnet@v3 - # with: - # dotnet-version: "6.0.x" - - # - name: Restore cached model file - # id: cache-model-restore - # uses: actions/cache/restore@v4 - # with: - # path: | - # nitro-node/test/test_assets/*.gguf - # key: ${{ runner.os }}-model-gguf - - # - uses: suisei-cn/actions-download-file@v1.4.0 - # id: download-model-file - # name: Download model file - # with: - # url: "The model we are using is [tinyllama-1.1b](https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf)!" - # target: nitro-node/test/test_assets/ - # auto-match: true - # retry-times: 3 - - # - name: Save downloaded model file to cache - # id: cache-model-save - # uses: actions/cache/save@v4 - # with: - # path: | - # nitro-node/test/test_assets/*.gguf - # key: ${{ steps.cache-model-restore.outputs.cache-primary-key }} - - # - name: Run tests - # id: test_nitro_node - # run: | - # cd nitro-node - # make clean test-ci diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7bb556afd..2fa9f36a6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,7 @@ name: CI on: schedule: - - cron: "0 20 * * *" # At 8 PM UTC, which is 3 AM UTC+7 + - cron: "0 20 * * *" # At 0:20 UTC, which is 7:20 AM UTC+7 push: branches: - main @@ -24,6 +24,7 @@ on: "!docs/**", "!.gitignore", "!README.md", + "!nitro-node/**", ] pull_request: types: [opened, synchronize, reopened] @@ -44,6 +45,7 @@ on: "!docs/**", "!.gitignore", "!README.md", + "!nitro-node/**", ] workflow_dispatch: @@ -113,7 +115,7 @@ jobs: } # Get the latest release tag from GitHub API LATEST_TAG=$(get_latest_tag) - + # Remove the 'v' and append the build number to the version NEW_VERSION="${LATEST_TAG#v}-${GITHUB_RUN_NUMBER}" echo "New version: $NEW_VERSION" @@ -345,7 +347,7 @@ jobs: run: | ./install_deps.sh mkdir build && cd build - cmake -DWHISPER_COREML=1 -DNITRO_VERSION=${{ needs.set-nitro-version.outputs.version }} .. + cmake -DWHISPER_COREML=1 -DNITRO_VERSION=${{ needs.set-nitro-version.outputs.version }} .. CC=gcc-8 make -j $(sysctl -n hw.ncpu) ls -la @@ -423,7 +425,7 @@ jobs: run: | ./install_deps.sh mkdir build && cd build - cmake -DNITRO_VERSION=${{ needs.set-nitro-version.outputs.version }} -DLLAMA_METAL=OFF .. + cmake -DNITRO_VERSION=${{ needs.set-nitro-version.outputs.version }} -DLLAMA_METAL=OFF .. CC=gcc-8 make -j $(sysctl -n hw.ncp) ls -la @@ -499,7 +501,7 @@ jobs: # run: | # ./install_deps.sh # mkdir build && cd build - # cmake -DNITRO_VERSION=${{ needs.set-nitro-version.outputs.version }} -DLLAMA_VULKAN=ON -DLLAMA_METAL=OFF .. + # cmake -DNITRO_VERSION=${{ needs.set-nitro-version.outputs.version }} -DLLAMA_VULKAN=ON -DLLAMA_METAL=OFF .. # CC=gcc-8 make -j $(sysctl -n hw.ncp) # ls -la diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index c713f0f5d..6ada766ae 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -34,6 +34,8 @@ on: "!docs/**", "!.gitignore", "!README.md", + "!.github/scripts/nitro-node/**", + "!nitro-node/**", ] pull_request: types: [opened, synchronize, reopened] @@ -55,6 +57,8 @@ on: "!docs/**", "!.gitignore", "!README.md", + "!.github/scripts/nitro-node/**", + "!nitro-node/**", ] jobs: @@ -96,7 +100,7 @@ jobs: run: | ./install_deps.sh mkdir build && cd build - cmake .. + cmake .. CC=gcc-8 make -j $(sysctl -n hw.ncp) ls -la diff --git a/.github/workflows/test-install-nitro-node.yml b/.github/workflows/test-install-nitro-node.yml index de9abb29f..99211ab54 100644 --- a/.github/workflows/test-install-nitro-node.yml +++ b/.github/workflows/test-install-nitro-node.yml @@ -1,8 +1,8 @@ name: Test install nitro-node on: - #schedule: - # - cron: "0 20 * * *" # At 8 PM UTC, which is 3 AM UTC+7 + schedule: + - cron: "0 20 * * *" # At 0:20 UTC, which is 7:20 AM UTC+7 push: branches: - main @@ -50,8 +50,14 @@ jobs: path: nitro-node/janhq-nitro-node.tgz if-no-files-found: error - ubuntu-install: - runs-on: ubuntu-latest + install: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest needs: [linux-pack-tarball] if: always() && needs.linux-pack-tarball.result == 'success' steps: @@ -65,42 +71,10 @@ jobs: with: node-version: 18 - - name: Download prebuilt tarball - uses: actions/download-artifact@master - with: - name: janhq-nitro-node - path: .github/scripts/ - - - name: List tarball content - id: tar-tf + - name: Enable yarn run: | - cd .github - cd scripts - tar tf janhq-nitro-node.tgz - - - name: Run tests - id: test_install_nitro_node - env: - NITRO_NODE_PKG: ${{ github.workspace }}/.github/scripts/janhq-nitro-node.tgz - run: | - cd .github - cd scripts - node e2e-test-install-nitro-node.js - - macOS-install: - runs-on: macos-latest - needs: [linux-pack-tarball] - if: always() && needs.linux-pack-tarball.result == 'success' - steps: - - name: Clone - id: checkout - uses: actions/checkout@v4 - with: - submodules: recursive - - - uses: actions/setup-node@v4 - with: - node-version: 18 + corepack enable + corepack prepare yarn@1 --activate - name: Download prebuilt tarball uses: actions/download-artifact@master @@ -122,42 +96,5 @@ jobs: run: | cd .github cd scripts - node e2e-test-install-nitro-node.js - - windows-install: - runs-on: windows-latest - needs: [linux-pack-tarball] - if: always() && needs.linux-pack-tarball.result == 'success' - steps: - - name: Clone - - id: checkout - uses: actions/checkout@v4 - with: - submodules: recursive - - - uses: actions/setup-node@v4 - with: - node-version: 18 - - - name: Download prebuilt tarball - uses: actions/download-artifact@master - with: - name: janhq-nitro-node - path: .github/scripts/ - - - name: List tarball content - id: tar-tf - run: | - cd .github - cd scripts - tar tf janhq-nitro-node.tgz - - - name: Run tests - id: test_install_nitro_node - env: - NITRO_NODE_PKG: ${{ github.workspace }}\.github\scripts\janhq-nitro-node.tgz - run: | - cd .github - cd scripts + cd nitro-node node e2e-test-install-nitro-node.js diff --git a/nitro-node/Makefile b/nitro-node/Makefile index 6f67435ee..ca3a5b9d2 100644 --- a/nitro-node/Makefile +++ b/nitro-node/Makefile @@ -5,33 +5,33 @@ all: publish -# Installs yarn dependencies +# Installs npm dependencies #install: build-core install: ifeq ($(OS),Windows_NT) - yarn config set network-timeout 300000 + npm config set fetch-timeout 300000 endif - yarn install + npm install # Build build: install - yarn run build + npm run build # Download Nitro download-nitro: install - yarn run downloadnitro + npm run downloadnitro test-ci: install - yarn test + npm test # Note, this make target is just for testing on *NIX systems test: install @test -e test/test_assets/*.gguf && echo "test/test_assets/*.gguf is already downloaded" || (mkdir -p test/test_assets && cd test/test_assets/ && curl -JLO "https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf") - yarn test + npm test # Builds and pack pack: build - yarn run build:publish + npm run build:publish # Test that installation will also download nitro binaries test-e2e-installation: pack @@ -43,9 +43,9 @@ endif clean: ifeq ($(OS),Windows_NT) - powershell -Command "Remove-Item -Recurse -Force -Path *.tgz, .yarn, yarn.lock, package-lock.json, bin, dist" - powershell -Command "Get-ChildItem -Path . -Include node_modules -Recurse -Directory | Remove-Item -Recurse -Force" + powershell -Command "Get-ChildItem -Path . -Include *.tgz, package-lock.json -Recurse | Remove-Item -Recurse -Force" + powershell -Command "Get-ChildItem -Path . -Include node_modules, bin, dist -Recurse -Directory | Remove-Item -Recurse -Force" else - rm -rf *.tgz .yarn yarn.lock package-lock.json bin dist + rm -rf *.tgz package-lock.json bin dist find . -name "node_modules" -type d -prune -exec rm -rf '{}' + endif diff --git a/nitro-node/test/nitro-process.test.ts b/nitro-node/test/nitro-process.test.ts index cd2740c23..511009049 100644 --- a/nitro-node/test/nitro-process.test.ts +++ b/nitro-node/test/nitro-process.test.ts @@ -183,9 +183,8 @@ describe("Manage nitro process", () => { { messages: [ { - content: - "You are a good productivity assistant. You help user with what they are asking in Markdown format . For responses that contain code, you must use ``` with the appropriate coding language to help display the code to user correctly.", - role: "assistant", + content: "You are a good assistant.", + role: "system", }, { content: "Please give me a hello world code in cpp", @@ -203,12 +202,18 @@ describe("Manage nitro process", () => { }, new WritableStream({ write(chunk: string) { - const data = chunk.replace(/^\s*data:\s*/, "").trim(); - // Stop at [DONE] message - if (data.match(/\[DONE\]/)) { - return; + const parts = chunk + .split("\n") + .filter((p) => Boolean(p.trim().length)); + for (const part of parts) { + const data = part.replace(/^\s*data:\s*/, "").trim(); + // Stop at [DONE] message + if (data.match(/\[DONE\]/)) { + return; + } + // Parse the streamed content + streamedContent.push(JSON.parse(data)); } - streamedContent.push(JSON.parse(data)); }, //close() {}, //abort(_err) {}