Skip to content

Commit

Permalink
Update ktfmt (#156)
Browse files Browse the repository at this point in the history
Per [b/343255536](https://b.corp.google.com/issues/343255536),

This update ktfmt to the latest version. This is needed to support a kmp
migration, and the formatting changes from `0.16.0` to `0.18.0` are
enough to pollute the kmp pr. So this change is being done separately to
help reduce the diff in kmp related changes.
  • Loading branch information
daymxn authored May 28, 2024
1 parent 8868baa commit 77501f5
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 90 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {
id("org.jetbrains.dokka") version "1.8.20" apply false
kotlin("android") version "1.8.22" apply false
kotlin("plugin.serialization") version "1.8.22" apply false
id("com.ncorti.ktfmt.gradle") version "0.16.0" apply false
id("com.ncorti.ktfmt.gradle") version "0.18.0" apply false
id("license-plugin")
id("multi-project-plugin")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ internal constructor(
private val requestOptions: RequestOptions,
httpEngine: HttpClientEngine,
private val apiClient: String,
private val headerProvider: HeaderProvider?
private val headerProvider: HeaderProvider?,
) {

constructor(
key: String,
model: String,
requestOptions: RequestOptions,
apiClient: String,
headerProvider: HeaderProvider? = null
headerProvider: HeaderProvider? = null,
) : this(key, model, requestOptions, OkHttp.create(), apiClient, headerProvider)

private val model = fullModelName(model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sealed interface Response
data class GenerateContentResponse(
val candidates: List<Candidate>? = null,
val promptFeedback: PromptFeedback? = null,
val usageMetadata: UsageMetadata? = null
val usageMetadata: UsageMetadata? = null,
) : Response

@Serializable
Expand All @@ -40,5 +40,5 @@ data class CountTokensResponse(val totalTokens: Int, val totalBillableCharacters
data class UsageMetadata(
val promptTokenCount: Int? = null,
val candidatesTokenCount: Int? = null,
val totalTokenCount: Int? = null
val totalTokenCount: Int? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ data class FunctionCallingConfig(val mode: Mode) {
}

@Serializable
data class FunctionDeclaration(
val name: String,
val description: String,
val parameters: Schema,
)
data class FunctionDeclaration(val name: String, val description: String, val parameters: Schema)

@Serializable
data class Schema(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ data class CitationSources(
val startIndex: Int = 0,
val endIndex: Int,
val uri: String,
val license: String? = null
val license: String? = null,
)

@Serializable
Expand Down Expand Up @@ -138,10 +138,6 @@ enum class FinishReason {
}

@Serializable
data class GRpcError(
val code: Int,
val message: String,
val details: List<GRpcErrorDetails>,
)
data class GRpcError(val code: Int, val message: String, val details: List<GRpcErrorDetails>)

@Serializable data class GRpcErrorDetails(val reason: String? = null)
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,10 @@ data class Content(@EncodeDefault val role: String? = "user", val parts: List<Pa
@Serializable
data class FileData(
@SerialName("mime_type") val mimeType: String,
@SerialName("file_uri") val fileUri: String
@SerialName("file_uri") val fileUri: String,
)

@Serializable
data class Blob(
@SerialName("mime_type") val mimeType: String,
val data: Base64,
)
@Serializable data class Blob(@SerialName("mime_type") val mimeType: String, val data: Base64)

@Serializable
data class SafetySetting(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class FirstOrdinalSerializer<T : Enum<T>>(private val enumClass: KClass<T>) : KS
|GitHub to bring it to our attention:
|https://github.com/google/google-ai-android
"""
.trimMargin()
.trimMargin(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ internal class RequestFormatTests {
RequestOptions(),
mockEngine,
"genai-android/${BuildConfig.VERSION_NAME}",
null
null,
)

withTimeout(5.seconds) {
Expand All @@ -122,7 +122,7 @@ internal class RequestFormatTests {
RequestOptions(endpoint = "https://my.custom.endpoint"),
mockEngine,
TEST_CLIENT_ID,
null
null,
)

withTimeout(5.seconds) {
Expand All @@ -149,7 +149,7 @@ internal class RequestFormatTests {
RequestOptions(),
mockEngine,
TEST_CLIENT_ID,
null
null,
)

withTimeout(5.seconds) {
Expand Down Expand Up @@ -179,7 +179,7 @@ internal class RequestFormatTests {
RequestOptions(),
mockEngine,
TEST_CLIENT_ID,
null
null,
)

withTimeout(5.seconds) { controller.countTokens(textCountTokenRequest("cats")) }
Expand All @@ -203,7 +203,7 @@ internal class RequestFormatTests {
RequestOptions(),
mockEngine,
TEST_CLIENT_ID,
null
null,
)

withTimeout(5.seconds) { controller.countTokens(textCountTokenRequest("cats")) }
Expand All @@ -226,7 +226,7 @@ internal class RequestFormatTests {
RequestOptions(),
mockEngine,
TEST_CLIENT_ID,
null
null,
)

withTimeout(5.seconds) {
Expand All @@ -239,7 +239,7 @@ internal class RequestFormatTests {
ToolConfig(
functionCallingConfig =
FunctionCallingConfig(mode = FunctionCallingConfig.Mode.AUTO)
)
),
)
)
.collect { channel.close() }
Expand Down Expand Up @@ -273,7 +273,7 @@ internal class RequestFormatTests {
RequestOptions(),
mockEngine,
TEST_CLIENT_ID,
testHeaderProvider
testHeaderProvider,
)

withTimeout(5.seconds) { controller.countTokens(textCountTokenRequest("cats")) }
Expand Down Expand Up @@ -307,7 +307,7 @@ internal class RequestFormatTests {
RequestOptions(),
mockEngine,
TEST_CLIENT_ID,
testHeaderProvider
testHeaderProvider,
)

withTimeout(5.seconds) { controller.countTokens(textCountTokenRequest("cats")) }
Expand All @@ -333,7 +333,7 @@ internal class ModelNamingTests(private val modelName: String, private val actua
RequestOptions(),
mockEngine,
TEST_CLIENT_ID,
null
null,
)

withTimeout(5.seconds) {
Expand Down Expand Up @@ -363,7 +363,7 @@ internal class ModelNamingTests(private val modelName: String, private val actua
fun textGenerateContentRequest(prompt: String) =
GenerateContentRequest(
model = "unused",
contents = listOf(Content(parts = listOf(TextPart(prompt))))
contents = listOf(Content(parts = listOf(TextPart(prompt)))),
)

fun textCountTokenRequest(prompt: String) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ internal typealias CommonTest = suspend CommonTestScope.() -> Unit
internal fun commonTest(
status: HttpStatusCode = HttpStatusCode.OK,
requestOptions: RequestOptions = RequestOptions(),
block: CommonTest
block: CommonTest,
) = doBlocking {
val channel = ByteChannel(autoFlush = true)
val mockEngine = MockEngine {
Expand All @@ -113,7 +113,7 @@ internal fun commonTest(
requestOptions,
mockEngine,
TEST_CLIENT_ID,
null
null,
)
CommonTestScope(channel, apiController).block()
}
Expand All @@ -132,7 +132,7 @@ internal fun commonTest(
internal fun goldenStreamingFile(
name: String,
httpStatusCode: HttpStatusCode = HttpStatusCode.OK,
block: CommonTest
block: CommonTest,
) = doBlocking {
val goldenFile = loadGoldenFile("streaming/$name")
val messages = goldenFile.readLines().filter { it.isNotBlank() }
Expand Down Expand Up @@ -162,7 +162,7 @@ internal fun goldenStreamingFile(
internal fun goldenUnaryFile(
name: String,
httpStatusCode: HttpStatusCode = HttpStatusCode.OK,
block: CommonTest
block: CommonTest,
) =
commonTest(httpStatusCode) {
val goldenFile = loadGoldenFile("unary/$name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ internal fun com.google.ai.client.generativeai.type.GenerationConfig.toInternal(
candidateCount = candidateCount,
maxOutputTokens = maxOutputTokens,
stopSequences = stopSequences,
responseMimeType = responseMimeType
responseMimeType = responseMimeType,
)

internal fun com.google.ai.client.generativeai.type.HarmCategory.toInternal() =
Expand Down Expand Up @@ -203,10 +203,7 @@ internal fun Part.toPublic(): com.google.ai.client.generativeai.type.Part {
functionResponse.response.toPublic(),
)
is FileDataPart ->
com.google.ai.client.generativeai.type.FileDataPart(
fileData.fileUri,
fileData.mimeType,
)
com.google.ai.client.generativeai.type.FileDataPart(fileData.fileUri, fileData.mimeType)
else ->
throw SerializationException(
"Unsupported part type \"${javaClass.simpleName}\" provided. This model may not be supported by this SDK."
Expand Down Expand Up @@ -274,7 +271,7 @@ internal fun GenerateContentResponse.toPublic() =
com.google.ai.client.generativeai.type.GenerateContentResponse(
candidates?.map { it.toPublic() }.orEmpty(),
promptFeedback?.toPublic(),
usageMetadata?.toPublic()
usageMetadata?.toPublic(),
)

internal fun CountTokensResponse.toPublic() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal constructor(
val content: Content,
val safetyRatings: List<SafetyRating>,
val citationMetadata: List<CitationMetadata>,
val finishReason: FinishReason?
val finishReason: FinishReason?,
)

/** Rating for a particular [HarmCategory] with a provided [HarmProbability]. */
Expand All @@ -44,7 +44,7 @@ class CitationMetadata(
val startIndex: Int = 0,
val endIndex: Int,
val uri: String,
val license: String? = null
val license: String? = null,
)

/** The reason for content finishing. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import android.util.Log
class GenerateContentResponse(
val candidates: List<Candidate>,
val promptFeedback: PromptFeedback?,
val usageMetadata: UsageMetadata?
val usageMetadata: UsageMetadata?,
) {
/** Convenience field representing all the text parts in the response, if they exists. */
val text: String? by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private constructor(
val candidateCount: Int?,
val maxOutputTokens: Int?,
val stopSequences: List<String>?,
val responseMimeType: String?
val responseMimeType: String?,
) {

class Builder {
Expand All @@ -57,7 +57,7 @@ private constructor(
candidateCount = candidateCount,
maxOutputTokens = maxOutputTokens,
stopSequences = stopSequences,
responseMimeType = responseMimeType
responseMimeType = responseMimeType,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ package com.google.ai.client.generativeai.type
* @param blockReason The reason that content was blocked, if at all.
* @param safetyRatings A list of relevant [SafetyRating]s.
*/
class PromptFeedback(
val blockReason: BlockReason?,
val safetyRatings: List<SafetyRating>,
)
class PromptFeedback(val blockReason: BlockReason?, val safetyRatings: List<SafetyRating>)

/** Describes why content was blocked. */
enum class BlockReason {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,10 @@ import kotlin.time.toDuration
* first response.
* @property apiVersion the api endpoint to call.
*/
class RequestOptions(
val timeout: Duration,
val apiVersion: String = "v1beta",
) {
class RequestOptions(val timeout: Duration, val apiVersion: String = "v1beta") {
@JvmOverloads
constructor(
timeout: Long? = Long.MAX_VALUE,
apiVersion: String = "v1beta",
) : this(
(timeout ?: Long.MAX_VALUE).toDuration(DurationUnit.MILLISECONDS),
apiVersion,
)
) : this((timeout ?: Long.MAX_VALUE).toDuration(DurationUnit.MILLISECONDS), apiVersion)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ package com.google.ai.client.generativeai.type
*
* @param functionDeclarations The set of functions that this tool allows the model access to
*/
class Tool(
val functionDeclarations: List<FunctionDeclaration>,
)
class Tool(val functionDeclarations: List<FunctionDeclaration>)
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ package com.google.ai.client.generativeai.type
class UsageMetadata(
val promptTokenCount: Int,
val candidatesTokenCount: Int,
val totalTokenCount: Int
val totalTokenCount: Int,
)
Loading

0 comments on commit 77501f5

Please sign in to comment.