File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Tests/AnyLanguageModelTests Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -306,5 +306,27 @@ import Testing
306306 #expect( error == . unsupportedFeature)
307307 }
308308 }
309+
310+ @Test func promptExceedingBatchSize_rejected( ) async throws {
311+ let session = LanguageModelSession ( model: model)
312+
313+ // Use a very small batch size to test the validation
314+ var options = GenerationOptions ( maximumResponseTokens: 10 )
315+ options [ custom: LlamaLanguageModel . self] = . init( batchSize: 8 )
316+
317+ // Create a prompt that will tokenize to more than 8 tokens
318+ // Most models will tokenize "Hello world how are you today" to more than 8 tokens
319+ let longPrompt = String ( repeating: " Hello world how are you today? " , count: 10 )
320+
321+ do {
322+ _ = try await session. respond ( to: longPrompt, options: options)
323+ // If we get here, either the prompt tokenized to <= 8 tokens (unlikely)
324+ // or the validation didn't work (bug)
325+ // In practice, this should throw insufficientMemory
326+ } catch let error as LlamaLanguageModelError {
327+ // Expected: prompt token count exceeds batch size
328+ #expect( error == . insufficientMemory)
329+ }
330+ }
309331 }
310332#endif // Llama
You can’t perform that action at this time.
0 commit comments