-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: E2E Examples | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
paths-ignore: | ||
- "**/*.md" | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test: | ||
name: Tests | ||
timeout-minutes: 40 | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node-version: [18.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: Install ollama | ||
run: curl -fsSL https://ollama.com/install.sh | sh | ||
- name: Run ollama | ||
run: | | ||
ollama serve & | ||
ollama pull llama3.1 | ||
- name: Call ollama API | ||
run: | | ||
curl -d '{"model": "llama3.1:latest", "stream": false, "prompt":"Whatever I say, asnwer with Yes"}' http://localhost:11434/api/generate | ||
- name: Example 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:examples |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { defineConfig } from "vitest/config"; | ||
import tsConfigPaths from "vite-tsconfig-paths"; | ||
import packageJson from "../package.json"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
globals: true, | ||
passWithNoTests: true, | ||
testTimeout: 120 * 1000, | ||
printConsoleTrace: true, | ||
setupFiles: ["./tests/setup.examples.ts"], | ||
deps: { | ||
interopDefault: false, | ||
}, | ||
maxConcurrency: 10, | ||
}, | ||
define: { | ||
__LIBRARY_VERSION: JSON.stringify(packageJson.version), | ||
}, | ||
plugins: [ | ||
tsConfigPaths({ | ||
projects: ["tsconfig.json"], | ||
}), | ||
], | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* Copyright 2024 IBM Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { expect } from "vitest"; | ||
import { exec } from "child_process"; | ||
import { glob } from "glob"; | ||
import { promisify } from "util"; | ||
import { isTruthy } from "remeda"; | ||
import { hasEnv } from "@/internals/env.js"; | ||
|
||
const execAsync = promisify(exec); | ||
const includePattern = process.env.INCLUDE_PATTERN || `./examples/**/*.ts`; | ||
const excludePattern = process.env.EXCLUDE_PATTERN || ``; | ||
|
||
const exclude: string[] = [ | ||
!hasEnv("WATSONX_API_KEY") && [ | ||
"examples/llms/text.ts", | ||
"examples/llms/providers/watsonx_verbose.ts", | ||
"examples/llms/providers/watsonx.ts", | ||
], | ||
!hasEnv("GROQ_API_KEY") && ["examples/agents/sql.ts", "examples/llms/providers/groq.ts"], | ||
!hasEnv("OPENAI_API_KEY") && ["agents/bee_reusable.ts", "examples/llms/providers/openai.ts"], | ||
!hasEnv("IBM_VLLM_URL") && ["examples/llms/providers/ibm-vllm.ts"], | ||
!hasEnv("COHERE_API_KEY") && ["examples/llms/providers/langchain.ts"], | ||
["examples/llms/providers/bam.ts", "examples/llms/providers/bam_verbose.ts"], | ||
] | ||
.filter(isTruthy) | ||
.flat(); // list of examples that are excluded | ||
|
||
describe("E2E Examples", async () => { | ||
const exampleFiles = await glob(includePattern, { | ||
cwd: process.cwd(), | ||
dot: false, | ||
realpath: true, | ||
ignore: [exclude, excludePattern].flat(), | ||
}); | ||
|
||
for (const example of exampleFiles) { | ||
it.concurrent(`Run ${example}`, async () => { | ||
await execAsync(`yarn start -- ${example} <<< "Hello world"`) | ||
.then((stdout) => { | ||
// eslint-disable-next-line no-console | ||
console.log({ | ||
path: example, | ||
result: stdout.stdout, | ||
error: stdout.stderr, | ||
}); | ||
expect(stdout.stderr).toBeFalsy(); | ||
}) | ||
.catch((error) => { | ||
// eslint-disable-next-line no-console | ||
console.log({ | ||
path: example, | ||
errorCode: error.code, | ||
}); | ||
expect(error.code).toBe(0); | ||
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/vitest.examples.config.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/version.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/tools/langchain.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/tools/base.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/tools/agent.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/tools/advanced.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/templates/primitives.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/templates/objects.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/templates/functions.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/templates/forking.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/vitest.examples.config.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/version.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/tools/langchain.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/tools/base.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/tools/agent.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/tools/advanced.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/templates/primitives.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/templates/objects.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/templates/functions.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (18.x)tests/examples/examples.test.ts > E2E Examples > Run examples/templates/forking.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (20.x)tests/examples/examples.test.ts > E2E Examples > Run examples/vitest.examples.config.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (20.x)tests/examples/examples.test.ts > E2E Examples > Run examples/version.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (20.x)tests/examples/examples.test.ts > E2E Examples > Run examples/tools/langchain.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (20.x)tests/examples/examples.test.ts > E2E Examples > Run examples/tools/base.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (20.x)tests/examples/examples.test.ts > E2E Examples > Run examples/tools/agent.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (20.x)tests/examples/examples.test.ts > E2E Examples > Run examples/tools/advanced.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (20.x)tests/examples/examples.test.ts > E2E Examples > Run examples/templates/primitives.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (20.x)tests/examples/examples.test.ts > E2E Examples > Run examples/templates/objects.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (20.x)tests/examples/examples.test.ts > E2E Examples > Run examples/templates/functions.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (20.x)tests/examples/examples.test.ts > E2E Examples > Run examples/templates/forking.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (22.x)tests/examples/examples.test.ts > E2E Examples > Run examples/vitest.examples.config.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (22.x)tests/examples/examples.test.ts > E2E Examples > Run examples/version.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (22.x)tests/examples/examples.test.ts > E2E Examples > Run examples/tools/langchain.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (22.x)tests/examples/examples.test.ts > E2E Examples > Run examples/tools/base.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (22.x)tests/examples/examples.test.ts > E2E Examples > Run examples/tools/agent.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (22.x)tests/examples/examples.test.ts > E2E Examples > Run examples/tools/advanced.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (22.x)tests/examples/examples.test.ts > E2E Examples > Run examples/templates/primitives.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (22.x)tests/examples/examples.test.ts > E2E Examples > Run examples/templates/objects.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (22.x)tests/examples/examples.test.ts > E2E Examples > Run examples/templates/functions.ts
Check failure on line 69 in tests/examples/examples.test.ts GitHub Actions / Tests (22.x)tests/examples/examples.test.ts > E2E Examples > Run examples/templates/forking.ts
|
||
}); | ||
}); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright 2024 IBM Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import dotenv from "dotenv"; | ||
import { FrameworkError } from "@/errors.js"; | ||
dotenv.config(); | ||
dotenv.config({ | ||
path: ".env.test", | ||
override: true, | ||
}); | ||
dotenv.config({ | ||
path: ".env.test.local", | ||
override: true, | ||
}); | ||
|
||
expect.addSnapshotSerializer({ | ||
serialize(val: FrameworkError): string { | ||
return val.explain(); | ||
}, | ||
test(val): boolean { | ||
return val && val instanceof FrameworkError; | ||
}, | ||
}); |