From dba7ad72cda62e9bcacf05d4cc269384257fefb1 Mon Sep 17 00:00:00 2001 From: Tomas Dvorak Date: Wed, 28 Aug 2024 15:12:18 +0200 Subject: [PATCH] ci: setup github action --- .github/workflows/main.yml | 72 +++++++++++++++++++++++++ commitlint.config.ts | 5 ++ src/adapters/langchain/llms/llm.test.ts | 9 ++++ src/memory/tokenMemory.test.ts | 1 + src/serializer/serializer.test.ts | 4 +- tests/e2e/agents/bee.test.ts | 2 +- 6 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..85779a76 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,72 @@ +name: CI + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + lint: + timeout-minutes: 20 + name: Lint & Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Enable Corepack + run: corepack enable + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version-file: ".nvmrc" + cache: "yarn" + - name: Install dependencies + run: yarn install --immutable + - name: Code Lint + run: yarn lint + - name: Commits Lint + run: yarn commitlint --verbose --from "${{ github.event.pull_request.base.sha || github.event.commits[0].id }}" --to "${{ github.event.pull_request.head.sha || github.event.head_commit.id }}" + - name: Build + run: yarn build + + test: + name: Tests + timeout-minutes: 20 + needs: + - lint + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + node-version: [18.x, 20.x, 22.x] + + steps: + - uses: actions/checkout@v4 + - name: Enable Corepack + run: corepack enable + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: "yarn" + - name: Install dependencies + run: yarn install --immutable + - name: Unit Tests + run: yarn test:unit + - name: E2E Tests + env: + GENAI_API_KEY: ${{ secrets.GENAI_API_KEY }} + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + # TODO: enable WatsonX later + # WATSONX_API_KEY: ${{ secrets.WATSONX_API_KEY }} + # WATSONX_PROJECT_ID: ${{ secrets.WATSONX_PROJECT_ID }} + # WATSONX_SPACE_ID: ${{ secrets.WATSONX_SPACE_ID }} + # WATSONX_DEPLOYMENT_ID: ${{ secrets.WATSONX_DEPLOYMENT_ID }} + run: yarn test:e2e diff --git a/commitlint.config.ts b/commitlint.config.ts index f3e83083..4bc92528 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -2,6 +2,11 @@ import type { UserConfig } from "@commitlint/types"; const Configuration: UserConfig = { extends: ["@commitlint/config-conventional"], + ignores: [ + function ignoreDependabot(commit: string) { + return commit.includes("") && commit.includes("dependabot"); + }, + ], }; export default Configuration; diff --git a/src/adapters/langchain/llms/llm.test.ts b/src/adapters/langchain/llms/llm.test.ts index cc2309bb..e916a755 100644 --- a/src/adapters/langchain/llms/llm.test.ts +++ b/src/adapters/langchain/llms/llm.test.ts @@ -18,8 +18,17 @@ import { verifyDeserialization } from "@tests/e2e/utils.js"; import { LangChainLLM } from "@/adapters/langchain/llms/llm.js"; import { GenAIModel } from "@ibm-generative-ai/node-sdk/langchain"; import { Client } from "@ibm-generative-ai/node-sdk"; +import { afterAll, beforeAll, vi } from "vitest"; describe("Langchain LLM", () => { + beforeAll(() => { + vi.stubEnv("GENAI_API_KEY", "123"); + }); + + afterAll(() => { + vi.unstubAllEnvs(); + }); + const getInstance = () => { return new LangChainLLM( new GenAIModel({ diff --git a/src/memory/tokenMemory.test.ts b/src/memory/tokenMemory.test.ts index fc242df2..96896eeb 100644 --- a/src/memory/tokenMemory.test.ts +++ b/src/memory/tokenMemory.test.ts @@ -46,6 +46,7 @@ describe("Token Memory", () => { }; it("Serializes", async () => { + vi.stubEnv("GENAI_API_KEY", "123"); const instance = getInstance(); await instance.add( BaseMessage.of({ diff --git a/src/serializer/serializer.test.ts b/src/serializer/serializer.test.ts index a5442587..eaa5912e 100644 --- a/src/serializer/serializer.test.ts +++ b/src/serializer/serializer.test.ts @@ -19,7 +19,7 @@ import * as R from "remeda"; import { FrameworkError } from "@/errors.js"; import { AgentError } from "@/agents/base.js"; import { BaseMessage } from "@/llms/primitives/message.js"; -import { beforeEach, expect } from "vitest"; +import { beforeEach, expect, vi } from "vitest"; import { verifyDeserialization } from "@tests/e2e/utils.js"; import { BAMLLM } from "@/adapters/bam/llm.js"; import { BAMChatLLM } from "@/adapters/bam/chat.js"; @@ -231,6 +231,7 @@ describe("Serializer", () => { }); beforeEach(() => { + vi.unstubAllEnvs(); Serializer.deregister(BaseMessage); }); @@ -264,6 +265,7 @@ describe("Serializer", () => { }); it("Handles nested functions", () => { + vi.stubEnv("GENAI_API_KEY", "123"); const { data } = JSON.parse( `{"kind":"token","data":"{\\"__version\\":\\"0.0.35\\",\\"__root\\":{\\"__serializer\\":true,\\"__class\\":\\"Object\\",\\"__ref\\":\\"18\\",\\"__value\\":{\\"tokensUsed\\":{\\"__serializer\\":true,\\"__class\\":\\"Number\\",\\"__ref\\":\\"19\\",\\"__value\\":\\"66\\"},\\"config\\":{\\"__serializer\\":true,\\"__class\\":\\"Object\\",\\"__ref\\":\\"9\\",\\"__value\\":{\\"maxTokens\\":{\\"__serializer\\":true,\\"__class\\":\\"Number\\",\\"__ref\\":\\"10\\",\\"__value\\":\\"7000\\"},\\"llm\\":{\\"__serializer\\":true,\\"__class\\":\\"BAMChatLLM\\",\\"__ref\\":\\"3\\",\\"__value\\":{\\"llm\\":{\\"__serializer\\":true,\\"__class\\":\\"BAMLLM\\",\\"__ref\\":\\"4\\",\\"__value\\":{\\"modelId\\":\\"qwen/qwen2-72b-instruct\\",\\"parameters\\":{\\"__serializer\\":true,\\"__class\\":\\"Object\\",\\"__ref\\":\\"5\\",\\"__value\\":{}},\\"executionOptions\\":{\\"__serializer\\":true,\\"__class\\":\\"Object\\",\\"__ref\\":\\"6\\",\\"__value\\":{}}}},\\"config\\":{\\"__serializer\\":true,\\"__class\\":\\"Object\\",\\"__ref\\":\\"7\\",\\"__value\\":{\\"messagesToPrompt\\":{\\"__serializer\\":true,\\"__class\\":\\"Function\\",\\"__ref\\":\\"8\\",\\"__value\\":{\\"name\\":\\"messagesToPrompt\\",\\"fn\\":\\"messagesToPrompt(messages){return llamaTemplate.render({messages:messages.map(message=>({system:message.role===\\\\\\"system\\\\\\"?[message.text]:[],user:message.role===\\\\\\"user\\\\\\"?[message.text]:[],assistant:message.role===\\\\\\"assistant\\\\\\"?[message.text]:[]}))})}\\"}}}}}}}},\\"messages\\":{\\"__serializer\\":true,\\"__class\\":\\"Array\\",\\"__ref\\":\\"11\\",\\"__value\\":[{\\"__serializer\\":true,\\"__class\\":\\"BaseMessage\\",\\"__ref\\":\\"12\\",\\"__value\\":{\\"role\\":\\"user\\",\\"text\\":\\"My name is Tom, what is my name?\\",\\"meta\\":{\\"__serializer\\":true,\\"__class\\":\\"Undefined\\",\\"__ref\\":\\"13\\"}}},{\\"__serializer\\":true,\\"__class\\":\\"BaseMessage\\",\\"__ref\\":\\"14\\",\\"__value\\":{\\"role\\":\\"assistant\\",\\"text\\":\\"Your name is Tom.\\",\\"meta\\":{\\"__serializer\\":true,\\"__class\\":\\"Undefined\\",\\"__ref\\":\\"15\\"}}},{\\"__serializer\\":true,\\"__class\\":\\"BaseMessage\\",\\"__ref\\":\\"16\\",\\"__value\\":{\\"role\\":\\"user\\",\\"text\\":\\"My name is Tom, what is my name?\\",\\"meta\\":{\\"__serializer\\":true,\\"__class\\":\\"Undefined\\",\\"__ref\\":\\"17\\"}}},{\\"__serializer\\":true,\\"__class\\":\\"BaseMessage\\",\\"__ref\\":\\"14\\",\\"__value\\":\\"__ref\\"}]}}}}"}`, ); diff --git a/tests/e2e/agents/bee.test.ts b/tests/e2e/agents/bee.test.ts index a23b1a29..ab086bf4 100644 --- a/tests/e2e/agents/bee.test.ts +++ b/tests/e2e/agents/bee.test.ts @@ -94,7 +94,7 @@ describe("Bee Agent", () => { { prompt: "Who is the president of Czech Republic?" }, { execution: { - maxIterations: 3, + maxIterations: 5, totalMaxRetries: 5, }, },