मुख्य कंटेंट तक स्किप करें

इमेज जनरेशन

Text prompt से एक या अधिक UIImage परिणाम बनाएँ। Provider limits और चुनने योग्य styles optional capabilities हैं; generation task भेजने के लिए आवश्यक नहीं।

Animated workflow

Image-generation task lifecycle

Prompt तैयार करें; उपलब्ध हों तो provider limits या styles उपयोग करें, अन्यथा default task configuration अपनाएँ।

Host app

Prompt तैयार करें

बनाई जाने वाली images का nonempty विवरण आवश्यक रखें।

AI service

Optional limit पढ़ें

Positive provider maximum उपलब्ध हो तो उपयोग करें; अन्यथा एक image माँगें।

AI service → app

Optional styles load करें

Provider styles दे तो मिला styleCode उपयोग करें; अन्यथा style खाली रखें।

Host app

Task कॉन्फ़िगर करें

तय count और style के साथ optional size और language set करें।

AI service

Task बनाएँ

Generation शुरू करें और onTaskCreated से task ID सहेजें।

task बना
अंतिम परिणाम

Images पाएँ

Completion callback से success, images, task ID और error उपयोग करें।

Optional capability metadata generation को न रोके: उपलब्ध न होने पर एक image और बिना explicit style के आगे बढ़ें।

आवश्यक शर्तें

  • AIBudsAISDK initialize करें, सेवा प्रदाता चुनें और आवश्यकता होने पर authentication पूरा करें।
  • पुष्टि करें कि चुना गया सेवा प्रदाता AIGCServiceAPI implement करता है।
  • बनी images दिखाने, सहेजने और साझा करने के लिए app policy तय करें।

AI की सहायता से लागू करें

AI से बनाएँ

इस वर्कफ़्लो को AI से लागू करें

आधिकारिक “AIBuds AI से चित्र बनाएँ” स्किल से वर्कफ़्लो को अपने ऐप के अनुसार लागू करें।

https://docs-aibuds.github.io/hi/skills/generate-aibuds-ai-images को पढ़ें और निर्देशों का पालन करें। इस स्किल से “AIBuds AI से चित्र बनाएँ” को इस iOS प्रोजेक्ट में लागू करें और परिणाम सत्यापित करें।
आधिकारिक स्किल देखें

API Reference

Framework

AIBudsAI.xcframework

Declaration

Swift
/// The available styles cached by the selected image-generation provider.
static var aigcStyles: [AIGCStyleModel]? { get }

/// The maximum number of images accepted in one task. A positive value can be
/// used to constrain the requested image count.
static var aigcMaxGenerateCount: Int { get }

/// Fetches styles supported by the selected provider.
public static func fetchAigcStyles(completion: ((_ styles: [AIGCStyleModel]?, _ error: NSError?) -> Void)? = nil)

/// Generates images from a text prompt and configuration.
/// - Parameters:
///   - prompt: The text prompt for image generation.
///   - config: Task configuration. Defaults to `.default`.
///   - onTaskCreated: Called with the provider task identifier.
///   - completion: Returns the task identifier, success flag, generated images,
///     and failure information.
public static func generateAIPhoto(prompt: String,
                                   config: AIGCTaskConfig = .default,
                            onTaskCreated: ((_ taskId: String) -> Void)? = nil,
                               completion: ((
                                   _ taskId: String?,
                                   _ success: Bool,
                                   _ images: [UIImage]?,
                                   _ error: NSError?
                               ) -> Void)? = nil)

generateAIPhoto, fetchAigcStyles और AIGCTaskConfig देखें।

Task कॉन्फ़िगरेशन

प्रॉपर्टीअर्थ
styleAIGCStyleModel.styleCode से मिला provider style code। Styles उपलब्ध न हों या app style selection न दे तो इसे nil रखें।
imageCountमांगी गई संख्या। Default 1 उपयोग करें जब positive aigcMaxGenerateCount न मिले; अन्यथा बताई गई limit के भीतर रखें।
imageSizeOptional positive width और height; nil होने पर provider default उपयोग होता है।
languageen-US जैसी prompt language; nil app localization उपयोग करता है और empty string supported होने पर auto-detection मांगती है।

उपयोग के उदाहरण

वैकल्पिक Provider Capabilities के साथ बनाएँ

App style selection न देता हो तो fetchAigcStyles छोड़ें और generation helper को nil के साथ call करें। नीचे का उदाहरण styles load करने की कोशिश करता है, लेकिन list खाली हो या request विफल हो तब भी prompt भेजता है।

Swift
let prompt = "A lightweight wearable assistant on a clean studio background"

func generate(styleCode: String?) {
    let maximum = AIBudsAISDK.aigcMaxGenerateCount
    let config = AIGCTaskConfig()
    config.style = styleCode
    config.imageCount = maximum > 0 ? min(2, maximum) : 1
    config.language = "en-US"

    AIBudsAISDK.generateAIPhoto(
        prompt: prompt,
        config: config,
        onTaskCreated: { taskID in
            DispatchQueue.main.async { showTask(id: taskID) }
        },
        completion: { taskID, success, images, error in
            DispatchQueue.main.async {
                guard success, let images, !images.isEmpty else {
                    if let error {
                        show(error)
                    } else {
                        print("The provider returned no images")
                    }
                    return
                }
                show(images: images, taskID: taskID)
            }
        }
    )
}

AIBudsAISDK.fetchAigcStyles { styles, error in
    // Style discovery is optional. A nil style uses the provider default.
    let styleCode = error == nil ? styles?.first?.styleCode : nil
    generate(styleCode: styleCode)
}

त्रुटि प्रबंधन

Style fetch विफल होना या generation limit उपलब्ध न होना generation failure नहीं है। style = nil और imageCount = 1 उपयोग करें; generation completion callback को task का authoritative result मानें।

ध्यान देने योग्य बातें

  • Style codes और positive maximum counts optional provider data हैं और बदल सकते हैं; Demo values hard-code न करें।
  • Empty style list मान्य है। Provider default के लिए prompt को style = nil के साथ भेजें।
  • Task-created callback का अर्थ images सफलतापूर्वक बन जाना नहीं है।
  • Public API अभी image-generation progress या cancellation उपलब्ध नहीं कराती।