* Returns true if the response is valid, false otherwise.
(response: GenerateContentResponse)
| 29 | * Returns true if the response is valid, false otherwise. |
| 30 | */ |
| 31 | function isValidResponse(response: GenerateContentResponse): boolean { |
| 32 | if (response.candidates === undefined || response.candidates.length === 0) { |
| 33 | return false; |
| 34 | } |
| 35 | const content = response.candidates[0]?.content; |
| 36 | if (content === undefined) { |
| 37 | return false; |
| 38 | } |
| 39 | return isValidContent(content); |
| 40 | } |
| 41 | |
| 42 | function isValidContent(content: Content): boolean { |
| 43 | if (content.parts === undefined || content.parts.length === 0) { |
no test coverage detected