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

feat(): babel #5

Merged
merged 3 commits into from
Sep 2, 2022
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
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/typescript", ["@babel/env", { "modules": false }]]
}
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "stability-ts",
"version": "1.1.1",
"version": "1.2.0",
"description": "A TypeScript client for the Stability AI SDK",
"main": "./build/index.js",
"scripts": {
"start": "node ./build/index.js",
"prebuild": "yarn clean",
"build": "webpack",
"postbuild": "tsc -b .",
"clean": "rimraf ./build",
"format": "prettier --write .",
"lint": "eslint . --fix --ext .ts,.tsx --max-warnings 0"
Expand All @@ -18,14 +19,17 @@
"author": "Jacob Kelley <jakie8@gmail.com>",
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.18.13",
"@babel/preset-env": "^7.18.10",
"@babel/preset-typescript": "^7.18.6",
"@types/google-protobuf": "^3.15.6",
"@types/mime": "^3.0.1",
"@types/mkdirp": "^1.0.2",
"@types/node": "^18.6.5",
"@types/uuid4": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"stability-sdk": "Stability-AI/stability-sdk",
"babel-loader": "^8.2.5",
"buffer": "^6.0.3",
"eslint": "^8.10.0",
"eslint-config-airbnb": "^19.0.4",
Expand All @@ -38,6 +42,8 @@
"prettier": "^2.7.1",
"process": "^0.11.10",
"rimraf": "^3.0.2",
"source-map-loader": "^4.0.0",
"stability-sdk": "Stability-AI/stability-sdk",
"ts-loader": "^9.3.1",
"typescript": "^4.8.2",
"webpack": "^5.74.0",
Expand Down
3 changes: 2 additions & 1 deletion src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import * as dotenv from 'dotenv'
dotenv.config()
import { Command, Option, InvalidArgumentError } from 'commander'
import { sync as readPackageUpSync } from 'read-pkg-up'
import { generate, diffusionMap, range } from './index'
import { generate } from './index'
import { diffusionMap, range } from './utils'

const res = readPackageUpSync({
cwd: __dirname,
Expand Down
18 changes: 2 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
ImageParameters,
SamplerParameters,
TransformType,
DiffusionSampler,
StepParameter,
ClassifierParameters,
Answer,
Expand All @@ -18,23 +17,10 @@ import mime from 'mime'
import fs from 'fs'
import path from 'path'
import mkdirp from 'mkdirp'

import { EventEmitter } from 'events'
import TypedEmitter from 'typed-emitter'

export const range = (min: number, max: number) =>
Math.floor(Math.random() * (max - min + 1)) + min

export const diffusionMap = {
ddim: DiffusionSampler.SAMPLER_DDIM,
plms: DiffusionSampler.SAMPLER_DDPM,
k_euler: DiffusionSampler.SAMPLER_K_EULER,
k_euler_ancestral: DiffusionSampler.SAMPLER_K_EULER_ANCESTRAL,
k_heun: DiffusionSampler.SAMPLER_K_HEUN,
k_dpm_2: DiffusionSampler.SAMPLER_K_DPM_2,
k_dpm_2_ancestral: DiffusionSampler.SAMPLER_K_DPM_2_ANCESTRAL,
k_lms: DiffusionSampler.SAMPLER_K_LMS,
}
import { diffusionMap, range } from './utils'

type DraftStabilityOptions = Partial<{
outDir: string
Expand Down Expand Up @@ -71,7 +57,7 @@ type StabilityApi = TypedEmitter<{
}) => void
}>

export const withDefaults: (
const withDefaults: (
draftOptions: DraftStabilityOptions & RequiredStabilityOptions
) => StabilityOptions = (draft) => {
if (!draft.prompt) throw new Error('Prompt is required')
Expand Down
15 changes: 15 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { DiffusionSampler } from 'stability-sdk/src/js/generation_pb'

export const range = (min: number, max: number) =>
Math.floor(Math.random() * (max - min + 1)) + min

export const diffusionMap = {
ddim: DiffusionSampler.SAMPLER_DDIM,
plms: DiffusionSampler.SAMPLER_DDPM,
k_euler: DiffusionSampler.SAMPLER_K_EULER,
k_euler_ancestral: DiffusionSampler.SAMPLER_K_EULER_ANCESTRAL,
k_heun: DiffusionSampler.SAMPLER_K_HEUN,
k_dpm_2: DiffusionSampler.SAMPLER_K_DPM_2,
k_dpm_2_ancestral: DiffusionSampler.SAMPLER_K_DPM_2_ANCESTRAL,
k_lms: DiffusionSampler.SAMPLER_K_LMS,
}
7 changes: 5 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"declaration": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"lib": ["es2020"],
"lib": ["ES5"],
"module": "commonjs",
"noImplicitAny": true,
"noImplicitReturns": true,
Expand All @@ -20,7 +20,10 @@
"strictNullChecks": true,
"target": "es2021",
"moduleResolution": "node",
"typeRoots": ["node_modules/@types"]
"typeRoots": ["node_modules/@types"],

"emitDeclarationOnly": true,
"isolatedModules": true
},
"exclude": ["node_modules"],
"include": ["src/**/*.ts"]
Expand Down
12 changes: 10 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const nodeExternals = require('webpack-node-externals')
const ShebangPlugin = require('webpack-shebang-plugin')

module.exports = {
mode: 'development',
mode: 'production',
entry: {
index: './src/index.ts',
bin: './src/bin.ts',
Expand All @@ -21,9 +21,14 @@ module.exports = {
rules: [
{
test: /\.ts?$/,
use: 'ts-loader',
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.js$/,
use: ['source-map-loader'],
enforce: 'pre',
},
],
},
resolve: {
Expand All @@ -32,6 +37,9 @@ module.exports = {
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'build'),
library: {
type: 'commonjs',
},
},
plugins: [new ShebangPlugin()],
node: {
Expand Down
Loading