Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- base : https://exomlapi.com/image-gen
- fungsi : buat generate gambar dari prompt, image generation gitu.
- note : cuma support text to image, belum support image to image,
- ada juga fungsi enhance prompt. jadi gw bikin 2 fungsi
- terpisah. 1 fungsi buat enhance prompt, dan 1 lagi fungsi
- buat generate gambar. ada beberapa model, bisa lu explore
- sendiri :v, tenang udh gw sediain list yg bs di pakek.
- sorry bet kalau kode nya panjang.
- last update : 8 Juni 2025
- by : wolep
- */
- const ai = {
- enhancePrompt: async (prompt) => {
- if (!prompt) throw Error(`input prompt gak boleh kosong humf!`)
- const response = await fetch("https://exomlapi.com/api/prompts/enhance", {
- "body": JSON.stringify({ prompt }),
- "method": "POST",
- })
- if (!response.ok) throw Error(`fetch status is not ok cuy pas enhance ${response.status} ${response.statusText}\n\n${await response.text() || null}`)
- const result = await response.json()
- return result
- },
- generateImage: async (prompt, options = {}) => {
- if (!prompt) throw Error(`input prompt gak boleh kosong humf!`)
- const modelList = [
- "exo-image",
- "flux.1-schnell",
- "flux.1-pro",
- "flux.1-dev"
- ]
- const { model = modelList[2], enhancePrompt = false } = options // model default flux.1-pro, enhancePrompt default false
- // value validation
- if (!modelList.some(v => v == model)) throw Error(`gaada model ${model} broo... gunakan opsi model yang tersedia: ${modelList.join(", ")}`)
- if (typeof (enhancePrompt) != "boolean") throw Error(`invalid value enhancePrompt`)
- // get enhanced prompt (if user wish)
- let usedPrompt = prompt
- if (enhancePrompt) {
- try {
- usedPrompt = (await ai.enhancePrompt(prompt)).enhancedPrompt
- } catch (err) {
- console.log(`gagal enhance prompt. image generation tetep lanjut makek prompt asli.\n ${err.message}`)
- }
- }
- // actual hit
- const response = await fetch("https://exomlapi.com/api/images/generate", {
- "body": JSON.stringify(
- {
- prompt: usedPrompt,
- model,
- "size": "1024x1024"
- }
- ),
- "method": "POST",
- });
- if (!response.ok) throw Error(`fetch status is not ok cuy pas generate image ${response.status} ${response.statusText}\n${await response.text() || null}`)
- const result = await response.json()
- return { myMetadata: { prompt, usedPrompt, enhancePrompt, model }, ...result }
- }
- }
- // cara pakai
- const imajinasimu = "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"
- // bisa kek gini
- // ai.generateImage(imajinasimu)
- // atau kek gini, ingat config ini opsional yah, bisa isi bisa gak
- const config = {
- enhancePrompt: false, // true atau false (default false)
- model: "flux.1-pro" // exo-image, flux.1-schnell, flux.1-pro, flux.1-dev (default flux.1-pro)
- }
- ai.generateImage(imajinasimu, config)
- .then(data => console.log(JSON.stringify(data, null, 2)))
- .catch(err => console.log(err.message))
- /*
- result
- {
- "myMetadata": {
- "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",
- "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",
- "enhancePrompt": false,
- "model": "flux.1-pro"
- },
- "id": "nxJrZwv-4yUbBN-94c911b7ee8ec4ec-SEA",
- "model": "black-forest-labs/FLUX.1-pro",
- "object": "list",
- "data": [
- {
- "timings": {
- "inference": 19597
- },
- "index": 0,
- "url": "https://api.together.ai/imgproxy/pV46aAY7TIs77Fq25kg49YfKUpiWEj6RWB2UFqA-obk/format:jpeg/aHR0cHM6Ly9kZWxpdmVyeS1ldTEuYmZsLmFpL3Jlc3VsdHMvZGEvODU2MTM0NjE1MTczMTMvNjE1MTczMTM1NzY5NGNiNjgyNDViMGY1NTAwZWVlNTkvc2FtcGxlLmpwZWc_c2U9MjAyNS0wNi0wOFQxNCUzQTM3JTNBMzZaJnNwPXImc3Y9MjAyNC0xMS0wNCZzcj1iJnJzY3Q9aW1hZ2UvanBlZyZzaWc9NlMlMkIzeExYRXklMkJXZFNYNDN5Vng0ampvJTJCSG1BOEFsc0dzZk9RSFdzY0NiTSUzRA"
- }
- ]
- }
- */
Add Comment
Please, Sign In to add comment