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

*: add multi-version node test matrix #22

Merged
merged 4 commits into from
Jan 4, 2025
Merged
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
23 changes: 22 additions & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

- uses: denoland/setup-deno@v1
with:
deno-version: v2.x
deno-version: vx.x.x

- run: deno fmt --check

Expand All @@ -20,3 +20,24 @@ jobs:
- run: deno test --allow-env --allow-net
env:
PRODIA_TOKEN: ${{ secrets.PRODIA_TOKEN }}

node-test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18, 20, 22]

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- run: npm run prepublish

- run: node example.mjs
env:
PRODIA_TOKEN: ${{ secrets.PRODIA_TOKEN }}
32 changes: 32 additions & 0 deletions example.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createProdia } from "./dist/v2/index.js";
import { strictEqual } from "assert";

const token = process.env.PRODIA_TOKEN;

if (typeof token !== "string") {
throw new Error("PRODIA_TOKEN is not set");
}

const isJpeg = (image) => {
const view = new Uint8Array(image);

return view[0] === 0xff && view[1] === 0xd8;
};

const client = createProdia({
token,
});

const job = await client.job({
type: "inference.flux.dev.txt2img.v1",
config: {
prompt: "puppies in a cloud, 4k",
steps: 1,
width: 1024,
height: 1024,
},
});

const image = await job.arrayBuffer();

strictEqual(isJpeg(image), true, "Image should be a JPEG");
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
},
"author": "Monty Anderson <[email protected]>",
"license": "ISC",
"engines": {
"node": ">=18.0.0"
},
"devDependencies": {
"prettier": "^3.0.0",
"typescript": "^5.1.6"
Expand Down
8 changes: 1 addition & 7 deletions v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,7 @@ export const createProdia = ({
);
}

const buffer = await new Promise<ArrayBuffer>((resolve, reject) => {
const output = body.get("output") as File;
const reader = new FileReader();
reader.readAsArrayBuffer(output);
reader.onload = () => resolve(reader.result as ArrayBuffer);
reader.onerror = () => reject(new Error("Failed to read output"));
});
const buffer = await (body.get("output") as Blob).arrayBuffer();

return {
job: job,
Expand Down
Loading