|
12 | 12 | import android.content.ClipDescription;
|
13 | 13 | import android.content.Context;
|
14 | 14 | import android.content.Intent;
|
| 15 | +import android.content.pm.PackageInfo; |
15 | 16 | import android.content.res.AssetFileDescriptor;
|
16 | 17 | import android.database.Cursor;
|
17 | 18 | import android.graphics.Bitmap;
|
|
44 | 45 | import android.widget.Toast;
|
45 | 46 |
|
46 | 47 | import com.flyun.base.BaseMessage;
|
| 48 | +import com.google.firebase.crashlytics.FirebaseCrashlytics; |
47 | 49 | import com.theokanning.openai.GoogleHttpException;
|
48 | 50 | import com.theokanning.openai.OpenAiHttpException;
|
49 | 51 | import com.theokanning.openai.completion.chat.ChatCompletionChoice;
|
@@ -882,6 +884,7 @@ public SendMessagesHelper(int instance) {
|
882 | 884 | apiServer = UserConfig.getInstance(currentAccount).apiServer;
|
883 | 885 | llmType = LLMType.openAi;
|
884 | 886 | }
|
| 887 | + OpenAiService.errorCallback = t -> FirebaseCrashlytics.getInstance().recordException(t); |
885 | 888 | openAiService = new OpenAiService(token, 60, apiServer, llmType);
|
886 | 889 | }
|
887 | 890 | });
|
@@ -1351,9 +1354,13 @@ public void didReceivedNotification(int id, int account, final Object... args) {
|
1351 | 1354 | }
|
1352 | 1355 | } else if (id == NotificationCenter.cancelRequest) {
|
1353 | 1356 |
|
| 1357 | + boolean isShowStopStream = false; |
| 1358 | + if(args.length > 0) { |
| 1359 | + isShowStopStream = (boolean) args[0]; |
| 1360 | + } |
1354 | 1361 | if (openAiService != null && isRequesting) {
|
1355 | 1362 | // isRequesting = false;
|
1356 |
| - openAiService.clean(false); |
| 1363 | + openAiService.clean(false, isShowStopStream); |
1357 | 1364 | }
|
1358 | 1365 | }
|
1359 | 1366 | }
|
@@ -6087,7 +6094,7 @@ public void onError(OpenAiHttpException error, Throwable throwable) {
|
6087 | 6094 | if (error != null) {
|
6088 | 6095 | errorTx = error.getMessage();
|
6089 | 6096 | } else {
|
6090 |
| - errorTx = throwable.getMessage(); |
| 6097 | + errorTx = formatError(throwable); |
6091 | 6098 | }
|
6092 | 6099 |
|
6093 | 6100 | if (!TextUtils.isEmpty(errorTx)) {
|
@@ -6199,7 +6206,7 @@ public void onError(OpenAiHttpException error, Throwable throwable) {
|
6199 | 6206 | } else {
|
6200 | 6207 |
|
6201 | 6208 | // Log.e("test","err:" + throwable);
|
6202 |
| - errorTx = throwable.getMessage(); |
| 6209 | + errorTx = formatError(throwable); |
6203 | 6210 | }
|
6204 | 6211 |
|
6205 | 6212 | if (!TextUtils.isEmpty(errorTx)) {
|
@@ -7111,7 +7118,7 @@ public void onError(GoogleHttpException error, Throwable throwable) {
|
7111 | 7118 | errorTx = getGeminiError(error.getMessage());
|
7112 | 7119 | } else {
|
7113 | 7120 | // 增加Gemini 一问一答的错误提示
|
7114 |
| - errorTx = getGeminiError(throwable.getMessage()); |
| 7121 | + errorTx = getGeminiError(formatError(throwable)); |
7115 | 7122 | }
|
7116 | 7123 |
|
7117 | 7124 | if (!TextUtils.isEmpty(errorTx)) {
|
@@ -7224,7 +7231,7 @@ public void onError(GoogleHttpException error, Throwable throwable) {
|
7224 | 7231 | + "\n" + "message:" + getGeminiError(error.getMessage());
|
7225 | 7232 | } else {
|
7226 | 7233 | // 增加Gemini 一问一答的错误提示
|
7227 |
| - errorTx = getGeminiError(throwable.getMessage()); |
| 7234 | + errorTx = getGeminiError(formatError(throwable)); |
7228 | 7235 | }
|
7229 | 7236 |
|
7230 | 7237 | if (!TextUtils.isEmpty(errorTx)) {
|
@@ -7410,7 +7417,7 @@ public void onError(AnthropicHttpException error, Throwable throwable) {
|
7410 | 7417 | if (error != null) {
|
7411 | 7418 | errorTx = error.getMessage();
|
7412 | 7419 | } else {
|
7413 |
| - errorTx = throwable.getMessage(); |
| 7420 | + errorTx = formatError(throwable); |
7414 | 7421 | }
|
7415 | 7422 |
|
7416 | 7423 | if (!TextUtils.isEmpty(errorTx)) {
|
@@ -7504,7 +7511,7 @@ public void onError(AnthropicHttpException error, Throwable throwable) {
|
7504 | 7511 | + "\n" + "status:" + error.status
|
7505 | 7512 | + "\n" + "message:" + getGeminiError(error.getMessage());
|
7506 | 7513 | } else {
|
7507 |
| - errorTx = throwable.getMessage(); |
| 7514 | + errorTx = formatError(throwable); |
7508 | 7515 | }
|
7509 | 7516 |
|
7510 | 7517 | if (!TextUtils.isEmpty(errorTx)) {
|
@@ -10342,4 +10349,24 @@ private void setRequesting(boolean isRequesting) {
|
10342 | 10349 | getNotificationCenter().postNotificationName(NotificationCenter.updateSteam, this.isRequesting);
|
10343 | 10350 | });
|
10344 | 10351 | }
|
| 10352 | + |
| 10353 | + public static String formatError(Throwable throwable) { |
| 10354 | + String response = ""; |
| 10355 | + String version = "App version: "; |
| 10356 | + |
| 10357 | + try { |
| 10358 | + PackageInfo pInfo = ApplicationLoader.applicationContext.getPackageManager() |
| 10359 | + .getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0); |
| 10360 | + version += String.format(Locale.US, "%s (%d)", pInfo.versionName, |
| 10361 | + pInfo.versionCode); |
| 10362 | + } catch (Exception e) { |
| 10363 | + } |
| 10364 | + |
| 10365 | + if(throwable instanceof retrofit2.HttpException |
| 10366 | + && ((retrofit2.HttpException) throwable).response() != null) { |
| 10367 | + response = ((retrofit2.HttpException) throwable).response().toString(); |
| 10368 | + } |
| 10369 | + |
| 10370 | + return throwable.getMessage() + "\n\n" + response + "\n\n" + version; |
| 10371 | + } |
10345 | 10372 | }
|
0 commit comments