v1.0.0 OpenAIStructure
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>"
)