Skip to content

Commit bb656b0

Browse files
committed
*适配one-api
*添加C#、OC、Swift、Sql代码高亮 *修复user配置自定义模型不生效问题 *修复流式输出时聊天框可发送消息的问题
1 parent aaf34a0 commit bb656b0

15 files changed

+567
-23
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
ChatAir is a native client for OpenAI and Gemini, providing a smoother and faster chat experience than ChatGPT.
1212

1313
<div align="left">
14-
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/01.png" width ="160" />
15-
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/02.png" width ="160" />
16-
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/03.png" width ="160" />
17-
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/04.png" width ="160" />
18-
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/05.png" width ="160" />
19-
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/06.png" width ="160" />
14+
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/01.png" width ="260" />
15+
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/02.png" width ="260" />
16+
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/03.png" width ="260" />
17+
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/04.png" width ="260" />
18+
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/05.png" width ="260" />
19+
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/06.png" width ="260" />
2020
</div>
2121

2222
## Installation

README_CN.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
ChatAir 是 OpenAI 和 Gemini 的原生客户端,提供比 ChatGPT 更流畅、更快速的聊天体验。
1212

1313
<div align="left">
14-
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/01.png" width ="160" />
15-
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/02.png" width ="160" />
16-
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/03.png" width ="160" />
17-
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/04.png" width ="160" />
18-
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/05.png" width ="160" />
19-
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/06.png" width ="160" />
14+
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/01.png" width ="260" />
15+
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/02.png" width ="260" />
16+
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/03.png" width ="260" />
17+
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/04.png" width ="260" />
18+
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/05.png" width ="260" />
19+
<img src = "https://github.com/flyun/chatAir/blob/chatair/ScreenShots/06.png" width ="260" />
2020
</div>
2121

2222
## 安装

TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -5783,7 +5783,7 @@ protected void performSendMessageRequest(final TLObject req, final MessageObject
57835783
aiModel = UserConfig.getInstance(currentAccount).aiModel;
57845784
}
57855785

5786-
aiModelReal = UserConfig.getInstance(currentAccount).getAiModelReal(aiModel);
5786+
aiModelReal = UserConfig.getInstance(currentAccount).getAiModelReal(aiModel, user.id);
57875787

57885788
isGemini = UserConfig.getInstance(currentAccount).isJudgeByModelGemini(aiModel);
57895789
isGeminiProVision = UserConfig.getInstance(currentAccount).isJudgeByModelGeminiProVision(aiModel);
@@ -5845,11 +5845,22 @@ protected void performSendMessageRequest(final TLObject req, final MessageObject
58455845

58465846
streamMessages.clear();
58475847

5848+
// 兼容one-api
5849+
String OtherId = "Other_" + SystemClock.elapsedRealtime();
5850+
58485851
openAiService.streamChatCompletion(chatCompletionRequest, new OpenAiService.StreamCallBack() {
58495852
@Override
58505853
public void onSuccess(ChatCompletionChunk result) {
58515854

5852-
final String streamId = result.getId();
5855+
final String streamId;
5856+
5857+
5858+
if (TextUtils.isEmpty(result.getId())) {
5859+
// 兼容one-api
5860+
streamId = OtherId;
5861+
} else {
5862+
streamId = result.getId();
5863+
}
58535864

58545865
if (TextUtils.isEmpty(streamId) || result.getChoices().size() == 0)
58555866
return;

TMessagesProj/src/main/java/org/telegram/messenger/UserConfig.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ public String getAiModelName(int aiModel) {
570570

571571
}
572572

573-
public String getAiModelReal(int aiModel) {
573+
public String getAiModelReal(int aiModel, long userId) {
574574

575575
String aiModelReal = "";
576576
LinkedHashMap<Integer, AiModelBean> aiModelList
@@ -579,7 +579,16 @@ public String getAiModelReal(int aiModel) {
579579
if (aiModelList.containsKey(aiModel)) {
580580
if (aiModel == 0) {
581581
// 自定义model
582-
aiModelReal = UserConfig.getInstance(currentAccount).customModel;
582+
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(userId);
583+
if (user != null && (user.flags2 & MessagesController.UPDATE_MASK_CHAT_AIR_AI_CUSTOM_MODEL) != 0) {
584+
// 聊天配置
585+
aiModelReal = user.customModel;
586+
} else {
587+
// 系统默认
588+
aiModelReal = UserConfig.getInstance(currentAccount).customModel;
589+
}
590+
591+
583592
} else {
584593
AiModelBean bean = aiModelList.get(aiModel);
585594
if (bean != null) {
@@ -660,7 +669,7 @@ public static String getUserAiModelReal(int currentAccount, long userId) {
660669

661670
int aiModel = getUserAiModel(currentAccount, userId);
662671

663-
String aiModelReal = UserConfig.getInstance(currentAccount).getAiModelReal(aiModel);
672+
String aiModelReal = UserConfig.getInstance(currentAccount).getAiModelReal(aiModel, userId);
664673

665674
if (aiModelReal == null) return "";
666675

TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,9 @@ public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo i
501501
private boolean smoothKeyboard;
502502

503503
private boolean isPaused = true;
504+
505+
// 是否显示流式响应暂停按钮
506+
private boolean isHideStopStream = true;
504507
private boolean recordIsCanceled;
505508
private boolean showKeyboardOnResume;
506509

@@ -5149,6 +5152,9 @@ public void onAnimationEnd(Animator animation) {
51495152
}
51505153

51515154
private void sendMessage() {
5155+
5156+
if (BuildVars.IS_CHAT_AIR && !isHideStopStream && sendByEnter) return;
5157+
51525158
if (isInScheduleMode()) {
51535159
AlertsCreator.createScheduleDatePickerDialog(parentActivity, parentFragment.getDialogId(), this::sendMessageInternal, resourcesProvider);
51545160
} else {
@@ -9427,9 +9433,10 @@ public void didReceivedNotification(int id, int account, Object... args) {
94279433
} else if (id == NotificationCenter.didUpdatePremiumGiftFieldIcon) {
94289434
updateGiftButton(true);
94299435
} else if (id == NotificationCenter.updateSteam) {
9430-
boolean isShow = (boolean) args[0];
9431-
cancelStreamButton.setVisibility(isShow ? VISIBLE : GONE);
9432-
sendButtonContainer.setVisibility(!isShow ? VISIBLE : GONE);
9436+
boolean isShowStopStream = (boolean) args[0];
9437+
isHideStopStream = !isShowStopStream;
9438+
cancelStreamButton.setVisibility(isShowStopStream ? VISIBLE : GONE);
9439+
sendButtonContainer.setVisibility(!isShowStopStream ? VISIBLE : GONE);
94339440
} else if (id == NotificationCenter.updateModel) {
94349441
updateAttachInterface();
94359442
}

TMessagesProj/src/main/java/org/telegram/ui/GeneralGrammarLocator.java

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static String fromExtension(String extension) {
3535
case "h++":
3636
return "cpp";
3737

38+
case "c#":
3839
case "cs":
3940
case "csx":
4041
return "csharp";
@@ -51,6 +52,9 @@ public static String fromExtension(String extension) {
5152
case "mjs":
5253
return "javascript";
5354

55+
case "json":
56+
return "json";
57+
5458
case "kt":
5559
case "kts":
5660
case "ktm":
@@ -66,6 +70,10 @@ public static String fromExtension(String extension) {
6670
case "svg":
6771
return "markup";
6872

73+
case "objective-c":
74+
return "objectiveC";
75+
case "swift":
76+
return "swift";
6977
case "py":
7078
case "pyi":
7179
case "pyc":
@@ -79,6 +87,9 @@ public static String fromExtension(String extension) {
7987
case "sc":
8088
return "scala";
8189

90+
case "sql":
91+
return "sql";
92+
8293
case "el":
8394
case "lisp":
8495
return "lisp";

TMessagesProj/src/main/res/xml/network_security_config.xml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<base-config cleartextTrafficPermitted="true">
55
<trust-anchors>
6+
<base-config cleartextTrafficPermitted="true" />
67
<certificates
78
overridePins="true"
89
src="system" />

gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1414
# org.gradle.parallel=true
1515
#Sat Mar 12 05:53:50 MSK 2016
16-
APP_VERSION_CODE=3
17-
APP_VERSION_NAME=1.0.2
16+
APP_VERSION_CODE=4
17+
APP_VERSION_NAME=1.0.3
1818
APP_PACKAGE=info.flyun.chatair
1919
RELEASE_KEY_PASSWORD=android
2020
RELEASE_KEY_ALIAS=androidkey

markwon-core/src/main/java/io/noties/markwon/code/MainGrammarLocator.java

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static String fromExtension(String extension) {
3535
case "h++":
3636
return "cpp";
3737

38+
case "c#":
3839
case "cs":
3940
case "csx":
4041
return "csharp";
@@ -66,6 +67,11 @@ public static String fromExtension(String extension) {
6667
case "svg":
6768
return "markup";
6869

70+
case "objective-c":
71+
return "objectiveC";
72+
case "swift":
73+
return "swift";
74+
6975
case "py":
7076
case "pyi":
7177
case "pyc":
@@ -79,6 +85,12 @@ public static String fromExtension(String extension) {
7985
case "sc":
8086
return "scala";
8187

88+
case "sql":
89+
return "sql";
90+
91+
case "json":
92+
return "json";
93+
8294
case "el":
8395
case "lisp":
8496
return "lisp";

0 commit comments

Comments
 (0)