Skip to content

Commit

Permalink
replaced functionCall with functionCalls (#137)
Browse files Browse the repository at this point in the history
Co-authored-by: David Motsonashvili <davidmotson@google.com>
Co-authored-by: Rodrigo Lazo <rlazo@users.noreply.github.com>
  • Loading branch information
3 people authored May 6, 2024
1 parent c2512bc commit 21be798
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions .changes/common/bath-advertisement-attempt-car.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"MINOR","changes":["Add GenerateContentResponse#functionCalls and mark GenerateContentResponse#functionCall deprecated"]}
1 change: 1 addition & 0 deletions .changes/generativeai/badge-cake-arithmetic-cook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"MINOR","changes":["Add GenerateContentResponse#functionCalls and mark GenerateContentResponse#functionCall deprecated"]}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,18 @@ class GenerateContentResponse(
/** Convenience field representing the first text part in the response, if it exists. */
val text: String? by lazy { firstPartAs<TextPart>()?.text }

/** Convenience field representing the first text part in the response, if it exists. */
/** Convenience field representing the first function call part in the request, if it exists */
@Deprecated("Use functionCallParts instead", ReplaceWith("functionCallParts"))
val functionCall: FunctionCallPart? by lazy { firstPartAs() }

/** Convenience field representing the first text part in the response, if it exists. */
/** Convenience field to get all the function call parts in the request, if they exist */
val functionCalls: List<FunctionCallPart> by lazy {
candidates.first().content.parts.filterIsInstance<FunctionCallPart>()
}

/**
* Convenience field representing the first function response part in the response, if it exists.
*/
val functionResponse: FunctionResponsePart? by lazy { firstPartAs() }

private inline fun <reified T : Part> firstPartAs(): T? {
Expand Down

0 comments on commit 21be798

Please sign in to comment.