Skip to content

Commit

Permalink
Merge pull request #128 from mylxsw/v2.x
Browse files Browse the repository at this point in the history
V2.x
  • Loading branch information
mylxsw authored Dec 21, 2024
2 parents a0b95d6 + 002f778 commit 731b4d2
Show file tree
Hide file tree
Showing 13 changed files with 301 additions and 256 deletions.
1 change: 1 addition & 0 deletions assets/lottie/empty_status.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ PODS:
- Flutter
- media_kit_video (0.0.1):
- Flutter
- motion (0.0.1):
- Flutter
- package_info_plus (0.4.5):
- Flutter
- path_provider_foundation (0.0.1):
Expand Down Expand Up @@ -174,6 +176,7 @@ DEPENDENCIES:
- media_kit_libs_ios_video (from `.symlinks/plugins/media_kit_libs_ios_video/ios`)
- media_kit_native_event_loop (from `.symlinks/plugins/media_kit_native_event_loop/ios`)
- media_kit_video (from `.symlinks/plugins/media_kit_video/ios`)
- motion (from `.symlinks/plugins/motion/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- record_darwin (from `.symlinks/plugins/record_darwin/ios`)
Expand Down Expand Up @@ -241,6 +244,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/media_kit_native_event_loop/ios"
media_kit_video:
:path: ".symlinks/plugins/media_kit_video/ios"
motion:
:path: ".symlinks/plugins/motion/ios"
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
path_provider_foundation:
Expand Down Expand Up @@ -290,6 +295,7 @@ SPEC CHECKSUMS:
media_kit_libs_ios_video: a5fe24bc7875ccd6378a0978c13185e1344651c1
media_kit_native_event_loop: e6b2ab20cf0746eb1c33be961fcf79667304fa2a
media_kit_video: 5da63f157170e5bf303bf85453b7ef6971218a2e
motion: 7f0d608a472de69d1210c1d871600cde66ae4d54
package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
record_darwin: df0a677188e5fed18472550298e675f19ddaffbe
Expand Down
37 changes: 10 additions & 27 deletions lib/bloc/chat_message_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ class ChatMessageBloc extends BlocExt<ChatMessageEvent, ChatMessageState> {
userId: APIServer().localUserID(),
);

if (lastMessage != null &&
(lastMessage.type == MessageType.contextBreak ||
lastMessage.isInitMessage())) {
if (lastMessage != null && (lastMessage.type == MessageType.contextBreak || lastMessage.isInitMessage())) {
return;
}

Expand Down Expand Up @@ -218,8 +216,7 @@ class ChatMessageBloc extends BlocExt<ChatMessageEvent, ChatMessageState> {
emit(ChatAnywhereInited(chatHistory.id!));
} else {
if (localChatHistoryId > 0) {
localChatHistory =
await chatMsgRepo.getChatHistory(localChatHistoryId);
localChatHistory = await chatMsgRepo.getChatHistory(localChatHistoryId);
}
}
}
Expand Down Expand Up @@ -252,9 +249,7 @@ class ChatMessageBloc extends BlocExt<ChatMessageEvent, ChatMessageState> {
chatHistoryId: localChatHistoryId,
userId: APIServer().localUserID(),
);
if (last == null ||
last.ts == null ||
DateTime.now().difference(last.ts!).inMinutes > 60 * 3) {
if (last == null || last.ts == null || DateTime.now().difference(last.ts!).inMinutes > 60 * 3) {
// 发送时间线消息
await chatMsgRepo.sendMessage(
roomId,
Expand Down Expand Up @@ -287,10 +282,7 @@ class ChatMessageBloc extends BlocExt<ChatMessageEvent, ChatMessageState> {

// 记录当前消息
var sentMessageId = 0;
if (event.isResent &&
event.index == 0 &&
last != null &&
last.type == MessageType.text) {
if (event.isResent && event.index == 0 && last != null && last.type == MessageType.text) {
// 如果当前是消息重发,同时重发的是最后一条消息,则不会重新生成该消息,直接生成答案即可
sentMessageId = last.id!;
if (last.statusIsFailed()) {
Expand Down Expand Up @@ -389,17 +381,13 @@ class ChatMessageBloc extends BlocExt<ChatMessageEvent, ChatMessageState> {
}
}

waitMessage.text += items
.where((e) => e.role != 'system')
.map((e) => e.content)
.join('');
waitMessage.text += items.where((e) => e.role != 'system').map((e) => e.content).join('');
emit(ChatMessageUpdated(waitMessage, processing: true));

// 失败处理
for (var e in items) {
if (e.code != null && e.code! > 0) {
error = RequestFailedException(
e.error ?? 'Request processing failure', e.code!);
error = RequestFailedException(e.error ?? 'Request processing failure', e.code!);
}
}
});
Expand All @@ -426,8 +414,7 @@ class ChatMessageBloc extends BlocExt<ChatMessageEvent, ChatMessageState> {
}
} catch (e) {
if (waitMessage.text.isEmpty) {
Logger.instance
.e('An error occurred during the response process: $e');
Logger.instance.e('An error occurred during the response process: $e');
rethrow;
}
}
Expand All @@ -449,12 +436,9 @@ class ChatMessageBloc extends BlocExt<ChatMessageEvent, ChatMessageState> {
sentMessageParts,
);

if (room.id == chatAnywhereRoomId &&
localChatHistoryId != null &&
localChatHistoryId > 0) {
if (room.id == chatAnywhereRoomId && localChatHistoryId != null && localChatHistoryId > 0) {
// 更新聊天历史纪录最后一条消息
final chatHistory =
await chatMsgRepo.getChatHistory(localChatHistoryId);
final chatHistory = await chatMsgRepo.getChatHistory(localChatHistoryId);
if (chatHistory != null) {
chatHistory.lastMessage = waitMessage.text;
// 异步处理就好,不需要等待
Expand Down Expand Up @@ -524,8 +508,7 @@ class ChatMessageBloc extends BlocExt<ChatMessageEvent, ChatMessageState> {
}
}

Future<Room?> queryRoomById(
ChatMessageRepository chatMsgRepo, int roomId) async {
Future<Room?> queryRoomById(ChatMessageRepository chatMsgRepo, int roomId) async {
Room? room;
if (Ability().isUserLogon()) {
final roomInServer = await APIServer().room(roomId: roomId);
Expand Down
60 changes: 22 additions & 38 deletions lib/lang/lang.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ mixin AppLocale {

static const String nameRequiredMessage = 'name-required-message';
static const String modelRequiredMessage = 'model-required-message';
static const String charactorPromptRequiredMessage = 'charactor-prompt-required-message';

static const String writeYourIdeas = 'write-your-ideas';
static const String describeYourImages = 'describe-your-images';
Expand All @@ -136,8 +137,7 @@ mixin AppLocale {
static const String generating = 'generating';
static const String generateExitConfirm = 'generate-exit-confirm';
static const String tooManyRequests = 'too-many-requests';
static const String tooManyRequestsOrPaymentRequired =
'too-many-requests-or-payment-required';
static const String tooManyRequestsOrPaymentRequired = 'too-many-requests-or-payment-required';
static const String promptHint = 'prompt-hint';
static const String confirmClearCache = 'confirm-clear-cache';
static const String confirmSignOut = 'confirm-sign-out';
Expand All @@ -158,17 +158,15 @@ mixin AppLocale {
static const String referenceImage = 'reference-image';
static const String selectImage = 'select-image';
static const String imagination = 'imagination';
static const String keywordsSeparatedByCommas =
'keywords-separated-by-commas';
static const String keywordsSeparatedByCommas = 'keywords-separated-by-commas';
static const String originalImage = 'original-image';
static const String superResolution = 'super-resolution';
static const String colorizeImage = 'colorize-image';
static const String errorLog = 'error-log';
static const String report = 'report';
static const String latestVersion = 'latest-version';
static const String aIdeaApp = 'aidea-app';
static const String onceEnabledSmartOptimization =
'once-enabled-smart-optimization';
static const String onceEnabledSmartOptimization = 'once-enabled-smart-optimization';
static const String gotIt = 'got-it';
static const String referenceImageNote = 'reference-image-note';
static const String selectReferenceImage = 'select-reference-image';
Expand Down Expand Up @@ -411,6 +409,7 @@ mixin AppLocale {
promptUsage: '领域设定用于设置 AI 角色的行为',
nameRequiredMessage: '请输入名称',
modelRequiredMessage: '请选择 AI 模型',
charactorPromptRequiredMessage: '请输入角色设定',
operateSuccess: '操作成功',
operateFailed: '操作失败',
confirmDelete: '确定删除?',
Expand Down Expand Up @@ -445,8 +444,7 @@ mixin AppLocale {
generating: '创作中...',
generateExitConfirm: '创作中...\n退出后,可在历史记录中查看结果',
tooManyRequests: '操作过于频繁,请稍后再试',
tooManyRequestsOrPaymentRequired:
'操作过于频繁(如果您使用了自定义的 OpenAI Keys,请登录 https://platform.openai.com 检查账户余额是否充足)',
tooManyRequestsOrPaymentRequired: '操作过于频繁(如果您使用了自定义的 OpenAI Keys,请登录 https://platform.openai.com 检查账户余额是否充足)',
promptHint: '设定角色和技能,以便为你提供更精准有效的信息。',
confirmClearCache: '确定要清除缓存吗?',
confirmSignOut: '确定要退出登录吗?',
Expand Down Expand Up @@ -649,8 +647,7 @@ mixin AppLocale {
text: 'Text',
uploading: 'Uploading...',
robotIsThinkingMessage: 'Thinking...',
robotHasSomeError:
'There seems to be something wrong, Do you want to resend the message?',
robotHasSomeError: 'There seems to be something wrong, Do you want to resend the message?',
appName: 'AIdea',
chatAnywhere: 'Chat',
homeTitle: 'Characters',
Expand Down Expand Up @@ -710,6 +707,7 @@ mixin AppLocale {
promptUsage: 'Prompt is used to set the behavior of the AI character',
nameRequiredMessage: 'Please enter the name of the character',
modelRequiredMessage: 'Please select AI model',
charactorPromptRequiredMessage: 'Please enter the charactor prompt',
operateSuccess: 'Success',
operateFailed: 'Failed',
confirmDelete: 'Confirm to delete?',
Expand All @@ -722,10 +720,8 @@ mixin AppLocale {
modelNotValid: 'The current model is not open',
signInRequired: 'You are not logged in, please log in first',
accountNeedReSignin: 'Account exception, please log in again',
openAIAuthFailed:
'You have enabled custom OpenAI service, please check if the API Key is correct',
modelNotFound:
'The current model is not enabled yet, please try again later',
openAIAuthFailed: 'You have enabled custom OpenAI service, please check if the API Key is correct',
modelNotFound: 'The current model is not enabled yet, please try again later',
confirmToDeleteRoom: 'Confirm to delete the character?',
writeYourIdeas: 'Your ideas',
describeYourImages: 'Your ideas',
Expand All @@ -745,8 +741,7 @@ mixin AppLocale {
generateResult: 'Generate result',
generateFailed: 'Creation failed',
generating: 'Generating...',
generateExitConfirm:
'Generating...\nYou can view the result in the history',
generateExitConfirm: 'Generating...\nYou can view the result in the history',
tooManyRequests: 'Too many requests, please try again later',
tooManyRequestsOrPaymentRequired:
'Too many requests (If you are using your own OpenAI Keys, please log in to https://platform.openai.com to check if your account balance is sufficient)',
Expand All @@ -772,21 +767,17 @@ mixin AppLocale {
referenceImage: 'Reference Image',
selectImage: 'Select Image',
imagination: 'Imagination',
keywordsSeparatedByCommas:
'Keywords of the scene you imagine, separated by commas',
keywordsSeparatedByCommas: 'Keywords of the scene you imagine, separated by commas',
originalImage: 'Original Image',
superResolution: 'Super-Resolution',
colorizeImage: 'Colorize Image',
errorLog: 'Error Log',
report: 'Report',
latestVersion: 'You are currently on the latest version',
aIdeaApp:
'AIdea is an app that allows you to converse with AI, and the app code is completely open source.',
onceEnabledSmartOptimization:
'Smart Optimization\n\nOnce enabled, AI will further refine and optimize your ideas.',
aIdeaApp: 'AIdea is an app that allows you to converse with AI, and the app code is completely open source.',
onceEnabledSmartOptimization: 'Smart Optimization\n\nOnce enabled, AI will further refine and optimize your ideas.',
gotIt: 'Got it',
referenceImageNote:
'Reference Image\n\nAI will create based on the reference image provided.',
referenceImageNote: 'Reference Image\n\nAI will create based on the reference image provided.',
selectReferenceImage: 'Please select a reference image',
random: 'Random',
followSystem: 'Follow System',
Expand All @@ -801,17 +792,14 @@ mixin AppLocale {
accountInputTips: 'Enter your phone number or email',
phoneInputTips: 'Enter your phone number',
passwordInputTips: 'Enter your password',
pleaseReadAgreeProtocol:
'Please read and agree to the user agreement and privacy policy first',
pleaseReadAgreeProtocol: 'Please read and agree to the user agreement and privacy policy first',
signInSuccess: 'Sign in success',
signInFailed: 'Sign in failed',
accountRequired: 'Please enter your account',
accountFormatError:
'Account format error\nPlease enter your phone number or email',
accountFormatError: 'Account format error\nPlease enter your phone number or email',
phoneNumberFormatError: 'Phone number format error',
passwordRequired: 'Please enter your password',
passwordFormatError:
'Password format error\nMust be 8-20 digits, letters, special characters',
passwordFormatError: 'Password format error\nMust be 8-20 digits, letters, special characters',
accountCreated: 'Account created',
sendVerifyCode: 'Send',
verifyCode: 'Verify code',
Expand All @@ -831,14 +819,12 @@ mixin AppLocale {
bound: 'Bound',
unbind: 'Unbind',
inviteCode: 'Invite code',
inviteCodeInputTips:
'Enter friend invite code, get extra rewards (optional)',
inviteCodeInputTips: 'Enter friend invite code, get extra rewards (optional)',
inviteCodeFormatError: 'Invite code format error',
enableCustomOpenAI: 'Your custom OpenAI service will be used once enabled',
me: 'Me',
creditsUsage: 'Usage',
creditUsageTips:
'Usage details will be updated the next day, showing usage in the last 30 days.',
creditUsageTips: 'Usage details will be updated the next day, showing usage in the last 30 days.',
updateCheck: 'Check Update',
buy: 'Buy',
paymentHistory: 'Histories',
Expand Down Expand Up @@ -884,8 +870,7 @@ mixin AppLocale {
advanced: 'Advanced',
collapseOptions: 'Collapse',
welcomeMessage: 'Welcome Message',
welcomeMessageTips:
'The system will automatically send a welcome message each time a new chat is started.',
welcomeMessageTips: 'The system will automatically send a welcome message each time a new chat is started.',
memoryDepth: 'Memory Depth',
robotRecommand: 'Recommand',
pickYourRobot: 'Pick your robot',
Expand All @@ -904,8 +889,7 @@ mixin AppLocale {
showInviteCode: 'Show Invite Code',
dontShowInviteCode: 'Don\'t Show Invite Code',
inviteNow: 'Invite Now',
inviteSlogan:
'Invite friends to register, both parties will receive rewards',
inviteSlogan: 'Invite friends to register, both parties will receive rewards',
preview: 'Preview',
download: 'Download',
clickSwitchImage: 'Click to switch image',
Expand Down
Loading

0 comments on commit 731b4d2

Please sign in to comment.