Skip to content

Gemini API : The recitation problem is annoying #257

Closed
@ImadSaddik

Description

@ImadSaddik

When attempting to use the Gemini API in Android, I encountered the error Content generation stopped. Reason: RECITATION. This error is particularly frustrating as it occurs randomly without any apparent cause.

The most recent occurrence of this issue was when I raised #249, regarding streaming not functioning properly in Android. David Motson provided temporary assistance in resolving this problem. I used a prompt to test if the streaming would work - Give me a Java program that uses Jsoup -. Initially, I was successfully receiving chunks of data, but then suddenly encountered the RECITATION problem.

Below are the logs:

2024-02-11 08:15:05.409 13579-13741 GeminiPro               com.example.streaminggeminiapp       D  onNext: .nodes.Document;
                                                                                                    import org.jsoup.nodes.Element;
                                                                                                    import org.jsoup.select.Elements;
                                                                                                    
                                                                                                    public class JsoupExample {
2024-02-11 08:15:06.284 13579-13741 GeminiPro               com.example.streaminggeminiapp       D  onNext: 

                                                                                                    
                                                                                                        public static void main(String[] args) {
                                                                                                            // Parse HTML from a URL
                                                                                                            String url = "https://www.example.com";
                                                                                                            Document doc = Jsoup.connect(url).get();
                                                                                                    
                                                                                                            // Get the title of the page
                                                                                                            String title = doc.
2024-02-11 08:15:08.039 13579-13741 GeminiPro               com.example.streaminggeminiapp       D  onError: Content generation stopped. Reason: RECITATION
--------- beginning of crash
2024-02-11 08:15:08.055 13579-13741 AndroidRuntime          com.example.streaminggeminiapp       E  FATAL EXCEPTION: DefaultDispatcher-worker-2
                                                                                                    Process: com.example.streaminggeminiapp, PID: 13579
                                                                                                    com.google.ai.client.generativeai.type.ResponseStoppedException: Content generation stopped. Reason: RECITATION
                                                                                                    	at com.google.ai.client.generativeai.GenerativeModel.validate(GenerativeModel.kt:182)
                                                                                                    	at com.google.ai.client.generativeai.GenerativeModel.access$validate(GenerativeModel.kt:49)
                                                                                                    	at com.google.ai.client.generativeai.GenerativeModel$generateContentStream$$inlined$map$1$2.emit(Emitters.kt:224)
                                                                                                    	at kotlinx.coroutines.flow.FlowKt__ChannelsKt.emitAllImpl$FlowKt__ChannelsKt(Channels.kt:37)
                                                                                                    	at kotlinx.coroutines.flow.FlowKt__ChannelsKt.access$emitAllImpl$FlowKt__ChannelsKt(Channels.kt:1)
                                                                                                    	at kotlinx.coroutines.flow.FlowKt__ChannelsKt$emitAllImpl$1.invokeSuspend(Unknown Source:14)
                                                                                                    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                                                                                                    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
                                                                                                    	at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:68)
                                                                                                    	at kotlinx.coroutines.internal.DispatchedContinuation.resumeWith(DispatchedContinuation.kt:347)
                                                                                                    	at io.ktor.utils.io.internal.CancellableReusableContinuation.resumeWith(CancellableReusableContinuation.kt:93)
                                                                                                    	at io.ktor.utils.io.ByteBufferChannel.resumeReadOp(ByteBufferChannel.kt:2098)
                                                                                                    	at io.ktor.utils.io.ByteBufferChannel.flushImpl(ByteBufferChannel.kt:186)
                                                                                                    	at io.ktor.utils.io.ByteBufferChannel.flush(ByteBufferChannel.kt:196)
                                                                                                    	at io.ktor.utils.io.ByteBufferChannel.copyDirect$ktor_io(ByteBufferChannel.kt:1262)
                                                                                                    	at io.ktor.utils.io.ByteBufferChannel$copyDirect$1.invokeSuspend(Unknown Source:18)
                                                                                                    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                                                                                                    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
                                                                                                    	at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
                                                                                                    	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
                                                                                                    	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
                                                                                                    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
                                                                                                    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
                                                                                                    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
                                                                                                    	Suppressed: java.lang.NullPointerException: Can't toast on a thread that has not called Looper.prepare()
                                                                                                    		at com.android.internal.util.Preconditions.checkNotNull(Preconditions.java:167)
                                                                                                    		at android.widget.Toast.getLooper(Toast.java:212)
                                                                                                    		at android.widget.Toast.<init>(Toast.java:197)
                                                                                                    		at android.widget.Toast.makeText(Toast.java:583)
                                                                                                    		at android.widget.Toast.makeText(Toast.java:570)
                                                                                                    		at android.widget.Toast.makeText(Toast.java:544)
                                                                                                    		at com.example.streaminggeminiapp.MainActivity$1.onError(MainActivity.java:57)
                                                                                                    		at com.example.streaminggeminiapp.GeminiPro$1.onError(GeminiPro.java:56)
                                                                                                    		at kotlinx.coroutines.reactive.FlowSubscription.flowProcessing(ReactiveFlow.kt:215)
                                                                                                    		at kotlinx.coroutines.reactive.FlowSubscription.access$flowProcessing(ReactiveFlow.kt:187)
                                                                                                    		at kotlinx.coroutines.reactive.FlowSubscription$flowProcessing$1.invokeSuspend(Unknown Source:14)
                                                                                                    		at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                                                                                                    		at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
                                                                                                    		... 16 more
                                                                                                    	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [FlowSubscription{Active}@c97cec2, Dispatchers.Unconfined]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions