npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stability-rest

v0.0.1-beta.2

Published

Client for Stability.ai REST API

Downloads

17

Readme

Stability Rest Client

This is a rest client to interface with Stability.ai's API. As this requires an API key, server-side usage is recommended.

⚠️ This is a work in progress. Stability.ai Rest API is still in beta and is subject to change.

Installation

$ npm install stability-rest

Usage

Typescript

import {
  ClipGuidancePreset,
  GenerationSampler,
  StabilityClient,
  WellKnownEngine,
} from "stability-rest";
import * as fs from "fs";

const client = new StabilityClient(process.env.STABILITY_API_KEY);

client.generation
  .textToImagePng(
    WellKnownEngine["stable-diffusion-512-v2-1"],
    "a pale blue planet in the depth of the space",
    {
      width: 512,
      height: 512,
      cfg_scale: 7.0,
      sampler: GenerationSampler.K_EULER_ANCESTRAL,
      clip_guidance_preset: ClipGuidancePreset.FAST_BLUE,
      steps: 20,
      samples: 1,
      seed: 10,
    }
  )
  .then((response) => {
    fs.writeFileSync("out.png", response.data);
  });

Javascript

const {
  StabilityClient,
  WellKnownEngine,
  GenerationSampler,
  ClipGuidancePreset,
} = require("stability-rest");
const fs = require("fs");

const client = new StabilityClient(process.env.STABILITY_API_KEY);

client.generation
  .textToImagePng(
    WellKnownEngine["stable-diffusion-512-v2-1"],
    "a pale blue planet in the depth of the space",
    {
      width: 512,
      height: 512,
      seed: 123,
      cfg_scale: 7.0,
      sampler: GenerationSampler.K_EULER_ANCESTRAL,
      clip_guidance_preset: ClipGuidancePreset.FAST_BLUE,
      steps: 20,
      samples: 1,
    }
  )
  .then((response) => {
    fs.writeFileSync("out.png", response.data);
  });

API

This client maps 1-1 with the Stability API. For more information, please refer to the API documentation.

const client = new StabilityClient(process.env.STABILITY_API_KEY);

// UserResource
client.user.account(); // GET /user/account
client.user.balance(); // GET /user/balance

// EngineResource
client.engine.list(); // GET /engines/list

// GenerationResource
client.generation.textToImage(engineId, prompt, options); // POST /generation/:engineId/text-to-image

client.generation.textToImagePng(engineId, prompt, options); // POST /generation/:engineId/text-to-image - this one returns an arraybuffer.

Helpers

getArtifactBuffer(artifact)

Convert an artifact base64 string to a buffer.

WellKnownEngine

A list of well-known engines. This might be outdated as it is statically defined. You can also call StablityClient.engine.list() to get a list of all engines.

Contributing

Contributions are welcome! Please open an issue or PR. There are no guidelines yet, but please follow the existing code style.

TODO

List of things that need to be done:

  • [ ] Match v1.0.0 of the API once it is released.
  • [ ] Improve tests, checks for schema equality, etc.
  • [ ] Refactor, removing duplicates code.
  • [ ] Multiple prompts with different weights.
  • [ ] Prompt builder.

Environment Setup

  1. Clone the repo
  2. Install dependencies 3. Create a .env file with your API key. Set the key as STABILITY_API_KEY.
  3. Make contributions
  4. Run tests [1]
$ npm run test

Then create a PR once all the tests pass.

Important Notes on Tests 1

We do not mock the API calls in the tests. This is to ensure that the client is working as expected. However, this means that you need to have a valid API key to run the tests.

⚠️ Please do not use your production API key to run the tests. You can create a new API key in DreamStudio. Running the tests might consume your API quota.

License

MIT © Aditya Purwa