Skip to content

Commit

Permalink
Merge pull request #78 from mylxsw/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mylxsw authored Dec 19, 2023
2 parents 3f388c3 + 9d3efb7 commit bc1a8f9
Show file tree
Hide file tree
Showing 46 changed files with 449 additions and 186 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

- 支持 OpenAI 的 GPT-3.5,GPT-4 大语言模型
- 支持 Anthropic 的 Claude instant,Claude 2.0 大语言模型
- 支持国产模型:通义千问,文心一言,讯飞星火,商汤日日新,腾讯混元,百川53B,360智脑
- 支持开源大模型:Llama2,ChatGLM2,AquilaChat 7B,Bloomz 7B 等,后续还将开放更多
- 支持文生图、图生图、超分辨率、黑白图片上色等功能,集成 Stable Diffusion 模型,支持 SDXL 1.0
- 支持 Google 的 Gemini Pro 以及视觉大语言模型
- 支持国产模型:通义千问,文心一言,讯飞星火,商汤日日新,腾讯混元,百川53B,360智脑,天工等
- 支持开源大模型:Yi 34B,Llama2,ChatGLM2,AquilaChat 7B,Bloomz 7B 等,后续还将开放更多
- 支持文生图、图生图、超分辨率、黑白图片上色、艺术字、艺术二维码等功能,支持 SDXL 1.0、Dall·E 3 等

下载体验地址:

Expand Down
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion flutter.compileSdkVersion
compileSdkVersion 34
ndkVersion flutter.ndkVersion

compileOptions {
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.9.20'
repositories {
google()
mavenCentral()
Expand Down
4 changes: 2 additions & 2 deletions lib/bloc/chat_message_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class ChatMessageBloc extends BlocExt<ChatMessageEvent, ChatMessageState> {

// 更新 Room 最后活跃时间
// 这里没有使用 await,因为不需要等待更新完成,让 room 的更新异步的去处理吧
if (!Ability().enableAPIServer()) {
if (!Ability().isUserLogon()) {
chatMsgRepo.updateRoomLastActiveTime(roomId);
}

Expand Down Expand Up @@ -488,7 +488,7 @@ class ChatMessageBloc extends BlocExt<ChatMessageEvent, ChatMessageState> {
Future<Room?> queryRoomById(
ChatMessageRepository chatMsgRepo, int roomId) async {
Room? room;
if (Ability().enableAPIServer()) {
if (Ability().isUserLogon()) {
final roomInServer = await APIServer().room(roomId: roomId);
room = Room(
roomInServer.name,
Expand Down
6 changes: 3 additions & 3 deletions lib/bloc/free_count_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class FreeCountBloc extends Bloc<FreeCountEvent, FreeCountState> {
FreeCountBloc() : super(FreeCountInitial()) {
// 重新加载所有的模型免费使用次数
on<FreeCountReloadAllEvent>((event, emit) async {
if (!Ability().enableAPIServer()) {
if (!Ability().isUserLogon()) {
emit(FreeCountLoadedState(
counts: counts,
counts: await APIServer().freeChatCounts(),
needSignin: event.checkSigninStatus,
));
return;
Expand All @@ -28,7 +28,7 @@ class FreeCountBloc extends Bloc<FreeCountEvent, FreeCountState> {
// 重新加载指定模型的免费使用次数
on<FreeCountReloadEvent>((event, emit) async {
if (Ability().usingLocalOpenAIModel(event.model) ||
!Ability().enableAPIServer()) {
!Ability().isUserLogon()) {
emit(FreeCountLoadedState(counts: counts));
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/bloc/payment_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PaymentBloc extends Bloc<PaymentEvent, PaymentState> {
PaymentBloc() : super(PaymentInitial()) {
on<PaymentLoadAppleProducts>((event, emit) async {
if (PlatformTool.isIOS()) {
final products = await APIServer().applePayProducts();
final products = await APIServer().paymentProducts();
if (products.consume.isEmpty) {
emit(PaymentAppleProductsLoaded(
const <ProductDetails>[],
Expand Down Expand Up @@ -69,7 +69,7 @@ class PaymentBloc extends Bloc<PaymentEvent, PaymentState> {
loading: false,
));
} else {
final products = await APIServer().otherPayProducts();
final products = await APIServer().paymentProducts();
if (products.consume.isEmpty) {
emit(PaymentAppleProductsLoaded(
const <ProductDetails>[],
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/payment_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PaymentInitial extends PaymentState {}

class PaymentAppleProductsLoaded extends PaymentState {
final List<ProductDetails> products;
final List<AppleProduct> localProducts;
final List<PaymentProduct> localProducts;
final Object? error;
final bool loading;
final String? note;
Expand Down
10 changes: 5 additions & 5 deletions lib/bloc/room_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RoomBloc extends BlocExt<RoomEvent, RoomState> {
));
}

if (Ability().enableAPIServer()) {
if (Ability().isUserLogon()) {
final room = await APIServer().room(roomId: event.roomId);
if (event.chatHistoryId != null && event.chatHistoryId! > 0) {
final chatHistory =
Expand Down Expand Up @@ -128,7 +128,7 @@ class RoomBloc extends BlocExt<RoomEvent, RoomState> {
emit(RoomsLoading());

try {
if (Ability().enableAPIServer()) {
if (Ability().isUserLogon()) {
await APIServer().createRoom(
name: event.name,
vendor: event.model.split(':').first,
Expand Down Expand Up @@ -161,7 +161,7 @@ class RoomBloc extends BlocExt<RoomEvent, RoomState> {
emit(RoomsLoading());

try {
if (Ability().enableAPIServer()) {
if (Ability().isUserLogon()) {
await APIServer().deleteRoom(roomId: event.roomId);
} else {
var room = await chatMsgRepo.room(event.roomId);
Expand All @@ -180,7 +180,7 @@ class RoomBloc extends BlocExt<RoomEvent, RoomState> {

// 更新聊天室信息
on<RoomUpdateEvent>((event, emit) async {
if (Ability().enableAPIServer()) {
if (Ability().isUserLogon()) {
final room = await APIServer().updateRoom(
roomId: event.roomId,
name: event.name!,
Expand Down Expand Up @@ -311,7 +311,7 @@ class RoomBloc extends BlocExt<RoomEvent, RoomState> {

Future<RoomsLoaded> createRoomsLoadedState({bool cache = true}) async {
try {
if (Ability().enableAPIServer()) {
if (Ability().isUserLogon()) {
final resp = await APIServer().rooms(cache: cache);
return RoomsLoaded(
resp.rooms
Expand Down
9 changes: 7 additions & 2 deletions lib/helper/ability.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class Ability {
return _instance;
}

/// 是否显示全局警告信息
bool get showGlobalAlert {
return true;
}

/// 服务状态页
String get serviceStatusPage {
return capabilities.serviceStatusPage;
Expand Down Expand Up @@ -104,8 +109,8 @@ class Ability {
return enableOtherPay;
}

/// 是否支持API Server
bool enableAPIServer() {
/// 是否用户已经登陆
bool isUserLogon() {
return setting.stringDefault(settingAPIServerToken, '') != '';
}

Expand Down
2 changes: 1 addition & 1 deletion lib/helper/constant.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';

// 客户端应用版本号
const clientVersion = '1.0.9';
const clientVersion = '1.0.10';
// 本地数据库版本号
const databaseVersion = 26;

Expand Down
2 changes: 1 addition & 1 deletion lib/helper/error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Object? resolveHTTPStatusCode(int statusCode,
return const LanguageText(AppLocale.openAIAuthFailed);
}

if (Ability().enableAPIServer()) {
if (Ability().isUserLogon()) {
return const LanguageText(AppLocale.accountNeedReSignin,
action: 're-signin');
}
Expand Down
6 changes: 5 additions & 1 deletion lib/helper/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ class GlobalEvent {
final Map<String, List<Function(dynamic data)>> _listeners = {};

/// 监听事件
void on(String event, Function(dynamic data) callback) {
Function() on(String event, Function(dynamic data) callback) {
if (_listeners[event] == null) {
_listeners[event] = [];
}

_listeners[event]!.add(callback);

return () {
_listeners[event]!.remove(callback);
};
}

/// 触发事件
Expand Down
8 changes: 8 additions & 0 deletions lib/helper/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ class PlatformTool {
}
}

static bool isLinux() {
try {
return Platform.isLinux;
} catch (e) {
return false;
}
}

static String operatingSystem() {
try {
return Platform.operatingSystem;
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void main() async {
if (kIsWeb) {
databaseFactory = databaseFactoryFfiWeb;
} else {
if (PlatformTool.isWindows()) {
if (PlatformTool.isWindows() || PlatformTool.isLinux()) {
sqfliteFfiInit();
databaseFactory = databaseFactoryFfi;
}
Expand Down
17 changes: 15 additions & 2 deletions lib/page/app_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,30 @@ class AppScaffold extends StatefulWidget {
class _AppScaffoldState extends State<AppScaffold> {
var _showBottomNavigatorBar = true;

Function? cancelHideBottomNavigatorBarEventListener;
Function? cancelShowBottomNavigatorBarEventListener;

@override
void dispose() {
cancelHideBottomNavigatorBarEventListener?.call();
cancelShowBottomNavigatorBarEventListener?.call();

super.dispose();
}

@override
void initState() {
GlobalEvent().on("hideBottomNavigatorBar", (data) {
cancelHideBottomNavigatorBarEventListener =
GlobalEvent().on("hideBottomNavigatorBar", (data) {
if (mounted) {
setState(() {
_showBottomNavigatorBar = false;
});
}
});

GlobalEvent().on("showBottomNavigatorBar", (data) {
cancelShowBottomNavigatorBarEventListener =
GlobalEvent().on("showBottomNavigatorBar", (data) {
if (mounted) {
setState(() {
_showBottomNavigatorBar = true;
Expand Down
12 changes: 11 additions & 1 deletion lib/page/balance/free_statistics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,17 @@ class _FreeStatisticsPageState extends State<FreeStatisticsPage> {
listener: (BuildContext context, FreeCountState state) {
if (state is FreeCountLoadedState) {
if (state.needSignin) {
context.go('/login');
showBeautyDialog(
context,
type: QuickAlertType.warning,
text: '免费模型需登录账号后使用',
confirmBtnText: '去登录',
onConfirmBtnTap: () {
context.pop();
context.go('/login');
},
showCancelBtn: true,
);
}
}
},
Expand Down
60 changes: 30 additions & 30 deletions lib/page/balance/payment.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:askaide/bloc/payment_bloc.dart';
import 'package:askaide/helper/ability.dart';
import 'package:askaide/helper/helper.dart';
import 'package:askaide/helper/logger.dart';
import 'package:askaide/helper/platform.dart';
Expand All @@ -22,6 +23,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_localization/flutter_localization.dart';
import 'package:go_router/go_router.dart';
import 'package:in_app_purchase/in_app_purchase.dart';
import 'package:quickalert/models/quickalert_type.dart';
import 'package:tobias/tobias.dart';
import 'package:url_launcher/url_launcher_string.dart';

Expand Down Expand Up @@ -181,37 +183,20 @@ class _PaymentScreenState extends State<PaymentScreen> {
),
),
actions: [
TextButton(
style: ButtonStyle(
overlayColor: MaterialStateProperty.all(Colors.transparent),
),
onPressed: () {
context.push('/quota-details');
},
child: Text(
AppLocale.paymentHistory.getString(context),
style: TextStyle(color: customColors.weakLinkColor),
textScaleFactor: 0.9,
if (Ability().isUserLogon())
TextButton(
style: ButtonStyle(
overlayColor: MaterialStateProperty.all(Colors.transparent),
),
onPressed: () {
context.push('/quota-details');
},
child: Text(
AppLocale.paymentHistory.getString(context),
style: TextStyle(color: customColors.weakLinkColor),
textScaleFactor: 0.9,
),
),
),
// TextButton(
// style: ButtonStyle(
// overlayColor: MaterialStateProperty.all(Colors.transparent),
// ),
// onPressed: () {
// _startPaymentLoading();
// // 恢复购买
// InAppPurchase.instance.restorePurchases().whenComplete(() {
// _closePaymentLoading();
// showSuccessMessage('恢复完成');
// });
// },
// child: Text(
// '恢复购买',
// style: TextStyle(color: customColors.weakLinkColor),
// textScaleFactor: 0.9,
// ),
// ),
],
),
backgroundColor: customColors.backgroundContainerColor,
Expand Down Expand Up @@ -312,6 +297,21 @@ class _PaymentScreenState extends State<PaymentScreen> {
return;
}

if (!Ability().isUserLogon()) {
showBeautyDialog(
context,
type: QuickAlertType.warning,
text: '该功能需要登录账号后使用',
onConfirmBtnTap: () {
context.pop();
context.push('/login');
},
showCancelBtn: true,
confirmBtnText: '立即登录',
);
return;
}

if (PlatformTool.isIOS() ||
PlatformTool.isAndroid() ||
PlatformTool.isMacOS()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/page/balance/price_block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class PriceBlock extends StatelessWidget {
final CustomColors customColors;
final ProductDetails detail;
final ProductDetails? selectedProduct;
final AppleProduct product;
final PaymentProduct product;
final bool loading;

const PriceBlock({
Expand Down
Loading

0 comments on commit bc1a8f9

Please sign in to comment.