From d22b03e84ece598b22de15fb087ae1738ee91c9a Mon Sep 17 00:00:00 2001 From: Rodrigo Lazo Paz Date: Wed, 13 Dec 2023 10:55:38 -0500 Subject: [PATCH 1/3] Add `x-goog-api-client` header --- generativeai/build.gradle.kts | 4 ++++ .../ai/client/generativeai/internal/api/APIController.kt | 2 ++ 2 files changed, 6 insertions(+) diff --git a/generativeai/build.gradle.kts b/generativeai/build.gradle.kts index 4b93220f..260c0c67 100644 --- a/generativeai/build.gradle.kts +++ b/generativeai/build.gradle.kts @@ -32,11 +32,15 @@ android { namespace = "com.google.ai.client.generativeai" compileSdk = 34 + buildFeatures.buildConfig = true + defaultConfig { minSdk = 21 testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles("consumer-rules.pro") + + buildConfigField("String", "VERSION_NAME", "\"${project.version.toString()}\"") } publishing { diff --git a/generativeai/src/main/java/com/google/ai/client/generativeai/internal/api/APIController.kt b/generativeai/src/main/java/com/google/ai/client/generativeai/internal/api/APIController.kt index de299165..bff0a698 100644 --- a/generativeai/src/main/java/com/google/ai/client/generativeai/internal/api/APIController.kt +++ b/generativeai/src/main/java/com/google/ai/client/generativeai/internal/api/APIController.kt @@ -18,6 +18,7 @@ package com.google.ai.client.generativeai.internal.api import com.google.ai.client.generativeai.internal.util.decodeToFlow import com.google.ai.client.generativeai.type.ServerException +import com.google.ai.client.generativeai.BuildConfig import io.ktor.client.HttpClient import io.ktor.client.call.body import io.ktor.client.engine.HttpClientEngine @@ -101,6 +102,7 @@ internal class APIController( } contentType(ContentType.Application.Json) header("x-goog-api-key", key) + header("x-goog-api-client", "genai-kotlin/${BuildConfig.VERSION_NAME}") } } From 2d8023b7ba3a8a9e49527061f5ea1476bb616616 Mon Sep 17 00:00:00 2001 From: Rodrigo Lazo Paz Date: Wed, 13 Dec 2023 11:00:30 -0500 Subject: [PATCH 2/3] use `android` instead of `kotlin` --- .../google/ai/client/generativeai/internal/api/APIController.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generativeai/src/main/java/com/google/ai/client/generativeai/internal/api/APIController.kt b/generativeai/src/main/java/com/google/ai/client/generativeai/internal/api/APIController.kt index bff0a698..9594f112 100644 --- a/generativeai/src/main/java/com/google/ai/client/generativeai/internal/api/APIController.kt +++ b/generativeai/src/main/java/com/google/ai/client/generativeai/internal/api/APIController.kt @@ -102,7 +102,7 @@ internal class APIController( } contentType(ContentType.Application.Json) header("x-goog-api-key", key) - header("x-goog-api-client", "genai-kotlin/${BuildConfig.VERSION_NAME}") + header("x-goog-api-client", "genai-android/${BuildConfig.VERSION_NAME}") } } From b528d1c50affc95d766c4111ee9a8d0f39bc85ec Mon Sep 17 00:00:00 2001 From: Rodrigo Lazo Paz Date: Wed, 13 Dec 2023 11:02:45 -0500 Subject: [PATCH 3/3] Fix format --- .../google/ai/client/generativeai/internal/api/APIController.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generativeai/src/main/java/com/google/ai/client/generativeai/internal/api/APIController.kt b/generativeai/src/main/java/com/google/ai/client/generativeai/internal/api/APIController.kt index 9594f112..73a8c239 100644 --- a/generativeai/src/main/java/com/google/ai/client/generativeai/internal/api/APIController.kt +++ b/generativeai/src/main/java/com/google/ai/client/generativeai/internal/api/APIController.kt @@ -16,9 +16,9 @@ package com.google.ai.client.generativeai.internal.api +import com.google.ai.client.generativeai.BuildConfig import com.google.ai.client.generativeai.internal.util.decodeToFlow import com.google.ai.client.generativeai.type.ServerException -import com.google.ai.client.generativeai.BuildConfig import io.ktor.client.HttpClient import io.ktor.client.call.body import io.ktor.client.engine.HttpClientEngine