From d0bcbe2cd260c5bc290aa7fa9dc8f72c05394711 Mon Sep 17 00:00:00 2001 From: nezhyborets Date: Mon, 14 Jul 2025 13:37:39 +0300 Subject: [PATCH] Fix derived schema example --- README.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1669e361..05709f16 100644 --- a/README.md +++ b/README.md @@ -840,7 +840,7 @@ struct MovieInfo: JSONSchemaConvertible { let genres: [MovieGenre] let cast: [String] - static let example: Self = { + static let example: Self = { .init( title: "Earth", director: "Alexander Dovzhenko", @@ -850,17 +850,26 @@ struct MovieInfo: JSONSchemaConvertible { ) }() } - enum MovieGenre: String, Codable, JSONSchemaEnumConvertible { case action, drama, comedy, scifi var caseNames: [String] { Self.allCases.map { $0.rawValue } } } - let query = ChatQuery( - messages: [.system(.init(content: "Best Picture winner at the 2011 Oscars"))], + messages: [ + .system( + .init(content: .textContent("Best Picture winner at the 2011 Oscars")) + ) + ], model: .gpt4_o, - responseFormat: .jsonSchema(.derivedJsonSchema(name: "movie-info", type: MovieInfo.self)) + responseFormat: .jsonSchema( + .init( + name: "movie-info", + description: nil, + schema: .derivedJsonSchema(MovieInfo.self), + strict: true + ) + ) ) let result = try await openAI.chats(query: query) ```