Skip to content

Commit

Permalink
fix(misc): SDK upgrade, docs (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Pilar <tomas.pilar@ibm.com>
  • Loading branch information
pilartomas authored Mar 18, 2024
1 parent 2ac57af commit 1b110e5
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 67 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "yarn"
Expand All @@ -31,9 +31,9 @@ jobs:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "yarn"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
registry-url: https://registry.npmjs.org/
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,19 @@ source ~/.zshrc

### Output format

You can choose default output format during `genai config` or set it via `--output-format` flag. Choices are `yaml` and `json`. Former is ideal for direct viewing, latter for piping into [jq](https://jqlang.github.io/jq/).
You can choose default output format during `genai config` or set it via `--output-format` flag. Choices are `json` and `yaml`. Former can be piped into [jq](https://jqlang.github.io/jq/) for further processing. Default is `json`.

### Many inputs

Certain commands (e.g. `text generation create` or `text tokenization create`) accept inputs from `stdin` if positional arguments are omitted. The content of `stdin` MUST follow [JSONL](https://jsonlines.org/) format.

```bash
cat inputs.jsonl
# "foo"
# "bar"
# "baz"
cat inputs.jsonl moreInputs.jsonl | genai text generation create -m google/flan-ul2 | jq '.results[0].generated_text'
```

## Commands

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ibm-generative-ai/cli",
"version": "2.0.1",
"version": "2.0.2",
"description": "CLI for IBM Generative AI (Tech Preview)",
"keywords": [
"ai",
Expand Down Expand Up @@ -44,7 +44,7 @@
]
},
"dependencies": {
"@ibm-generative-ai/node-sdk": "^2.0.0",
"@ibm-generative-ai/node-sdk": "^2.0.2",
"dayjs": "^1.11.9",
"lodash": "^4.17.21",
"stream-json": "^1.7.5",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions src/commands/file/read.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { stdout } from "node:process";
import { pipeline } from "node:stream/promises";
import { Readable } from "node:stream";

export const readCommandDefinition = [
"read <id>",
"Read file contents",
(yargs) =>
yargs.positional("id", {
type: "string",
description: "Identifier of the file to read",
}),
async (args) => {
const blob = await args.client.file.read(
{
id: args.id,
},
{ signal: args.timeout }
);
const readable = Readable.fromWeb(blob.stream());
await pipeline(readable, stdout);
},
];
File renamed without changes.
39 changes: 0 additions & 39 deletions src/commands/files/read.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 9 additions & 2 deletions src/errors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { BaseError, InvalidInputError } from "@ibm-generative-ai/node-sdk";
import {
BaseError,
InvalidInputError as InvalidInputSDKError,
} from "@ibm-generative-ai/node-sdk";

export class InvalidInputError extends Error {}

export const isUsageError = (err) =>
!(err instanceof BaseError) || err instanceof InvalidInputError;
!(err instanceof BaseError) ||
err instanceof InvalidInputSDKError ||
err instanceof InvalidInputError;
4 changes: 2 additions & 2 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { hideBin } from "yargs/helpers";

import { profileMiddleware } from "./middleware/profile.js";
import { textCommandDefinition } from "./commands/text/index.js";
import { modelsCommandDefinition } from "./commands/models/index.js";
import { filesCommandDefinition } from "./commands/files/index.js";
import { modelsCommandDefinition } from "./commands/model/index.js";
import { filesCommandDefinition } from "./commands/file/index.js";
import { requestCommandDefinition } from "./commands/request/index.js";
import { tuneCommandDefinition } from "./commands/tune/index.js";
import { configCommandDefinition } from "./commands/config/index.js";
Expand Down
2 changes: 1 addition & 1 deletion src/utils/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function format(data, format) {
if (!isValidFormat(format)) new Error("Invalid format");
switch (format) {
case "json":
return JSON.stringify(data);
return JSON.stringify(data, null, 2);
case "yaml":
return YAML.stringify(data);
}
Expand Down
27 changes: 18 additions & 9 deletions src/utils/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@ import { pipeline } from "stream/promises";
import Parser from "stream-json/Parser.js";
import StreamValues from "stream-json/streamers/StreamValues.js";

import { InvalidInputError } from "../errors.js";

export const readJSONStream = async (stream) => {
const values = [];
await pipeline(
stream,
new Parser({ jsonStreaming: true }),
new StreamValues(),
async function (source) {
for await (const value of source) {
values.push(value.value);
try {
await pipeline(
stream,
new Parser({ jsonStreaming: true }),
new StreamValues(),
async function (source) {
for await (const value of source) {
values.push(value.value);
}
}
}
);
);
} catch (err) {
throw new InvalidInputError(
"Failed to parse JSON stream, please check your input",
{ cause: err }
);
}
return values;
};
18 changes: 13 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@ibm-generative-ai/cli@workspace:."
dependencies:
"@ibm-generative-ai/node-sdk": ^2.0.0
"@ibm-generative-ai/node-sdk": ^2.0.2
dayjs: ^1.11.9
eslint: ^8.56.0
eslint-config-prettier: ^8.8.0
Expand All @@ -109,18 +109,19 @@ __metadata:
languageName: unknown
linkType: soft

"@ibm-generative-ai/node-sdk@npm:^2.0.0":
version: 2.0.0
resolution: "@ibm-generative-ai/node-sdk@npm:2.0.0"
"@ibm-generative-ai/node-sdk@npm:^2.0.2":
version: 2.0.2
resolution: "@ibm-generative-ai/node-sdk@npm:2.0.2"
dependencies:
"@ai-zen/node-fetch-event-source": ^2.1.2
fetch-retry: ^5.0.6
http-status-codes: ^2.3.0
openapi-fetch: ^0.8.2
p-queue: ^8.0.1
yaml: ^2.3.3
peerDependencies:
"@langchain/core": ">=0.1.0"
checksum: 70064b43855ddc5923f71d7e2b17d9421b06b4a99b1d6c11e11c590d5d9cf419094a1406326ab4b2f5858b95bbf8e5f69d73a98d769cb5c1bbd5d3766dc7e5ec
checksum: 0dc17c082764b162234785f6b1f476feb895b7d42c1d063a20bb0ac3d6c94e8be23b8e93fd3ce02f285061082716f57bb69fb33f7b8d95720767cb4d6746f16a
languageName: node
linkType: hard

Expand Down Expand Up @@ -1049,6 +1050,13 @@ __metadata:
languageName: node
linkType: hard

"http-status-codes@npm:^2.3.0":
version: 2.3.0
resolution: "http-status-codes@npm:2.3.0"
checksum: dae3b99e0155441b6df28e8265ff27c56a45f82c6092f736414233e9ccf063d5ea93c1e1279e8b499c4642e2538b37995c76b1640ed3f615d0e2883d3a1dcfd5
languageName: node
linkType: hard

"husky@npm:^8.0.0":
version: 8.0.3
resolution: "husky@npm:8.0.3"
Expand Down

0 comments on commit 1b110e5

Please sign in to comment.