@@ -434,6 +434,29 @@ final class GenerativeModelVertexAITests: XCTestCase {
434
434
XCTAssertEqual ( text, " The sum of [1, 2, 3] is " )
435
435
}
436
436
437
+ func testGenerateContent_success_thinking_thoughtSummary( ) async throws {
438
+ MockURLProtocol . requestHandler = try GenerativeModelTestUtil . httpRequestHandler (
439
+ forResource: " unary-success-thinking-reply-thought-summary " ,
440
+ withExtension: " json " ,
441
+ subdirectory: vertexSubdirectory
442
+ )
443
+
444
+ let response = try await model. generateContent ( testPrompt)
445
+
446
+ XCTAssertEqual ( response. candidates. count, 1 )
447
+ let candidate = try XCTUnwrap ( response. candidates. first)
448
+ XCTAssertEqual ( candidate. finishReason, . stop)
449
+ XCTAssertEqual ( candidate. content. parts. count, 2 )
450
+ let thoughtPart = try XCTUnwrap ( candidate. content. parts. first as? TextPart )
451
+ XCTAssertTrue ( thoughtPart. isThought)
452
+ XCTAssertTrue ( thoughtPart. text. hasPrefix ( " Right, someone needs the city where Google " ) )
453
+ XCTAssertEqual ( response. thoughtSummary, thoughtPart. text)
454
+ let textPart = try XCTUnwrap ( candidate. content. parts. last as? TextPart )
455
+ XCTAssertFalse ( textPart. isThought)
456
+ XCTAssertEqual ( textPart. text, " Mountain View " )
457
+ XCTAssertEqual ( response. text, textPart. text)
458
+ }
459
+
437
460
func testGenerateContent_success_image_invalidSafetyRatingsIgnored( ) async throws {
438
461
MockURLProtocol . requestHandler = try GenerativeModelTestUtil . httpRequestHandler (
439
462
forResource: " unary-success-image-invalid-safety-ratings " ,
@@ -1330,6 +1353,33 @@ final class GenerativeModelVertexAITests: XCTestCase {
1330
1353
XCTAssertFalse ( citations. contains { $0. license? . isEmpty ?? false } )
1331
1354
}
1332
1355
1356
+ func testGenerateContentStream_successWithThinking_thoughtSummary( ) async throws {
1357
+ MockURLProtocol . requestHandler = try GenerativeModelTestUtil . httpRequestHandler (
1358
+ forResource: " streaming-success-thinking-reply-thought-summary " ,
1359
+ withExtension: " txt " ,
1360
+ subdirectory: vertexSubdirectory
1361
+ )
1362
+
1363
+ var thoughtSummary = " "
1364
+ var text = " "
1365
+ let stream = try model. generateContentStream ( " Hi " )
1366
+ for try await response in stream {
1367
+ let candidate = try XCTUnwrap ( response. candidates. first)
1368
+ XCTAssertEqual ( candidate. content. parts. count, 1 )
1369
+ let part = try XCTUnwrap ( candidate. content. parts. first)
1370
+ let textPart = try XCTUnwrap ( part as? TextPart )
1371
+ if textPart. isThought {
1372
+ let newThought = try XCTUnwrap ( response. thoughtSummary)
1373
+ thoughtSummary. append ( newThought)
1374
+ } else {
1375
+ text. append ( textPart. text)
1376
+ }
1377
+ }
1378
+
1379
+ XCTAssertTrue ( thoughtSummary. hasPrefix ( " **Understanding the Core Question** " ) )
1380
+ XCTAssertTrue ( text. hasPrefix ( " The sky is blue due to a phenomenon " ) )
1381
+ }
1382
+
1333
1383
func testGenerateContentStream_successWithInvalidSafetyRatingsIgnored( ) async throws {
1334
1384
MockURLProtocol . requestHandler = try GenerativeModelTestUtil . httpRequestHandler (
1335
1385
forResource: " streaming-success-image-invalid-safety-ratings " ,
0 commit comments