Skip to content

Commit

Permalink
Merge branch 'main' into daymon-simplify-funciton-calling
Browse files Browse the repository at this point in the history
  • Loading branch information
rlazo authored Jun 17, 2024
2 parents 687db30 + d8139ed commit 45a233e
Show file tree
Hide file tree
Showing 6 changed files with 1,507 additions and 1 deletion.
1,429 changes: 1,429 additions & 0 deletions api/common/0.7.1.api

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion common/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.7.0
version=0.7.1
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import kotlinx.serialization.json.Json
internal val JSON = Json {
ignoreUnknownKeys = true
prettyPrint = false
isLenient = true
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.google.ai.client.generativeai.common.shared.FunctionCallPart
import com.google.ai.client.generativeai.common.shared.HarmCategory
import com.google.ai.client.generativeai.common.shared.TextPart
import com.google.ai.client.generativeai.common.util.goldenUnaryFile
import com.google.ai.client.generativeai.common.util.shouldNotBeNullOrEmpty
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.matchers.collections.shouldNotBeEmpty
import io.kotest.matchers.nulls.shouldNotBeNull
Expand Down Expand Up @@ -313,4 +314,21 @@ internal class UnarySnapshotTests {
callPart.functionCall.args["season"] shouldBe null
}
}

@Test
fun `function call contains json literal`() =
goldenUnaryFile("success-function-call-json-literal.json") {
withTimeout(testTimeout) {
val response = apiController.generateContent(textGenerateContentRequest("prompt"))
val content = response.candidates.shouldNotBeNullOrEmpty().first().content
val callPart =
content.let {
it.shouldNotBeNull()
it.parts.shouldNotBeEmpty()
it.parts.first().shouldBeInstanceOf<FunctionCallPart>()
}

callPart.functionCall.args["current"] shouldBe "true"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import com.google.ai.client.generativeai.common.RequestOptions
import com.google.ai.client.generativeai.common.server.Candidate
import com.google.ai.client.generativeai.common.shared.Content
import com.google.ai.client.generativeai.common.shared.TextPart
import io.kotest.matchers.collections.shouldNotBeEmpty
import io.kotest.matchers.nulls.shouldNotBeNull
import io.ktor.client.engine.mock.MockEngine
import io.ktor.client.engine.mock.respond
import io.ktor.http.HttpHeaders
Expand Down Expand Up @@ -184,3 +186,14 @@ internal fun loadGoldenFile(path: String): File = loadResourceFile("golden-files

/** Loads a file from the test resources directory. */
internal fun loadResourceFile(path: String) = File("src/test/resources/$path")

/**
* Ensures that a collection is neither null or empty.
*
* Syntax sugar for [shouldNotBeNull] and [shouldNotBeEmpty].
*/
inline fun <reified T : Any> Collection<T>?.shouldNotBeNullOrEmpty(): Collection<T> {
shouldNotBeNull()
shouldNotBeEmpty()
return this
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"candidates": [
{
"content": {
"parts": [
{
"functionCall": {
"name": "functionName",
"args": {
"original_title": "String",
"current": true
}
}
}
],
"role": "model"
},
"finishReason": "STOP",
"index": 0,
"safetyRatings": [
{
"category": "HARM_CATEGORY_HARASSMENT",
"probability": "NEGLIGIBLE"
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"probability": "NEGLIGIBLE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"probability": "NEGLIGIBLE"
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"probability": "NEGLIGIBLE"
}
]
}
],
"usageMetadata": {
"promptTokenCount": 774,
"candidatesTokenCount": 4176,
"totalTokenCount": 4950
}
}

0 comments on commit 45a233e

Please sign in to comment.