@@ -34,9 +34,10 @@ public func generate<Content: Decodable>(
3434 context: ModelContext ,
3535 schema: JSONSchema ,
3636 generating: Content . Type ,
37+ indent: Int ? = nil ,
3738 didGenerate: ( [ Int ] ) -> GenerateDisposition = { _ in . more }
3839) async throws -> ( GenerateResult , Content ) {
39- let grammar = try Grammar . schema ( schema)
40+ let grammar = try Grammar . schema ( schema, indent : indent )
4041 let sampler = parameters. sampler ( )
4142 let processor = try await GrammarMaskedLogitProcessor . from ( configuration: context. configuration, grammar: grammar)
4243 let iterator = try TokenIterator ( input: input, model: context. model, processor: processor, sampler: sampler)
@@ -52,10 +53,11 @@ public func generate<Content: Generable>(
5253 parameters: GenerateParameters = GenerateParameters ( ) ,
5354 context: ModelContext ,
5455 generating: Content . Type ,
56+ indent: Int ? = nil ,
5557 didGenerate: ( [ Int ] ) -> GenerateDisposition = { _ in . more }
5658) async throws -> ( GenerateResult , Content ) {
5759 let sampler = parameters. sampler ( )
58- let grammar = try Grammar . generable ( Content . self)
60+ let grammar = try Grammar . generable ( Content . self, indent : indent )
5961 let processor = try await GrammarMaskedLogitProcessor . from ( configuration: context. configuration, grammar: grammar)
6062 let iterator = try TokenIterator ( input: input, model: context. model, processor: processor, sampler: sampler)
6163 let result = generate ( input: input, context: context, iterator: iterator, didGenerate: didGenerate)
@@ -68,10 +70,11 @@ public func generate<Content: Generable>(
6870 input: LMInput ,
6971 parameters: GenerateParameters = GenerateParameters ( ) ,
7072 context: ModelContext ,
71- generating: Content . Type
73+ generating: Content . Type ,
74+ indent: Int ? = nil
7275) async throws -> AsyncStream < Content . PartiallyGenerated > {
7376 let sampler = parameters. sampler ( )
74- let grammar = try Grammar . generable ( Content . self)
77+ let grammar = try Grammar . generable ( Content . self, indent : indent )
7578 let processor = try await GrammarMaskedLogitProcessor . from ( configuration: context. configuration, grammar: grammar)
7679 let iterator = try TokenIterator ( input: input, model: context. model, processor: processor, sampler: sampler)
7780 let stream = generate ( input: input, context: context, iterator: iterator)
0 commit comments