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

📦 NEW: Config based env #38

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
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
78 changes: 78 additions & 0 deletions .github/scripts/release-snapshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* This script creates a snapshot release by performing the following steps:
* 1. Ensures the script is running from the project root directory.
* 2. Defines a function to execute shell commands and log their output.
* 3. Defines a function to update the version in a given package.json file.
* - If the current version is already a snapshot, it increments the snapshot number.
* - If the current version is not a snapshot, it increments the patch version and sets the snapshot number to 0.
* 4. Retrieves the current commit short SHA.
* 5. Bumps the version in the specified package.json files.
* 6. Runs a series of commands to version, build, and publish the packages as a snapshot release.
*
* @file /Users/ahmadawais/Documents/Sandbox/baseai/.github/scripts/create-snapshot.js
* @requires child_process
* @requires path
* @requires fs
*/
const {execSync} = require('child_process');
const path = require('path');
const fs = require('fs');

// Ensure we're in the project root
process.chdir(path.resolve(__dirname, '../..'));

// Function to execute commands and log output
function run(command) {
console.log(`Running: ${command}`);
try {
execSync(command, {stdio: 'inherit'});
} catch (error) {
console.error(`Error executing command: ${command}`);
console.error(error);
process.exit(1);
}
}

// Function to update version in package.json
function bumpVersion(packagePath) {
const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
const currentVersion = pkg.version;
let [major, minor, patch, snapshot] = currentVersion
.split(/[-.]/)
.map(v => (isNaN(parseInt(v)) ? v : parseInt(v)));

if (snapshot === 'snapshot') {
// If already a snapshot, increment the snapshot number
snapshot = parseInt(pkg.version.split('-snapshot.')[1]) + 1;
} else {
// If not a snapshot, increment patch and set snapshot to 0
patch += 1;
snapshot = 0;
}

pkg.version = `${major}.${minor}.${patch}-snapshot.${snapshot}`;
fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2));
console.log(`Updated ${packagePath} to version ${pkg.version}`);
}

// Get the current commit short SHA
const SHORT_SHA = execSync('git rev-parse --short HEAD').toString().trim();

console.log('Creating snapshot release...');

// Bump versions
bumpVersion('./packages/baseai/package.json');
bumpVersion('./packages/core/package.json');

// Version and tag the snapshot release
run(`pnpm changeset version --snapshot ${SHORT_SHA}`);

// Build and publish the snapshot release
run('pnpm build:pkgs');
run('pnpm changeset publish --no-git-tag --tag snapshot');

// Reset Git changes
console.log('Git commit and push changes...');
run('git add . && git commit -m "📦 NEW: snapshot release" && git push');

console.log('All changes have been reset. Snapshot release process complete!');
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ We welcome contributions to this project.

---

## Releasing a test snapshot

Run the following command to create a snapshot of the current changes, this must be done in a custom branch. If the current version is `1.0.0`, the snapshot will be `1.0.1-snapshot.0` and if done again `1.0.1-snapshot.1` and so on. This version will also be committed to the package.json file. And in the next normal release, the version will be `1.0.1` and the snapshot will be reset.

```bash
pnpm snapshot
```

```
## Releasing a new version

```bash
Expand Down
12 changes: 9 additions & 3 deletions examples/nodejs/baseai/pipes/summary.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {PipeI} from '@baseai/core';
import {config} from '../baseai.config';

const buildPipe = (): PipeI => ({
apiKey: process.env.LANGBASE_API_KEY!, // Replace with your API key https://langbase.com/docs/api-reference/api-keys
name: 'summary',
apiKey: config.env.langbase,
name: 'summary-nodejs',
description: '',
status: 'private',
model: 'openai:gpt-4o-mini',
Expand All @@ -18,7 +19,12 @@ const buildPipe = (): PipeI => ({
stop: [],
tool_choice: 'auto',
parallel_tool_calls: false,
messages: [{role: 'system', content: `You are a helpful AI assistant.`}],
messages: [
{
role: 'system',
content: `You are a helpful AI assistant. Make everything less wordy.`,
},
],
variables: [],
memory: [],
tools: [],
Expand Down
8 changes: 6 additions & 2 deletions examples/nodejs/examples/pipe.run.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'dotenv/config';
import {Pipe} from '@baseai/core';
import {config} from '../baseai/baseai.config';
import pipeSummary from '../baseai/pipes/summary';
import {Pipe} from './../../../packages/core/src/pipes/pipes';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be imported from core. This will break.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace it with
import {Pipe} from '@baseai/core';


const pipe = new Pipe(pipeSummary());
const pipe = new Pipe({
...pipeSummary(),
config,
});

async function main() {
const userMsg = 'Who is an AI Engineer?';
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"changeset": "changeset",
"publint": "turbo publint",
"type-check": "turbo type-check",
"version-packages": "changeset version && pnpm clean-examples && pnpm install --no-frozen-lockfile --filter=./packages/* --filter=./tools/* ",
"version-packages": "changeset version && pnpm clean-examples && pnpm install --no-frozen-lockfile --filter=./packages/* --filter=./tools/*",
"clean": "turbo clean",
"clean-all": "turbo clean && rm -rf node_modules",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
Expand All @@ -29,7 +29,7 @@
"clean-examples": "node .github/scripts/cleanup-examples-changesets.mjs",
"update-examples": "npx tsx .github/scripts/update-examples.ts",
"ci:version": "changeset version && node .github/scripts/cleanup-examples-changesets.mjs && pnpm install --no-frozen-lockfile",
"snapshot": "changeset --empty && changeset version --snapshot && changeset publish --no-git-tag --snapshot"
"snapshot": "node .github/scripts/release-snapshot.js"
},
"devDependencies": {
"@baseai/eslint-config": "workspace:*",
Expand Down
231 changes: 116 additions & 115 deletions packages/baseai/package.json
Original file line number Diff line number Diff line change
@@ -1,116 +1,117 @@
{
"name": "baseai",
"description": "The Web AI Framework Dev - BaseAI.dev",
"version": "0.9.7",
"license": "UNLICENSED",
"type": "module",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"bin": {
"baseai": "bin/baseai.js"
},
"author": {
"name": "Langbase",
"url": "https://BaseAI.dev"
},
"repository": {
"type": "git",
"url": "https://github.com/LangbaseInc/baseai.git",
"directory": "packages/cli"
},
"bugs": {
"url": "https://github.com/LangbaseInc/baseai/issues"
},
"homepage": "https://BaseAI.dev",
"files": [
"dist/**"
],
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"lint": "eslint \"src/**/*.ts*\"",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
"type-check": "tsc --noEmit",
"prettier-check": "prettier --check \"./**/*.ts*\"",
"test": "pnpm test:node && pnpm test:edge",
"#test": "pnpm test:node && pnpm test:edge && pnpm test:ui && pnpm test:e2e",
"test:edge": "vitest --config vitest.edge.config.js --run",
"test:node": "vitest --config vitest.node.config.js --run",
"test:ui": "pnpm test:ui:react",
"test:ui:react": "vitest --config vitest.ui.react.config.js --run",
"test:e2e": "playwright test",
"test:edge:watch": "vitest --config vitest.edge.config.js",
"test:node:watch": "vitest --config vitest.node.config.js",
"test:ui:react:watch": "vitest --config vitest.ui.react.config.js"
},
"dependencies": {
"@antfu/ni": "^0.23.0",
"@clack/core": "^0.3.4",
"@clack/prompts": "^0.7.0",
"@hono/node-server": "^1.13.1",
"@hono/zod-openapi": "^0.16.0",
"@sindresorhus/slugify": "^2.2.1",
"camelcase": "^8.0.0",
"chalk": "^5.3.0",
"cli-alerts": "^2.0.0",
"cli-handle-error": "^4.4.0",
"cli-handle-unhandled": "^1.1.1",
"cli-meow-help": "^4.0.0",
"cli-table3": "^0.6.5",
"cli-welcome": "^3.0.0",
"compute-cosine-similarity": "^1.1.0",
"conf": "^13.0.1",
"cosmiconfig": "^9.0.0",
"cosmiconfig-typescript-loader": "^5.0.0",
"dotenv": "^16.4.5",
"execa": "^9.4.0",
"figures": "^6.1.0",
"get-package-json-file": "^2.0.0",
"hono": "^4.5.11",
"js-tiktoken": "^1.0.14",
"log-symbols": "^7.0.0",
"lowdb": "^7.0.1",
"meow": "^13.2.0",
"node-fetch": "^3.3.2",
"open": "^10.1.0",
"openai": "^4.63.0",
"p-map": "^7.0.2",
"picocolors": "^1.1.0",
"prettier": "^3.3.3",
"source-map-support": "^0.5.21",
"unpdf": "^0.11.0",
"uuid": "^10.0.0",
"xlsx": "^0.18.5",
"zod": "^3.23.8",
"zod-error": "^1.5.0",
"zod-validation-error": "^3.4.0"
},
"devDependencies": {
"@baseai/eslint-config": "workspace:*",
"@baseai/tsconfig": "workspace:*",
"@types/node": "^22.6.1",
"tsup": "^8.3.0",
"tsx": "^4.19.1",
"typescript": "^5.6.2",
"vitest": "1.6.0"
},
"keywords": [
"baseai",
"base",
"base AI framework",
"BaseAI.dev",
"composable AI",
"AI agents",
"AI multi agents",
"ai",
"llm",
"langbase core",
"langbase sdk",
"baseai",
"base ai",
"langbase",
"langbase.com",
"generative AI"
]
}
"name": "baseai",
"description": "The Web AI Framework Dev - BaseAI.dev",
"version": "0.9.8-snapshot.3",
"license": "UNLICENSED",
"type": "module",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"bin": {
"baseai": "bin/baseai.js"
},
"author": {
"name": "Langbase",
"url": "https://BaseAI.dev"
},
"repository": {
"type": "git",
"url": "https://github.com/LangbaseInc/baseai.git",
"directory": "packages/cli"
},
"bugs": {
"url": "https://github.com/LangbaseInc/baseai/issues"
},
"homepage": "https://BaseAI.dev",
"files": [
"dist/**",
"bin/**"
],
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"lint": "eslint \"src/**/*.ts*\"",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
"type-check": "tsc --noEmit",
"prettier-check": "prettier --check \"./**/*.ts*\"",
"test": "pnpm test:node && pnpm test:edge",
"#test": "pnpm test:node && pnpm test:edge && pnpm test:ui && pnpm test:e2e",
"test:edge": "vitest --config vitest.edge.config.js --run",
"test:node": "vitest --config vitest.node.config.js --run",
"test:ui": "pnpm test:ui:react",
"test:ui:react": "vitest --config vitest.ui.react.config.js --run",
"test:e2e": "playwright test",
"test:edge:watch": "vitest --config vitest.edge.config.js",
"test:node:watch": "vitest --config vitest.node.config.js",
"test:ui:react:watch": "vitest --config vitest.ui.react.config.js"
},
"dependencies": {
"@antfu/ni": "^0.23.0",
"@clack/core": "^0.3.4",
"@clack/prompts": "^0.7.0",
"@hono/node-server": "^1.13.1",
"@hono/zod-openapi": "^0.16.0",
"@sindresorhus/slugify": "^2.2.1",
"camelcase": "^8.0.0",
"chalk": "^5.3.0",
"cli-alerts": "^2.0.0",
"cli-handle-error": "^4.4.0",
"cli-handle-unhandled": "^1.1.1",
"cli-meow-help": "^4.0.0",
"cli-table3": "^0.6.5",
"cli-welcome": "^3.0.0",
"compute-cosine-similarity": "^1.1.0",
"conf": "^13.0.1",
"cosmiconfig": "^9.0.0",
"cosmiconfig-typescript-loader": "^5.0.0",
"dotenv": "^16.4.5",
"execa": "^9.4.0",
"figures": "^6.1.0",
"get-package-json-file": "^2.0.0",
"hono": "^4.5.11",
"js-tiktoken": "^1.0.14",
"log-symbols": "^7.0.0",
"lowdb": "^7.0.1",
"meow": "^13.2.0",
"node-fetch": "^3.3.2",
"open": "^10.1.0",
"openai": "^4.63.0",
"p-map": "^7.0.2",
"picocolors": "^1.1.0",
"prettier": "^3.3.3",
"source-map-support": "^0.5.21",
"unpdf": "^0.11.0",
"uuid": "^10.0.0",
"xlsx": "^0.18.5",
"zod": "^3.23.8",
"zod-error": "^1.5.0",
"zod-validation-error": "^3.4.0"
},
"devDependencies": {
"@baseai/eslint-config": "workspace:*",
"@baseai/tsconfig": "workspace:*",
"@types/node": "^22.6.1",
"tsup": "^8.3.0",
"tsx": "^4.19.1",
"typescript": "^5.6.2",
"vitest": "1.6.0"
},
"keywords": [
"baseai",
"base",
"base AI framework",
"BaseAI.dev",
"composable AI",
"AI agents",
"AI multi agents",
"ai",
"llm",
"langbase core",
"langbase sdk",
"baseai",
"base ai",
"langbase",
"langbase.com",
"generative AI"
]
}
5 changes: 3 additions & 2 deletions packages/baseai/src/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,9 @@ async function createLocalPipe(pipe: Pipe) {
${toolData.map(tool => tool.importPath).join('\n')}

const ${pipeNameCamelCase} = (): PipeI => ({
// Replace with your API key https://langbase.com/docs/api-reference/api-keys
apiKey: process.env.LANGBASE_API_KEY!,
// Prod only: Replace with your Langbase API key
// https://langbase.com/docs/api-reference/api-keys
apiKey: process.env.LANGBASE_API_KEY,
name: \`${pipe.name}\`,
description: \`${pipe.description}\`,
status: \`${pipe.status}\`,
Expand Down
Loading