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

iso-auto1111-api

v1.0.0

Published

auto1111 api wrapper that works the same node and browser

Downloads

30

Readme

iso-auto1111-api

This is an auto1111 api wrapper that works the same in node and in the browser.

I generally think everyone else puts too much library in their libraries, so this is my attempt at not doing that (xkcd_standards_comic.png). In comparison with the 4 other libraries already on NPM wrapping this API, this one has far fewer features and lines of code, runs on both client/server, and has a much greater focus on REPL ergonomics (when instantiated with the dev flag). If you're looking for batteries included type libaries these have like 6-11 batteries each minimum:

This is now just a simple wrapper for openapi-autowrapper because there was nothing auto1111 specific in this repo and I wanted to reuse the introspection/documentation code for my oobabooga api wrapper.

Changelog

1.0.0

endpoints no longer require or support POST.call(...) you can just use POST(...) directly

Usage

Install with NPM or just clone this repo, you'll also need to have auto1111 running somewhere with --api and probably also --cors-allow-origins * and --listen This uses fetch() so you'll also need an 18+ copy of node.

You can try running the script for an interactive demo.

node node_example.mjs

or use --inspect in order to play with the library in the debug tools

node --inspect node_example.mjs

this has the benefit of having a nice pretty-printing self-docs introspection tool in the REPL

image

or you can use http-server or similar to serve up the frontend in /client_example.html, which also supports the above in the console. The github pages version (TODO) can also be used if your cors is setup properly.

npm install -g http-server
http-server

>> *open localhost:8080/client_example.html in your browser*

or you can code against the api in node

import SD_API from '/SD_API.mjs'
let api = await SD_API() //SD_API() defaults to SD_API('http://localhost:7860')
let response = await api['/sdapi/v1/txt2img'].POST({prompt: 'an angel with a shotgun'}) //nightcore remix
///////
> response
> {
    images: ['iVBORw0KGgoAAAANSUhEUgA...'], // base64 encoded png by default, probably breaks if you generate jpgs?
    info: {prompt: 'an angel with a shotgun', all_prompts: Array(1), negative_prompt: '', all_negative_prompts: Array(1), seed: 1802462605, …},
    parameters: {enable_hr: false, denoising_strength: 0, firstphase_width: 0, firstphase_height: 0, hr_scale: 2, …}
}

or in the browser

import SD_API from '/SD_API.mjs'

let api = await SD_API() //SD_API() defaults to SD_API('http://localhost:7860')
let waifu = await api['/sdapi/v1/txt2img'].POST({prompt: 'a purple witch'}) //ask for a waifu
let img = new Image()
img.src = `data:image/png;base64,${waifu.images[0]}`

document.body.appendChild(img);

Additional Auto1111 API Documentation

For the most part you can get away with just introspecting on the schema using the command line tools, however, some things are a buit more complex and require actual documentation.

Secret Bonus Features

Since this uses the API's self documentation capabilities it actually works (kinda) against other gradio tools, (i've tested a bit with oobabooga). Just point at the right IP and mess around.

Caveats

  • untested
  • no support for auth
  • for the web example to work set --cors-allow-origins * when starting auto1111 and --listen if you want to access it on another computer.