google-gemini / generative-ai-android Goto Github PK
View Code? Open in Web Editor NEWGoogle AI SDK for Android
Home Page: https://ai.google.dev/
License: Apache License 2.0
Google AI SDK for Android
Home Page: https://ai.google.dev/
License: Apache License 2.0
I'm attempting to use the generativeai library version 0.2.2 in my project . but i get this error Could not find com.google.ai.client.generativeai:generativeai:0.2.2.
implementation "com.google.ai.client.generativeai:generativeai:0.1.1" appears incompatible version of Kotlin issue:Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1. But I cannot upgrade kotlin & gradle in my project.
Hello, we solved the problem mentioned in #17 by adding the relevant line to the proguard file, but it does not work in any version after v.0.2.0. We continue to receive the same error in the release version. I tried all versions one by one and tested it on the internal channel, only v0.2.0 works.
In the recently released v0.2.1
, while using Chat
methods, a server error like following occurs even if we provide a role
.
please use a valid role: user, model
After I checked a diff between v0.2.0
← v0.2.1
, observed following issues:
role
parameter has been removed from all methods of Chat
class. (This is not issue).role
field in internal class Content
changed from null
to "user"
Changing a default value in the above internal class is ineffective since it's not a public API that will be instantiated from a public API. Instead, when a public Content
is converted to an internal Content
, it will be replaced by a value null
since the same default value has not been provided to the public class Content
. At the time of conversion from public type to internal type, this role
's default value will be lost by the following code:
https://github.com/google/generative-ai-android/blob/7abb340e595a042eed2f4f539e57df4007736fde/generativeai/src/main/java/com/google/ai/client/generativeai/internal/util/conversions.kt#L49-L50
So as per my understanding, the default value for role
is needed in the following files:
OR
We can also make changes in a conversion function as follows:
internal fun com.google.ai.client.generativeai.type.Content.toInternal() =
- Content(this.role, this.parts.map { it.toInternal() })
+ Content(this.role ?: "user", this.parts.map { it.toInternal() })
This library seems to have some relatively unnecessary android dependencies, which prevent the library from being used in a server-side JVM environment. This issue can request/track the removal of Android dependencies from the library, making this library into something like generative-ai-jvm or generative-ai-kotlin.
I'd like to propose the addition of a Function Calling feature to enhance communication between Android device and the model
Hey, I am using Gemini AI and in the release build, I get generativeai.type.InvalidStateException.
I know this is not the right place to ask the question but I google things and I won't able to find any.
Here is the code
GeminiModule
@Module
@InstallIn(SingletonComponent::class)
object GeminiModule {
@Provides
@Singleton
fun provideGemini(): GenerativeModel {
val harassmentSafety =
SafetySetting(HarmCategory.HARASSMENT, BlockThreshold.ONLY_HIGH)
val hateSpeechSafety =
SafetySetting(HarmCategory.HATE_SPEECH, BlockThreshold.MEDIUM_AND_ABOVE)
val config = generationConfig {
stopSequences = listOf(
"fuck",
"sex",
)
temperature = 0.9f
topK = 16
topP = 0.1f
}
return GenerativeModel(
modelName = "gemini-pro",
apiKey = BuildConfig.apiKey,
generationConfig = config,
safetySettings = listOf(
harassmentSafety, hateSpeechSafety
)
)
}
}
and it's viewModel
@HiltViewModel
class ChatViewModel @Inject constructor(
private val generativeModel: GenerativeModel,
private val case: ChatUseCases,
private val mapper: ChatMessageToModelMapper
) : ViewModel() {
private var chat: Chat? = null
private val _uiState: MutableState<ChatUiState> =
mutableStateOf(ChatUiState())
val uiState: State<ChatUiState> = _uiState
private val _isLoading = mutableStateOf<Boolean>(false)
val isLoading: State<Boolean> get() = _isLoading
private var job: Job? = null
init {
getChat()
}
private fun getChat() = viewModelScope.launch {
val history = mapper.mapFromEntityList(case.getAllChat.invoke()).toContent()
chat = generativeModel.startChat(history)
_uiState.value = ChatUiState(
chat?.history?.map { content ->
// Map the initial messages
ChatMessage(
text = content.parts.first().asTextOrNull() ?: "",
participant = if (content.role == "user") Participant.USER else Participant.MODEL,
)
} ?: emptyList()
)
}
fun cancelJob() {
try {
_isLoading.value = false
job?.cancel()
} catch (e: Exception) {
Log.e(TAGS.BIT_ERROR.name, "cancelJob: ${e.localizedMessage}")
}
}
fun sendMessage(userMessage: String) {
// Add a pending message
val userInput = ChatMessage(
text = userMessage, participant = Participant.USER,
)
_isLoading.value = true
_uiState.value.addMessage(
userInput
)
job = viewModelScope.launch {
try {
val response = chat!!.sendMessage(userMessage)
_isLoading.value = false
response.text?.let { modelResponse ->
val modelRes = ChatMessage(
text = modelResponse, participant = Participant.MODEL
)
mapper.mapToEntityList(
listOf(
_uiState.value.getLastMessage()!!
.copy(
linkedId = modelRes.id
),
modelRes.copy(
linkedId = _uiState.value.getLastMessage()!!.id
)
)
).forEach {
case.insertChat.invoke(it)
}
_uiState.value.addMessage(
modelRes
)
}
} catch (e: Exception) {
Log.d("AAA", "sendMessage: $e")
if (e is PromptBlockedException) {
_uiState.value.addMessage(
ChatMessage(
text = "The input you provided contains offensive language, which goes against our community guidelines " +
"and standards. Please refrain from using inappropriate language and ensure that your input is " +
"respectful and adheres to our guidelines. If you have any questions or concerns, feel free " +
"to contact our support team.",
participant = Participant.ERROR
)
)
return@launch
}
_uiState.value.addMessage(
ChatMessage(
text = e.localizedMessage ?: "Unknown error",
participant = Participant.ERROR
)
)
} finally {
_isLoading.value = false
job = null
}
}
}
}
After a request fails once, subsequent requests will fail every time.
java.util.concurrent.CancellationException: Parent job is Canceled error reported
The log is as follows:
2024-02-26 21:43:10.633 32688-2795 System.err W com.google.ai.client.generativeai.type.UnknownException: Something unexpected happened.
2024-02-26 21:43:10.634 32688-2795 System.err W at com.google.ai.client.generativeai.type.GoogleGenerativeAIException$Companion.from(Exceptions.kt:45)
2024-02-26 21:43:10.634 32688-2795 System.err W at com.google.ai.client.generativeai.GenerativeModel.generateContent(GenerativeModel.kt:88)
2024-02-26 21:43:10.634 32688-2795 System.err W at com.google.ai.client.generativeai.GenerativeModel$generateContent$1.invokeSuspend(Unknown Source:15)
2024-02-26 21:43:10.634 32688-2795 System.err W at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2024-02-26 21:43:10.634 32688-2795 System.err W at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
2024-02-26 21:43:10.634 32688-2795 System.err W at android.os.Handler.handleCallback(Handler.java:888)
2024-02-26 21:43:10.634 32688-2795 System.err W at android.os.Handler.dispatchMessage(Handler.java:100)
2024-02-26 21:43:10.634 32688-2795 System.err W at android.os.Looper.loop(Looper.java:213)
2024-02-26 21:43:10.634 32688-2795 System.err W at android.app.ActivityThread.main(ActivityThread.java:8178)
2024-02-26 21:43:10.634 32688-2795 System.err W at java.lang.reflect.Method.invoke(Native Method)
2024-02-26 21:43:10.634 32688-2795 System.err W at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
2024-02-26 21:43:10.634 32688-2795 System.err W at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
2024-02-26 21:43:10.634 32688-2795 System.err W Caused by: java.util.concurrent.CancellationException: Parent job is Cancelled
2024-02-26 21:43:10.634 32688-2795 System.err W at io.ktor.client.engine.UtilsKt$attachToUserJob$cleanupHandler$1.invoke(Utils.kt:97)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.engine.UtilsKt$attachToUserJob$cleanupHandler$1.invoke(Utils.kt:95)
2024-02-26 21:43:10.635 32688-2795 System.err W at kotlinx.coroutines.JobSupport.invokeOnCompletion(JobSupport.kt:1529)
2024-02-26 21:43:10.635 32688-2795 System.err W at kotlinx.coroutines.Job$DefaultImpls.invokeOnCompletion$default(Job.kt:357)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.engine.HttpClientEngineKt.createCallContext(HttpClientEngine.kt:166)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.engine.HttpClientEngine$DefaultImpls.executeWithinCallContext(HttpClientEngine.kt:91)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.engine.HttpClientEngine$DefaultImpls.access$executeWithinCallContext(HttpClientEngine.kt:24)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.engine.HttpClientEngine$install$1.invokeSuspend(HttpClientEngine.kt:70)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.engine.HttpClientEngine$install$1.invoke(Unknown Source:15)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.engine.HttpClientEngine$install$1.invoke(Unknown Source:4)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:98)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.plugins.HttpSend$DefaultSender.execute(HttpSend.kt:138)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.plugins.HttpTimeout$Plugin$install$1.invokeSuspend(HttpTimeout.kt:174)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.plugins.HttpTimeout$Plugin$install$1.invoke(Unknown Source:15)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.plugins.HttpTimeout$Plugin$install$1.invoke(Unknown Source:6)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.plugins.HttpSend$InterceptedSender.execute(HttpSend.kt:116)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.plugins.HttpRedirect$Plugin$install$1.invokeSuspend(HttpRedirect.kt:64)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.plugins.HttpRedirect$Plugin$install$1.invoke(Unknown Source:15)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.plugins.HttpRedirect$Plugin$install$1.invoke(Unknown Source:6)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.plugins.HttpSend$InterceptedSender.execute(HttpSend.kt:116)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.plugins.HttpCallValidator$Companion$install$3.invokeSuspend(HttpCallValidator.kt:151)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.plugins.HttpCallValidator$Companion$install$3.invoke(Unknown Source:13)
2024-02-26 21:43:10.635 32688-2795 System.err W at io.ktor.client.plugins.HttpCallValidator$Companion$install$3.invoke(Unknown Source:6)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.client.plugins.HttpSend$InterceptedSender.execute(HttpSend.kt:116)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.client.plugins.HttpSend$Plugin$install$1.invokeSuspend(HttpSend.kt:104)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.client.plugins.HttpSend$Plugin$install$1.invoke(Unknown Source:15)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.client.plugins.HttpSend$Plugin$install$1.invoke(Unknown Source:4)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.proceedWith(SuspendFunctionGun.kt:88)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.client.plugins.DefaultTransformKt$defaultTransformers$1.invokeSuspend(DefaultTransform.kt:57)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.client.plugins.DefaultTransformKt$defaultTransformers$1.invoke(Unknown Source:11)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.client.plugins.DefaultTransformKt$defaultTransformers$1.invoke(Unknown Source:4)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.proceedWith(SuspendFunctionGun.kt:88)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.client.plugins.contentnegotiation.ContentNegotiation$Plugin$install$1.invokeSuspend(ContentNegotiation.kt:252)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.client.plugins.contentnegotiation.ContentNegotiation$Plugin$install$1.invoke(Unknown Source:11)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.client.plugins.contentnegotiation.ContentNegotiation$Plugin$install$1.invoke(Unknown Source:4)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.proceedWith(SuspendFunctionGun.kt:88)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.client.plugins.HttpCallValidator$Companion$install$1.invokeSuspend(HttpCallValidator.kt:130)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.client.plugins.HttpCallValidator$Companion$install$1.invoke(Unknown Source:13)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.client.plugins.HttpCallValidator$Companion$install$1.invoke(Unknown Source:4)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.client.plugins.HttpRequestLifecycle$Plugin$install$1.invokeSuspend(HttpRequestLifecycle.kt:38)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.client.plugins.HttpRequestLifecycle$Plugin$install$1.invoke(Unknown Source:11)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.client.plugins.HttpRequestLifecycle$Plugin$install$1.invoke(Unknown Source:4)
2024-02-26 21:43:10.636 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
2024-02-26 21:43:10.637 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
2024-02-26 21:43:10.637 32688-2795 System.err W at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:98)
2024-02-26 21:43:10.637 32688-2795 System.err W at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
2024-02-26 21:43:10.637 32688-2795 System.err W at io.ktor.client.HttpClient.execute$ktor_client_core(HttpClient.kt:191)
2024-02-26 21:43:10.637 32688-2795 System.err W at io.ktor.client.statement.HttpStatement.executeUnsafe(HttpStatement.kt:108)
2024-02-26 21:43:10.637 32688-2795 System.err W at io.ktor.client.statement.HttpStatement.execute(HttpStatement.kt:47)
2024-02-26 21:43:10.637 32688-2795 System.err W at io.ktor.client.statement.HttpStatement.execute(HttpStatement.kt:62)
2024-02-26 21:43:10.637 32688-2795 System.err W at com.google.ai.client.generativeai.internal.api.APIController.generateContent(APIController.kt:185)
2024-02-26 21:43:10.637 32688-2795 System.err W at com.google.ai.client.generativeai.GenerativeModel.generateContent(GenerativeModel.kt:86)
2024-02-26 21:43:10.637 32688-2795 System.err W at com.google.ai.client.generativeai.Chat.sendMessage(Chat.kt:60)
2024-02-26 21:43:10.637 32688-2795 System.err W at com.google.ai.client.generativeai.java.ChatFutures$FuturesImpl$sendMessage$1.invokeSuspend(ChatFutures.kt:54)
2024-02-26 21:43:10.637 32688-2795 System.err W at com.google.ai.client.generativeai.java.ChatFutures$FuturesImpl$sendMessage$1.invoke(Unknown Source:8)
2024-02-26 21:43:10.637 32688-2795 System.err W at com.google.ai.client.generativeai.java.ChatFutures$FuturesImpl$sendMessage$1.invoke(Unknown Source:4)
2024-02-26 21:43:10.637 32688-2795 System.err W at kotlinx.coroutines.intrinsics.UndispatchedKt.startCoroutineUndispatched(Undispatched.kt:44)
2024-02-26 21:43:10.637 32688-2795 System.err W at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:112)
2024-02-26 21:43:10.637 32688-2795 System.err W at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
2024-02-26 21:43:10.637 32688-2795 System.err W at kotlinx.coroutines.BuildersKt__Builders_commonKt.async(Builders.common.kt:91)
2024-02-26 21:43:10.637 32688-2795 System.err W at kotlinx.coroutines.BuildersKt.async(Unknown Source:1)
2024-02-26 21:43:10.637 32688-2795 System.err W at androidx.concurrent.futures.SuspendToFutureAdapter.launchFuture(SuspendToFutureAdapter.kt:86)
2024-02-26 21:43:10.637 32688-2795 System.err W at androidx.concurrent.futures.SuspendToFutureAdapter.launchFuture$default(SuspendToFutureAdapter.kt:81)
2024-02-26 21:43:10.637 32688-2795 System.err W at com.google.ai.client.generativeai.java.ChatFutures$FuturesImpl.sendMessage(ChatFutures.kt:54)
I got the error in my compose for desktop project when implementation ** com.google.ai.client.generativeai:generativeai:0.5.0.**。
my build.gradle.kts
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
plugins {
kotlin("jvm")
id("org.jetbrains.compose")
}
group = "com.pop.composedemo"
version = "1.0-SNAPSHOT"
repositories {
google()
mavenCentral()
gradlePluginPortal()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
dependencies {
implementation(compose.desktop.currentOs)
implementation(libs.gson)
implementation(libs.generativeai)
}
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "demo"
packageVersion = "1.0.0"
}
}
}
and my settings.gradle.kts
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
plugins {
kotlin("jvm").version(extra["kotlin.version"] as String)
id("org.jetbrains.compose").version(extra["compose.version"] as String)
}
}
rootProject.name = "demo"
Migrate to Kotlin Multiplatform in order to target more platforms
private fun imageConvertText(uri: Uri) {
loadingDialog.show()
try {
Log.d("result", "bitmap start")
val bitmap =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val source = ImageDecoder.createSource(this.contentResolver, uri)
ImageDecoder.decodeBitmap(source)
} else {
MediaStore.Images.Media.getBitmap(this.contentResolver, uri)
}
val baos = ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos)
val size = baos.toByteArray()
Log.d("result", size.size.toString())
Log.d("result", "bitmap completed")
val inputContent = content {
image(bitmap)
text("Read text from image")
}
Log.d("result", "api start")
try {
var mainResult = ""
CoroutineScope(Dispatchers.IO).launch {
generativeModel.generateContentStream(inputContent)
.collect { response ->
val result = response.text.toString().trim()
Log.d("result", "api end")
runOnUiThread {
loadingDialog.dismiss()
if (result.isNotEmpty()) {
mainResult += result
Log.d("result", "set Text")
menuBinding.outputImg.setImageBitmap(null)
menuBinding.outputImg.setImageBitmap(bitmap)
menuBinding.outputImg.visible()
menuBinding.edNumber.setText(mainResult)
} else {
Log.d("result", "No text found in the photo")
menuBinding.outputImg.gone()
menuBinding.outputImg.setImageBitmap(null)
showToast("No text found in the photo")
}
}
}
}
} catch (e: Exception) {
e.printStackTrace()
loadingDialog.dismiss()
showToast(e.message.toString())
}
} catch (e: Exception) {
e.printStackTrace()
loadingDialog.dismiss()
showToast(e.message.toString())
}
FAILURE: Build failed with an exception.
Where:
Build file 'C:\Users\14130\AndroidStudioProjects\generative-ai-android\plugins\build.gradle.kts' line: 17
What went wrong:
Plugin [id: 'org.gradle.kotlin.kotlin-dsl', version: '4.1.2'] was not found in any of the following sources:
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.
Get more help at https://help.gradle.org.
Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'org.gradle.kotlin.kotlin-dsl', version: '4.1.2'] was not found in any of the following sources:
at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)
CONFIGURE FAILED in 27s
As a programming enthusiast, I had some problems deploying projects
when will be available in Europe countries?
When testing app from Google Play console internal test channel with release build with ;
minifyEnabled true
shrinkResources true
"Something went wrong while trying to deserialize a response from the server" error occurs on Model answer
There is no Logcat info on Android Studio when it occurs.
What i tried is : Added lines below to my proguard-rules.pro
-keep class androidx.compose.ui.*.*{*;} -keep class com.google.ai.*.*{*;}
but not works
Thank you!
This issue was automatically created by Allstar.
Security Policy Violation
Project is out of compliance with Binary Artifacts policy: binaries present in source code
Rule Description
Binary Artifacts are an increased security risk in your repository. Binary artifacts cannot be reviewed, allowing the introduction of possibly obsolete or maliciously subverted executables. For more information see the Security Scorecards Documentation for Binary Artifacts.
Remediation Steps
To remediate, remove the generated executable artifacts from the repository.
Artifacts Found
Additional Information
This policy is drawn from Security Scorecards, which is a tool that scores a project's adherence to security best practices. You may wish to run a Scorecards scan directly on this repository for more details.
This issue will auto resolve when the policy is in compliance.
Issue created by Allstar. See https://github.com/ossf/allstar/ for more information. For questions specific to the repository, please contact the owner or maintainer.
A new official release because the current version does not yet contain the fix for the "API Error 400: please use a valid role: user, model error" #75 issue.
How i can get api key from user account like using auth2 or Google signin library to get api key without get it from website ate there any library for android kotlin?. Thankd
This issue was automatically created by Allstar.
Security Policy Violation
Security policy not enabled.
A SECURITY.md file can give users information about what constitutes a vulnerability and how to report one securely so that information about a bug is not publicly visible. Examples of secure reporting methods include using an issue tracker with private issue support, or encrypted email with a published key.
To fix this, add a SECURITY.md file that explains how to handle vulnerabilities found in your repository. Go to https://github.com/google-gemini/generative-ai-android/security/policy to enable.
For more information, see https://docs.github.com/en/code-security/getting-started/adding-a-security-policy-to-your-repository.
This issue will auto resolve when the policy is in compliance.
Issue created by Allstar. See https://github.com/ossf/allstar/ for more information. For questions specific to the repository, please contact the owner or maintainer.
Doesn't allow changing the HttpClient, for example adding logging, or configuring a proxy.
Ideally a Ktor engine could be passed in, or if not possible a OkHttp Call.Factory.
Is gemini-1.5-pro-latest
model available in Android SDK ?
Getting following error
API Error: models/gemini-1.5-pro-latest is not found for API version v1, or is not supported for GenerateContent. Call ListModels to see the list of available models and their supported methods.
This issue was automatically created by Allstar.
Security Policy Violation
Found 3 outside collaborators with admin access.
This policy requires users with this access to be members of the organisation. That way you can easily audit who has access to your repo, and if an account is compromised it can quickly be denied access to organization resources. To fix this you should either remove the user from repository-based access, or add them to the organization.
OR
If you don't see the Settings tab you probably don't have administrative access. Reach out to the administrators of the organisation to fix this issue.
OR
This issue will auto resolve when the policy is in compliance.
Issue created by Allstar. See https://github.com/ossf/allstar/ for more information. For questions specific to the repository, please contact the owner or maintainer.
in generativeai-android-sample
it use gradle-8.0.2
and agp
with 8.1.0
, but others with gradle-8.4
and 8.1.3
.
This issue was automatically created by Allstar.
Security Policy Violation
Dismiss stale reviews not configured for branch main
This issue will auto resolve when the policy is in compliance.
Issue created by Allstar. See https://github.com/ossf/allstar/ for more information. For questions specific to the repository, please contact the owner or maintainer.
I was trying out the SDK and got everything looking GTG, but was unable to get past the error in the title. I then pulled down the sample project and I'm seeing the same error when running the summarization bit, only change is adding my API key to local.properties.
Idk if this is a server-side issue or not but figured I'd log an issue. I tried API keys from accounts with and without whatever Gemini pro access is called, if that's relevant.
OnePlus 8, Android 13
com.google.ai.client.generativeai.type.SerializationException: Something went wrong while trying to deserialize a response from the server.
2024-05-02 21:43:09.062 27617-27617 System.err com.google.ai.sample W at com.google.ai.client.generativeai.type.GoogleGenerativeAIException$Companion.from(Exceptions.kt:41)
2024-05-02 21:43:09.063 27617-27617 System.err com.google.ai.sample W at com.google.ai.client.generativeai.GenerativeModel$generateContentStream$1.invokeSuspend(GenerativeModel.kt:128)
2024-05-02 21:43:09.064 27617-27617 System.err com.google.ai.sample W at com.google.ai.client.generativeai.GenerativeModel$generateContentStream$1.invoke(Unknown Source:9)
2024-05-02 21:43:09.066 27617-27617 System.err com.google.ai.sample W at com.google.ai.client.generativeai.GenerativeModel$generateContentStream$1.invoke(Unknown Source:6)
2024-05-02 21:43:09.067 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.flow.FlowKt__ErrorsKt$catch$$inlined$unsafeFlow$1.collect(SafeCollector.common.kt:115)
2024-05-02 21:43:09.068 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.flow.FlowKt__ErrorsKt$catch$$inlined$unsafeFlow$1$1.invokeSuspend(Unknown Source:15)
2024-05-02 21:43:09.069 27617-27617 System.err com.google.ai.sample W at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2024-05-02 21:43:09.070 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367)
2024-05-02 21:43:09.071 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith$default(DispatchedContinuation.kt:278)
2024-05-02 21:43:09.072 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.internal.ScopeCoroutine.afterCompletion(Scopes.kt:27)
2024-05-02 21:43:09.072 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.JobSupport.continueCompleting(JobSupport.kt:940)
2024-05-02 21:43:09.074 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.JobSupport.access$continueCompleting(JobSupport.kt:25)
2024-05-02 21:43:09.074 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.JobSupport$ChildCompletion.invoke(JobSupport.kt:1159)
2024-05-02 21:43:09.075 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.JobSupport.notifyCompletion(JobSupport.kt:1497)
2024-05-02 21:43:09.075 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.JobSupport.completeStateFinalization(JobSupport.kt:325)
2024-05-02 21:43:09.076 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.JobSupport.finalizeFinishingState(JobSupport.kt:242)
2024-05-02 21:43:09.076 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.JobSupport.continueCompleting(JobSupport.kt:939)
2024-05-02 21:43:09.077 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.JobSupport.access$continueCompleting(JobSupport.kt:25)
2024-05-02 21:43:09.078 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.JobSupport$ChildCompletion.invoke(JobSupport.kt:1159)
2024-05-02 21:43:09.078 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.JobSupport.notifyCompletion(JobSupport.kt:1497)
2024-05-02 21:43:09.079 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.JobSupport.completeStateFinalization(JobSupport.kt:325)
2024-05-02 21:43:09.079 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.JobSupport.finalizeFinishingState(JobSupport.kt:242)
2024-05-02 21:43:09.080 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath(JobSupport.kt:910)
2024-05-02 21:43:09.080 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.JobSupport.tryMakeCompleting(JobSupport.kt:867)
2024-05-02 21:43:09.081 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(JobSupport.kt:832)
2024-05-02 21:43:09.082 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:100)
2024-05-02 21:43:09.082 27617-27617 System.err com.google.ai.sample W at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
2024-05-02 21:43:09.083 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
2024-05-02 21:43:09.083 27617-27617 System.err com.google.ai.sample W at android.os.Handler.handleCallback(Handler.java:942)
2024-05-02 21:43:09.084 27617-27617 System.err com.google.ai.sample W at android.os.Handler.dispatchMessage(Handler.java:99)
2024-05-02 21:43:09.084 27617-27617 System.err com.google.ai.sample W at android.os.Looper.loopOnce(Looper.java:240)
2024-05-02 21:43:09.084 27617-27617 System.err com.google.ai.sample W at android.os.Looper.loop(Looper.java:351)
2024-05-02 21:43:09.085 27617-27617 System.err com.google.ai.sample W at android.app.ActivityThread.main(ActivityThread.java:8412)
2024-05-02 21:43:09.085 27617-27617 System.err com.google.ai.sample W at java.lang.reflect.Method.invoke(Native Method)
2024-05-02 21:43:09.086 27617-27617 System.err com.google.ai.sample W at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
2024-05-02 21:43:09.086 27617-27617 System.err com.google.ai.sample W at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
2024-05-02 21:43:09.089 27617-27617 System.err com.google.ai.sample W Caused by: kotlinx.serialization.MissingFieldException: Fields [promptTokenCount, totalTokenCount] are required for type with serial name 'com.google.ai.client.generativeai.common.UsageMetadata', but they were missing at path: $.usageMetadata
2024-05-02 21:43:09.090 27617-27617 System.err com.google.ai.sample W at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:93)
2024-05-02 21:43:09.090 27617-27617 System.err com.google.ai.sample W at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43)
2024-05-02 21:43:09.091 27617-27617 System.err com.google.ai.sample W at kotlinx.serialization.encoding.AbstractDecoder.decodeNullableSerializableElement(AbstractDecoder.kt:79)
2024-05-02 21:43:09.091 27617-27617 System.err com.google.ai.sample W at com.google.ai.client.generativeai.common.GenerateContentResponse$$serializer.deserialize(Response.kt:26)
2024-05-02 21:43:09.092 27617-27617 System.err com.google.ai.sample W at com.google.ai.client.generativeai.common.GenerateContentResponse$$serializer.deserialize(Response.kt:26)
2024-05-02 21:43:09.092 27617-27617 System.err com.google.ai.sample W at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:70)
2024-05-02 21:43:09.092 27617-27617 System.err com.google.ai.sample W at kotlinx.serialization.json.Json.decodeFromString(Json.kt:107)
2024-05-02 21:43:09.093 27617-27617 System.err com.google.ai.sample W at com.google.ai.client.generativeai.common.APIController$generateContentStream$$inlined$postStream$1$1$1$1$1.invokeSuspend(ktor.kt:103)
2024-05-02 21:43:09.093 27617-27617 System.err com.google.ai.sample W at com.google.ai.client.generativeai.common.APIController$generateContentStream$$inlined$postStream$1$1$1$1$1.invoke(Unknown Source:8)
2024-05-02 21:43:09.094 27617-27617 System.err com.google.ai.sample W at com.google.ai.client.generativeai.common.APIController$generateContentStream$$inlined$postStream$1$1$1$1$1.invoke(Unknown Source:4)
2024-05-02 21:43:09.094 27617-27617 System.err com.google.ai.sample W at com.google.ai.client.generativeai.common.util.KtorKt.onEachLine(ktor.kt:52)
2024-05-02 21:43:09.095 27617-27617 System.err com.google.ai.sample W at com.google.ai.client.generativeai.common.APIController$generateContentStream$$inlined$postStream$1$1$1$1.invokeSuspend(ktor.kt:82)
2024-05-02 21:43:09.095 27617-27617 System.err com.google.ai.sample W at com.google.ai.client.generativeai.common.APIController$generateContentStream$$inlined$postStream$1$1$1$1.invoke(Unknown Source:8)
2024-05-02 21:43:09.096 27617-27617 System.err com.google.ai.sample W at com.google.ai.client.generativeai.common.APIController$generateContentStream$$inlined$postStream$1$1$1$1.invoke(Unknown Source:4)
2024-05-02 21:43:09.096 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.flow.ChannelFlowBuilder.collectTo$suspendImpl(Builders.kt:320)
2024-05-02 21:43:09.096 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.flow.ChannelFlowBuilder.collectTo(Unknown Source:0)
2024-05-02 21:43:09.097 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.flow.internal.ChannelFlow$collectToFun$1.invokeSuspend(ChannelFlow.kt:60)
2024-05-02 21:43:09.097 27617-27617 System.err com.google.ai.sample W at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2024-05-02 21:43:09.098 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
2024-05-02 21:43:09.098 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:68)
2024-05-02 21:43:09.099 27617-27617 System.err com.google.ai.sample W at kotlinx.coroutines.internal.DispatchedContinuation.resumeWith(DispatchedContinuation.kt:347)
2024-05-02 21:43:09.099 27617-27617 System.err com.google.ai.sample W at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(SuspendFunctionGun.kt:135)
2024-05-02 21:43:09.099 27617-27617 System.err com.google.ai.sample W at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:109)
2024-05-02 21:43:09.100 27617-27617 System.err com.google.ai.sample W at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(SuspendFunctionGun.kt:11)
2024-05-02 21:43:09.100 27617-27617 System.err com.google.ai.sample W at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(SuspendFunctionGun.kt:59)
2024-05-02 21:43:09.100 27617-27617 System.err com.google.ai.sample W ... 10 more
2024-05-02 21:43:09.103 27617-27617 System.err com.google.ai.sample W Caused by: kotlinx.serialization.MissingFieldException: Fields [promptTokenCount, totalTokenCount] are required for type with serial name 'com.google.ai.client.generativeai.common.UsageMetadata', but they were missing
2024-05-02 21:43:09.103 27617-27617 System.err com.google.ai.sample W at kotlinx.serialization.internal.PluginExceptionsKt.throwMissingFieldException(PluginExceptions.kt:20)
2024-05-02 21:43:09.104 27617-27617 System.err com.google.ai.sample W at com.google.ai.client.generativeai.common.UsageMetadata.<init>(Response.kt:39)
2024-05-02 21:43:09.104 27617-27617 System.err com.google.ai.sample W at com.google.ai.client.generativeai.common.UsageMetadata$$serializer.deserialize(Response.kt:39)
2024-05-02 21:43:09.105 27617-27617 System.err com.google.ai.sample W at com.google.ai.client.generativeai.common.UsageMetadata$$serializer.deserialize(Response.kt:39)
2024-05-02 21:43:09.105 27617-27617 System.err com.google.ai.sample W at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:70)
2024-05-02 21:43:09.105 27617-27617 System.err com.google.ai.sample W ... 34 more
Hi,
I am trying to use the SDK to communicate with my flutter app using methodchannel
but i am getting this error
First this error
ERROR:C:\Users\xxxx\.gradle\caches\transforms-3\5d19816a0b04a46bdd05877142eefa50\transformed\jetified-generativeai-0.1.2-runtime.jar: D8: com.android.tools.r8.internal.Hc: Sealed classes are not supported as program classes
then this again
Execution failed for task ':app:mergeExtDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Failed to transform generativeai-0.1.2.aar (com.google.ai.client.generativeai:generativeai:0.1.2) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=26, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
> Execution failed for DexingNoClasspathTransform: C:\Users\Arafat Benson\.gradle\caches\transforms-3\5d19816a0b04a46bdd05877142eefa50\transformed\jetified-generativeai-0.1.2-runtime.jar.
> Error while dexing.
could you help me with the cause of this? thanks
Right now, in the README, we suggest people not check their API key into the repo, we should do the same in this README like we do in the docs: https://ai.google.dev/tutorials/quickstart#android
Im developing an Android chat app using a custom-tuned model from Gemini AI. However, I'm stuck with an error (see screenshot below) Error : models/tuned-test-model-g8tvOuyp9i6i is not found for API version v1 . when trying to integrate the model into my code. Any insights on resolving this issue would be greatly appreciated!
Android code for reference
val generativeModel = GenerativeModel(
modelName = "tuned-test-model-g8tv0uyp9i6i",
apiKey = BuildConfig.apiKey,
generationConfig = config
)
While Bard was updated to provide service in many more countries, I wonder when will the API be general available to those countries too?
Do you have an ETA?
Thank you in advance
Just asked about responseMimeType in the forum while ago forum. It just got updated in 0.6.0 what a perfect timing.
But I found some catch (not a big deal tho, but maybe it will help in the future) on the helper method example usage there is no responseMimeType written on it. But I can still use it perfectly normal.
Expected: responseMimeType parameter example
No response
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.