Skip to content

v1.0.0 OpenAIStructure

Choose a tag to compare

@yukiny0811 yukiny0811 released this 02 May 15:54
· 6 commits to main since this release
0ef7f77

Swift Macro for OpenAI API Structured Outputs.

@OpenAIStructure(name: "talk_theme")
struct TalkTheme {

    @Field("Theme title")
    var title: String

    @Field("Theme overview")
    var overview: String

    @Field("Question blocks")
    var questionBlocks: [QuestionBlock]
}

@OpenAIStructure(name: "question_block")
struct QuestionBlock {

    @Field("Block label")
    var label: String

    @Field("List of questions")
    var questions: [String]
}
let result: TalkThemePack = try await OpenAIRequest.request(
    input: "Talk theme related to food.",
    instructions: "Provide some talk themes.",
    model: .o4_mini(reasoningEffort: .low),
    object: TalkTheme.self,
    apiKey: "<your_api_key>"
)