Skip to content

Commit

Permalink
feat(init): repo transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Pilar authored and Tomas Pilar committed Jun 8, 2023
0 parents commit fc6b1a7
Show file tree
Hide file tree
Showing 25 changed files with 3,960 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
env:
node: true
es2022: true
extends:
- "eslint:recommended"
- "plugin:import/recommended"
- "prettier"
plugins:
- import
parserOptions:
ecmaVersion: "latest"
sourceType: "module"
rules:
"import/order":
- error
- newlines-between: always
26 changes: 26 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
lint:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "yarn"
- run: yarn --frozen-lockfile
- run: yarn lint
20 changes: 20 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Publish on Release

on:
release:
types: [created]

jobs:
publish-npm:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- run: yarn install --frozen-lockfile
- run: yarn npm publish --access public
env:
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

.pnp.*
node_modules

# local env files
.env*.local
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
873 changes: 873 additions & 0 deletions .yarn/releases/yarn-3.5.0.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.5.0.cjs
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 International Business Machines

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<div align="center">

# Generative AI CLI

This project provides convenient access to the Generative AI API from from the command line. For a full description of the API, please visit the [Generative AI API Docs](https://workbench.res.ibm.com/docs/api-reference).

</div>

![-----------------------------------------------------](./assets/img/rainbow.png)

## Table of contents

- [Key Features](#key-features)
- [Installation](#installation)
- [Usage](#usage)

![-----------------------------------------------------](./assets/img/rainbow.png)

## Key features

- ⚡️ Performant - processes 1k of short inputs in about 4 minutes
- ☀️ Fault-tolerant - retry strategies and overflood protection
- 🏖️ Worry-free parallel processing - just pass all the data, we take care of the parallel processing
- 🚦 Handles concurrency limiting - even if you have multiple parallel jobs running
- ⏩ Requests are always returned in the respective order
- 📄 Work with files as your input or output
- ⌨️ Support stdin and stdout interaction
- 🕹️ Interactive context-free mode

![-----------------------------------------------------](./assets/img/rainbow.png)

### Installation

Install package globally using npm:

```bash
$ npm install @ibm-generative-ai/cli -g
```

### Usage

```bash
# Configure the CLI with your api key:
$ export GENAI_API_KEY=pak-...

# Run single generate request:
$ genai generate "Once upon a time there lived a rabbit"
# " called Edward. He lived well because he had some things to eat. He had a wife called Daisy"

# Run multiple generate requests from a file:
# "Best Christmas gift for dad: "
# "Best Christmas gift for mum: "
# "Best Christmas gift for dog: "
$ genai generate -f inputs.txt
# "a new wallet"
# "a day out"
# "a bone"

# Run tokenize request:
$ genai tokenize "This is a future."
# {"token_count":5,"tokens":["This", "is", "a", "future", "."]}

# Retrieve generate config
$ genai generate config
# model_id: google/flan-ul2,
# parameters:
# max_new_tokens: 1,
# decoding_method: greedy
#

# Update generate config
$ genai generate config -m google/flan-ul2 --decoding-method greedy --max-new-tokens 5 --min-new-tokens 1

# Enter interactive mode
$ genai generate interactive

# List models
$ genai models list
# google/flan-t5-xxl
# google/flan-ul2
# ...

# Show model details
$ genai models info google/flan-ul2
# id: google/flan-ul2
# name: flan-ul2 (20B)
# size: 20B
# description: >-
# flan-ul2 (20B) is an encoder decoder model ...
```
Binary file added assets/img/rainbow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

set -e

echo -n "Checking Node installation ... "
if ! command -v node &> /dev/null
then
echo "Node runtime hasn't been detected, installing via nvm"
if command -v curl &> /dev/null
then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
elif command -v wget &> /dev/null
then
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
else
echo "Neither curl nor wget command is present, unable to proceed"
exit 1
fi
else
echo "Node detected"
fi

echo "Installing the command ..."
npm install -g @ibm-generative-ai/cli

echo -n "Checking the command version ... "
if ! command bam --version
then
echo "Failure, make sure your PATH is set up correctly"
fi
54 changes: 54 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@ibm-generative-ai/cli",
"version": "1.0.0",
"description": "CLI for IBM Generative AI",
"keywords": [
"ai",
"generative",
"genai",
"ibm",
"cli"
],
"homepage": "https://workbench.res.ibm.com",
"license": "MIT",
"repository": "https://github.com/IBM/ibm-generative-ai-cli.git",
"type": "module",
"bin": {
"genai": "./src/cli.js"
},
"files": [
"src/**/*"
],
"scripts": {
"start": "./src/cli.js",
"lint": "eslint",
"prepare": "husky install"
},
"packageManager": "yarn@3.5.0",
"engines": {
"node": ">=16.10.0"
},
"lint-staged": {
"*.js": [
"prettier --write",
"eslint --fix"
],
"*.md": [
"prettier --write"
]
},
"dependencies": {
"@ibm-generative-ai/node-sdk": "^1.1.0",
"lodash": "^4.17.21",
"stream-json": "^1.7.5",
"yaml": "^2.3.0",
"yargs": "^17.7.2"
},
"devDependencies": {
"eslint": "^8.40.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"husky": "^8.0.0",
"prettier": "^2.8.8"
}
}
14 changes: 14 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env node

import { parser } from "./parser.js";
import { isUsageError } from "./errors.js";

try {
await parser.parse();
} catch (err) {
if (isUsageError(err)) {
parser.showHelp();
}
console.error(err.message || "Something went wrong");
parser.exit(1);
}
4 changes: 4 additions & 0 deletions src/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { BaseError, InvalidInputError } from "@ibm-generative-ai/node-sdk";

export const isUsageError = (err) =>
!(err instanceof BaseError) || err instanceof InvalidInputError;
13 changes: 13 additions & 0 deletions src/middleware/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Client, version } from "@ibm-generative-ai/node-sdk";

export const clientMiddleware = (args) => {
const agent = version ? `node-cli/${version}` : "node-cli";
args.client = new Client({
apiKey: args.apiKey,
endpoint: args.endpoint,
headers: {
"User-Agent": agent,
"X-Request-Origin": agent,
},
});
};
Loading

0 comments on commit fc6b1a7

Please sign in to comment.