(prompt, options = {})
| 500 | }; |
| 501 | |
| 502 | export const generateImage = async (prompt, options = {}) => { |
| 503 | const { |
| 504 | model = "flux", |
| 505 | width = 1024, |
| 506 | height = 1024, |
| 507 | seed = Math.floor(Math.random() * 2147483647), |
| 508 | nologo = false, |
| 509 | enhance = false, |
| 510 | nofeed = false, |
| 511 | safe = false, |
| 512 | quality = "medium", |
| 513 | } = options; |
| 514 | |
| 515 | const params = new URLSearchParams({ |
| 516 | model, |
| 517 | width, |
| 518 | height, |
| 519 | seed, |
| 520 | enhance, |
| 521 | nologo, |
| 522 | nofeed, |
| 523 | safe, |
| 524 | quality, |
| 525 | }); |
| 526 | const url = `${BASE_URL}/image/${encodeURIComponent(prompt)}?${params}`; |
| 527 | const token = getApiToken(); |
| 528 | const headers = token ? { Authorization: `Bearer ${token}` } : {}; |
| 529 | const response = await fetch(url, { headers }); |
| 530 | if (!response.ok) throw await parseApiError(response); |
| 531 | |
| 532 | const blob = await response.blob(); |
| 533 | return new Promise((resolve, reject) => { |
| 534 | const reader = new FileReader(); |
| 535 | reader.onloadend = () => |
| 536 | resolve({ url: reader.result, prompt, model, width, height, seed }); |
| 537 | reader.onerror = reject; |
| 538 | reader.readAsDataURL(blob); |
| 539 | }); |
| 540 | }; |
| 541 | |
| 542 | export const generateVideo = async (prompt, options = {}) => { |
| 543 | const { |
no test coverage detected