UNPKG

ai-utils.js

Version:

Build AI applications, chatbots, and agents with JavaScript and TypeScript.

96 lines (95 loc) 4.08 kB
import { z } from "zod"; import { AbstractModel } from "../../model-function/AbstractModel.js"; import { FunctionOptions } from "../../model-function/FunctionOptions.js"; import { ImageGenerationModel, ImageGenerationModelSettings } from "../../model-function/generate-image/ImageGenerationModel.js"; import { RetryFunction } from "../../util/api/RetryFunction.js"; import { ThrottleFunction } from "../../util/api/ThrottleFunction.js"; /** * Create an image generation model that calls the Stability AI image generation API. * * @see https://api.stability.ai/docs#tag/v1generation/operation/textToImage * * @example * const { image } = await generateImage( * new StabilityImageGenerationModel({ * model: "stable-diffusion-512-v2-1", * cfgScale: 7, * clipGuidancePreset: "FAST_BLUE", * height: 512, * width: 512, * samples: 1, * steps: 30, * }) * [ * { text: "the wicked witch of the west" }, * { text: "style of early 19th century painting", weight: 0.5 }, * ] * ); */ export declare class StabilityImageGenerationModel extends AbstractModel<StabilityImageGenerationModelSettings> implements ImageGenerationModel<StabilityImageGenerationPrompt, StabilityImageGenerationResponse, StabilityImageGenerationModelSettings> { constructor(settings: StabilityImageGenerationModelSettings); readonly provider: "stability"; get modelName(): string; private get apiKey(); callAPI(input: StabilityImageGenerationPrompt, options?: FunctionOptions<StabilityImageGenerationModelSettings>): Promise<StabilityImageGenerationResponse>; generateImageResponse(prompt: StabilityImageGenerationPrompt, options?: FunctionOptions<StabilityImageGenerationModelSettings>): Promise<{ artifacts: { seed: number; base64: string; finishReason: "SUCCESS" | "ERROR" | "CONTENT_FILTERED"; }[]; }>; extractBase64Image(response: StabilityImageGenerationResponse): string; withSettings(additionalSettings: StabilityImageGenerationModelSettings): this; } export interface StabilityImageGenerationModelSettings extends ImageGenerationModelSettings { model: string; baseUrl?: string; apiKey?: string; retry?: RetryFunction; throttle?: ThrottleFunction; height?: number; width?: number; cfgScale?: number; clipGuidancePreset?: string; sampler?: StabilityImageGenerationSampler; samples?: number; seed?: number; steps?: number; stylePreset?: StabilityImageGenerationStylePreset; } declare const stabilityImageGenerationResponseSchema: z.ZodObject<{ artifacts: z.ZodArray<z.ZodObject<{ base64: z.ZodString; seed: z.ZodNumber; finishReason: z.ZodEnum<["SUCCESS", "ERROR", "CONTENT_FILTERED"]>; }, "strip", z.ZodTypeAny, { seed: number; base64: string; finishReason: "SUCCESS" | "ERROR" | "CONTENT_FILTERED"; }, { seed: number; base64: string; finishReason: "SUCCESS" | "ERROR" | "CONTENT_FILTERED"; }>, "many">; }, "strip", z.ZodTypeAny, { artifacts: { seed: number; base64: string; finishReason: "SUCCESS" | "ERROR" | "CONTENT_FILTERED"; }[]; }, { artifacts: { seed: number; base64: string; finishReason: "SUCCESS" | "ERROR" | "CONTENT_FILTERED"; }[]; }>; export type StabilityImageGenerationResponse = z.infer<typeof stabilityImageGenerationResponseSchema>; export type StabilityImageGenerationStylePreset = "enhance" | "anime" | "photographic" | "digital-art" | "comic-book" | "fantasy-art" | "line-art" | "analog-film" | "neon-punk" | "isometric" | "low-poly" | "origami" | "modeling-compound" | "cinematic" | "3d-model" | "pixel-art" | "tile-texture"; export type StabilityImageGenerationSampler = "DDIM" | "DDPM" | "K_DPMPP_2M" | "K_DPMPP_2S_ANCESTRAL" | "K_DPM_2" | "K_DPM_2_ANCESTRAL" | "K_EULER" | "K_EULER_ANCESTRAL" | "K_HEUN" | "K_LMS"; export type StabilityImageGenerationPrompt = Array<{ text: string; weight?: number; }>; export {};