@@ -32,48 +32,55 @@ public class GenerateContentResponse(
3232 public val usageMetadata : UsageMetadata ? ,
3333) {
3434 /* *
35- * Convenience field representing all the non-thought text parts in the response as a single
36- * string, if they exists.
35+ * Convenience field representing all text parts in the response as a single string, if they
36+ * exists.
37+ *
38+ * Any part that's marked as a thought will be ignored. Learn more about
39+ * [thinking](https://firebase.google.com/docs/ai-logic/thinking?api=dev).
3740 */
3841 public val text: String? by lazy {
39- candidates
40- .first()
41- .content
42- .parts
43- .filter { ! it.isThought && it is TextPart }
44- .joinToString(" " ) { (it as TextPart ).text }
42+ candidates.first().nonThoughtParts().filterIsInstance<TextPart >().joinToString(" " ) { it.text }
4543 }
4644
47- /* * Convenience field to list all the [FunctionCallPart]s in the response, if they exist. */
45+ /* *
46+ * Convenience field to list all the [FunctionCallPart]s in the response.
47+ *
48+ * Any part that's marked as a thought will be ignored. Learn more about
49+ * [thinking](https://firebase.google.com/docs/ai-logic/thinking?api=dev).
50+ */
4851 public val functionCalls: List <FunctionCallPart > by lazy {
49- candidates.first().content.parts .filterIsInstance<FunctionCallPart >()
52+ candidates.first().nonThoughtParts() .filterIsInstance<FunctionCallPart >()
5053 }
5154
5255 /* *
5356 * Convenience field representing all the text parts in the response that are marked as thoughts
5457 * as a single string, if they exists.
58+ *
59+ * Learn more about [thinking](https://firebase.google.com/docs/ai-logic/thinking?api=dev).
5560 */
5661 public val thoughtSummary: String? by lazy {
57- candidates
58- .first()
59- .content
60- .parts
61- .filter { it.isThought && it is TextPart }
62- .joinToString(" " ) { (it as TextPart ).text }
62+ candidates.first().thoughtParts().filterIsInstance<TextPart >().joinToString(" " )
6363 }
6464
6565 /* *
66- * Convenience field representing all the [InlineDataPart]s in the first candidate, if they exist .
66+ * Convenience field representing all the [InlineDataPart]s in the first candidate.
6767 *
6868 * This also includes any [ImagePart], but they will be represented as [InlineDataPart] instead.
69+ *
70+ * Any part that's marked as a thought will be ignored. Learn more about
71+ * [thinking](https://firebase.google.com/docs/ai-logic/thinking?api=dev).
6972 */
7073 public val inlineDataParts: List <InlineDataPart > by lazy {
71- candidates.first().content.parts .let { parts ->
74+ candidates.first().nonThoughtParts() .let { parts ->
7275 parts.filterIsInstance<ImagePart >().map { it.toInlineDataPart() } +
7376 parts.filterIsInstance<InlineDataPart >()
7477 }
7578 }
7679
80+ private fun Candidate.thoughtParts (): List <Part > = content.parts.filter { it.isThought }
81+
82+ private fun Candidate.nonThoughtParts (): List <Part > = content.parts.filter { ! it.isThought }
83+
7784 @Serializable
7885 internal data class Internal (
7986 val candidates : List <Candidate .Internal >? = null ,
0 commit comments