UNPKG

jann-scraper

Version:

The library scraper for WhatsApp bot or Restfull API's

61 lines (57 loc) 2.06 kB
const axios = require("axios") class Pixart { constructor() { this.name = "Pixart"; this.type = "ImageGeneration"; this.url = "https://nexra.aryahcr.cc/api/image/complements"; this.default_options = { negativePrompt: "", imageStyle: "(No style)", width: 1024, height: 1024, samplingMethod: "DPM-Solver", cfgScale: 4.5, dpmInferenceSteps: 14, saGuidanceScale: 3, saInferenceSteps: 25 }; this.need_slice_text = false; this.working = true; } async fetchData(prompt, options) { const headers = { "Content-Type": "application/json" }; const data = { prompt, model: "pixart-a", data: { prompt_negative: options?.negativePrompt || this.default_options.negativePrompt, image_style: options?.imageStyle || this.default_options.imageStyle, width: options?.width || this.default_options.width, height: options?.height || this.default_options.height, sampler: options?.samplingMethod || this.default_options.samplingMethod, dpm_guidance_scale: options?.cfgScale || this.default_options.cfgScale, dpm_inference_steps: options?.dpmInferenceSteps || this.default_options.dpmInferenceSteps, sa_guidance_scale: options?.saGuidanceScale || this.default_options.saGuidanceScale, sa_inference_steps: options?.saInferenceSteps || this.default_options.saInferenceSteps } }; try { const response = await axios.post("https://nexra.aryahcr.cc/api/image/complements", data, { headers }); return this.handleResponse(response.data); } catch (error) { if (error.message.startsWith("Invalid response.")) { throw new Error(error.message); } throw new Error("Failed to fetch Pixart data. Please try again later."); } } handleResponse(text) { text = text.substring(text.indexOf("{"), text.length); let img = JSON.parse(text); img = img.images[0].split(";base64,").pop(); return img; } } module.exports = { Pixart }