(candidate: Candidate | undefined)
| 80 | * Filters out thought parts (model reasoning) from the output. |
| 81 | */ |
| 82 | export function extractTextContent(candidate: Candidate | undefined): string { |
| 83 | if (!candidate?.content?.parts) return '' |
| 84 | |
| 85 | const textParts = candidate.content.parts.filter( |
| 86 | (part): part is Part & { text: string } => Boolean(part.text) && part.thought !== true |
| 87 | ) |
| 88 | |
| 89 | if (textParts.length === 0) return '' |
| 90 | if (textParts.length === 1) return textParts[0].text |
| 91 | |
| 92 | return textParts.map((part) => part.text).join('\n') |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Extracts the first function call from a Gemini response candidate |
no test coverage detected