wolfyflutter

exomlapi.com [ai] [image generation] [text to image]

Jun 8th, 2025 (edited)
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 4.50 KB | Source Code | 0 0
  1. /*
  2.   base        : https://exomlapi.com/image-gen
  3.   fungsi      : buat generate gambar dari prompt, image generation gitu.
  4.   note        : cuma support text to image, belum support image to image,
  5.                 ada juga fungsi enhance prompt. jadi gw bikin 2 fungsi
  6.                 terpisah. 1 fungsi buat enhance prompt, dan 1 lagi fungsi
  7.                 buat generate gambar. ada beberapa model, bisa lu explore
  8.                 sendiri :v, tenang udh gw sediain list yg bs di pakek.
  9.                 sorry bet kalau kode nya panjang.
  10.   last update : 8 Juni 2025
  11.   by          : wolep
  12. */
  13.  
  14. const ai = {
  15.     enhancePrompt: async (prompt) => {
  16.         if (!prompt) throw Error(`input prompt gak boleh kosong humf!`)
  17.         const response = await fetch("https://exomlapi.com/api/prompts/enhance", {
  18.             "body": JSON.stringify({ prompt }),
  19.             "method": "POST",
  20.         })
  21.         if (!response.ok) throw Error(`fetch status is not ok cuy pas enhance ${response.status} ${response.statusText}\n\n${await response.text() || null}`)
  22.         const result = await response.json()
  23.         return result
  24.     },
  25.  
  26.     generateImage: async (prompt, options = {}) => {
  27.         if (!prompt) throw Error(`input prompt gak boleh kosong humf!`)
  28.  
  29.         const modelList = [
  30.             "exo-image",
  31.             "flux.1-schnell",
  32.             "flux.1-pro",
  33.             "flux.1-dev"
  34.         ]
  35.  
  36.         const { model = modelList[2], enhancePrompt = false } = options // model default flux.1-pro, enhancePrompt default false
  37.  
  38.         // value validation
  39.         if (!modelList.some(v => v == model)) throw Error(`gaada model ${model} broo... gunakan opsi model yang tersedia: ${modelList.join(", ")}`)
  40.         if (typeof (enhancePrompt) != "boolean") throw Error(`invalid value enhancePrompt`)
  41.  
  42.         // get enhanced prompt (if user wish)
  43.         let usedPrompt = prompt
  44.         if (enhancePrompt) {
  45.             try {
  46.                 usedPrompt = (await ai.enhancePrompt(prompt)).enhancedPrompt
  47.             } catch (err) {
  48.                 console.log(`gagal enhance prompt. image generation tetep lanjut makek prompt asli.\n ${err.message}`)
  49.             }
  50.         }
  51.  
  52.         // actual hit
  53.         const response = await fetch("https://exomlapi.com/api/images/generate", {
  54.             "body": JSON.stringify(
  55.                 {
  56.                     prompt: usedPrompt,
  57.                     model,
  58.                     "size": "1024x1024"
  59.                 }
  60.             ),
  61.             "method": "POST",
  62.         });
  63.         if (!response.ok) throw Error(`fetch status is not ok cuy pas generate image ${response.status} ${response.statusText}\n${await response.text() || null}`)
  64.         const result = await response.json()
  65.         return { myMetadata: { prompt, usedPrompt, enhancePrompt, model }, ...result }
  66.     }
  67. }
  68.  
  69. // cara pakai
  70.  
  71. const imajinasimu = "anime neko holding sign written hai kak wolep!" +
  72.     "anime style red hair neesan, neko girl, beautiful, camisole white, small paper on chest, blush face smile"
  73.  
  74. // bisa kek gini
  75. // ai.generateImage(imajinasimu)
  76.  
  77. // atau kek gini, ingat config ini opsional yah, bisa isi bisa gak
  78. const config = {
  79.     enhancePrompt: false, // true atau false (default false)
  80.     model: "flux.1-pro" // exo-image, flux.1-schnell, flux.1-pro, flux.1-dev (default flux.1-pro)
  81. }
  82.  
  83. ai.generateImage(imajinasimu, config)
  84.     .then(data => console.log(JSON.stringify(data, null, 2)))
  85.     .catch(err => console.log(err.message))
  86.  
  87. /*
  88. result
  89. {
  90.   "myMetadata": {
  91.     "prompt": "anime neko holding sign written hai kak wolep!anime style red hair neesan, neko girl, beautiful, camisole white, small paper on chest, blush face smile",
  92.     "usedPrompt": "anime neko holding sign written hai kak wolep!anime style red hair neesan, neko girl, beautiful, camisole white, small paper on chest, blush face smile",
  93.     "enhancePrompt": false,
  94.     "model": "flux.1-pro"
  95.   },
  96.   "id": "nxJrZwv-4yUbBN-94c911b7ee8ec4ec-SEA",
  97.   "model": "black-forest-labs/FLUX.1-pro",
  98.   "object": "list",
  99.   "data": [
  100.     {
  101.       "timings": {
  102.         "inference": 19597
  103.       },
  104.       "index": 0,
  105.       "url": "https://api.together.ai/imgproxy/pV46aAY7TIs77Fq25kg49YfKUpiWEj6RWB2UFqA-obk/format:jpeg/aHR0cHM6Ly9kZWxpdmVyeS1ldTEuYmZsLmFpL3Jlc3VsdHMvZGEvODU2MTM0NjE1MTczMTMvNjE1MTczMTM1NzY5NGNiNjgyNDViMGY1NTAwZWVlNTkvc2FtcGxlLmpwZWc_c2U9MjAyNS0wNi0wOFQxNCUzQTM3JTNBMzZaJnNwPXImc3Y9MjAyNC0xMS0wNCZzcj1iJnJzY3Q9aW1hZ2UvanBlZyZzaWc9NlMlMkIzeExYRXklMkJXZFNYNDN5Vng0ampvJTJCSG1BOEFsc0dzZk9RSFdzY0NiTSUzRA"
  106.     }
  107.   ]
  108. }
  109. */
  110.  
  111.  
Add Comment
Please, Sign In to add comment