DevEmperor / WristAssist

A powerful ChatGPT and DALL-E app for all WearOS devices
https://play.google.com/store/apps/details?id=net.devemperor.wristassist
Apache License 2.0
93 stars 14 forks source link

Connection to OpenAI API failed: Please check your internet connection #10

Closed kikoas1995 closed 10 months ago

kikoas1995 commented 10 months ago

Hello,

I've finally written the API key in the app. I've triple checked it's correct, and also I've ensured that I can use that API key using it in a python script on my laptop. But on the Smartwatch all I see when sending a prompt is Connection to OpenAI API failed: Please check your internet connection. I have it synced with my phone via bluetooth. Any idea?

kikoas1995 commented 10 months ago

Using a Pixel Watch LTE Gen1 btw

kikoas1995 commented 10 months ago

Is there any way to enable seeing the actual stacktrace in the app?

DevEmperor commented 10 months ago

Thank you for pointing out this error. Another user has already told me about the same problem. Unfortunately, I had no insight into the stack trace at exceptions until yesterday. Now I have installed Google Crashlytics so that I can better fix such errors in the future. Unfortunately, a stack trace cannot be displayed easily on the watch itself. I submitted the update to Google Play yesterday and as soon as it is approved in the next few days, I will get back to you. Then you can trigger the bug so that I can examine it more closely and fix it. Thank you for your patience. :)

DevEmperor commented 10 months ago

Version 2.3.0 with Crashlytics has just been released in the PlayStore. Can you download the latest version to your watch and trigger the bug again? Then the stacktrace will be displayed and I can find and fix the bug. It's also best to go to "About" in the menu and hold down on the icon. Then you will see your UserID, which I can use to find your error message.

kikoas1995 commented 10 months ago

406459936 is my userid.

DevEmperor commented 10 months ago

You have to close the app completely and reopen it so that crash reports are sent. I can't see anything yet.

kikoas1995 commented 10 months ago

Done, can you check?

DevEmperor commented 10 months ago

I have now received your report and was able to find the error:

You have a U+200E LEFT-TO-RIGHT MARK character in your API key. It's a non-printing typesetting directive, instructing anything that is displaying the text to switch to left-to-right mode, (which is usually the case).

You probably didn't type in the key by hand on the keyboard, did you? :) If I set the API key in my test app as follows, I can reproduce your error: apiKey = "\u200Esk-t0rFL..."; I change my code so that such characters are filtered out. Nevertheless, I wonder how such a Unicode character slipped in with you...

DevEmperor commented 10 months ago

This is your stack trace btw:

Non-fatal Exception: java.lang.IllegalArgumentException: Unexpected char 0x200e at 7 in Authorization value: Bearer ‎sk-t0r...
       at okhttp3.Headers.checkValue(Headers.java:284)
       at okhttp3.Headers$Builder.set(Headers.java:415)
       at okhttp3.Request$Builder.header(Request.java:184)
       at com.theokanning.openai.service.AuthenticationInterceptor.intercept(AuthenticationInterceptor.java:26)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
       at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:229)
       at okhttp3.RealCall.execute(RealCall.java:81)
       at retrofit2.OkHttpCall.execute(OkHttpCall.java:204)
       at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:46)
       at io.reactivex.Observable.subscribe(Observable.java:10151)
       at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:35)
       at io.reactivex.Observable.subscribe(Observable.java:10151)
       at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
       at io.reactivex.Single.subscribe(Single.java:2517)
       at io.reactivex.Single.blockingGet(Single.java:2001)
       at com.theokanning.openai.service.OpenAiService.execute(OpenAiService.java:353)
       at com.theokanning.openai.service.OpenAiService.createChatCompletion(OpenAiService.java:138)
       at net.devemperor.wristassist.activities.ChatActivity.lambda$query$2$net-devemperor-wristassist-activities-ChatActivity(ChatActivity.java:261)
       at net.devemperor.wristassist.activities.ChatActivity$$ExternalSyntheticLambda0.run(:4)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
       at java.lang.Thread.run(Thread.java:1012)
DevEmperor commented 10 months ago

Just committed the fix. The update will be released in the next few days. Would be nice if you could try entering the key manually again if you haven't done so the last few times. As I said, I have no idea how this Unicode character got there... :D