Skip to content

Commit

Permalink
new: custom model
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed May 27, 2024
1 parent d7bab95 commit de48ce6
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 142 deletions.
2 changes: 1 addition & 1 deletion lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:fl_lib/fl_lib.dart';
import 'package:fl_lib/l10n/gen/lib_l10n.dart';
import 'package:fl_lib/l10n/gen_l10n/lib_l10n.dart';
import 'package:flutter/material.dart';
import 'package:gpt_box/data/res/l10n.dart';
import 'package:gpt_box/data/res/rnode.dart';
Expand Down
6 changes: 3 additions & 3 deletions lib/data/model/chat/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:shortid/shortid.dart';
part 'config.g.dart';

const _kUrl = 'https://api.openai.com';
const _kModel = 'gpt-4o';
const kChatModel = 'gpt-4o';
const _kHistoryLen = 7;
const _kImgModel = 'dall-e-3';
const _kSpeechModel = 'tts-1';
Expand All @@ -19,7 +19,7 @@ final class ChatConfig {
final String url;
@HiveField(2, defaultValue: '')
final String key;
@HiveField(3, defaultValue: _kModel)
@HiveField(3, defaultValue: kChatModel)
final String model;
@HiveField(7, defaultValue: _kHistoryLen)
final int historyLen;
Expand Down Expand Up @@ -58,7 +58,7 @@ final class ChatConfig {
prompt: '',
url: _kUrl,
key: '',
model: _kModel,
model: kChatModel,
historyLen: _kHistoryLen,
name: '',
imgModel: _kImgModel,
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"copied": "Copied",
"copy": "Copy",
"current": "Current",
"custom": "Custom",
"day": "day",
"defaulT": "Default",
"delFmt": "Delete {type}({id})?",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"copied": "已复制",
"copy": "复制",
"current": "当前",
"custom": "自定义",
"day": "天",
"defaulT": "默认",
"delFmt": "删除 {type}({id})?",
Expand Down
4 changes: 2 additions & 2 deletions lib/view/page/backup/impl/webdav.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Future<void> _onTapWebdavSetting(BuildContext context) async {
context.showRoundDialog(
title: l10n.error,
child: Text(err),
actions: Btns.oks(onTap: context.pop, okStr: l10n.ok),
actions: Btns.oks(onTap: context.pop),
);
}

Expand Down Expand Up @@ -156,6 +156,6 @@ Future<void> _onTapWebdavSetting(BuildContext context) async {
),
],
),
actions: Btns.oks(onTap: onSubmit, okStr: l10n.ok),
actions: Btns.oks(onTap: onSubmit),
);
}
1 change: 0 additions & 1 deletion lib/view/page/home/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ class _ChatPageState extends State<_ChatPage>
actions: Btns.oks(
onTap: () => context.pop(true),
red: true,
okStr: l10n.ok,
),
);
if (result != true) return;
Expand Down
4 changes: 1 addition & 3 deletions lib/view/page/home/ctrl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ void _onTapDeleteChat(String chatId, BuildContext context) {
context.pop();
},
red: true,
okStr: l10n.ok,
),
);
}
Expand Down Expand Up @@ -109,7 +108,7 @@ void _onTapRenameChat(String chatId, BuildContext context) async {
autoFocus: true,
onSubmitted: (p0) => context.pop(p0),
),
actions: Btns.oks(onTap: () => context.pop(ctrl.text), okStr: l10n.ok),
actions: Btns.oks(onTap: () => context.pop(ctrl.text)),
);
if (title == null || title.isEmpty) return;
entity.name = title;
Expand Down Expand Up @@ -330,7 +329,6 @@ void _onTapReplay(
actions: Btns.oks(
onTap: () => context.pop(true),
red: true,
okStr: l10n.ok,
),
);
if (sure != true) return;
Expand Down
8 changes: 3 additions & 5 deletions lib/view/page/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ final class ImagePage extends StatelessWidget {
onPressed: () async {
final sure = await context.showRoundDialog(
title: l10n.delete,
child:
Text(l10n.delFmt(args?.title ?? l10n.untitled, l10n.image)),
actions: Btns.oks(
onTap: () => context.pop(true),
okStr: l10n.ok,
child: Text(
l10n.delFmt(args?.title ?? l10n.untitled, l10n.image),
),
actions: Btns.oks(onTap: () => context.pop(true)),
);
if (sure != true) return;
context.pop(const ImagePageRet(isDeleted: true));
Expand Down
48 changes: 24 additions & 24 deletions lib/view/page/setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ class _SettingPageState extends State<SettingPage> {
_onSaveColor(ctrl.text);
context.pop();
},
okStr: l10n.ok,
),
);
},
Expand Down Expand Up @@ -258,7 +257,6 @@ class _SettingPageState extends State<SettingPage> {
}
},
red: true,
okStr: l10n.ok,
),
);
},
Expand Down Expand Up @@ -293,7 +291,6 @@ class _SettingPageState extends State<SettingPage> {
),
actions: Btns.oks(
onTap: () => context.pop(ctrl.text),
okStr: l10n.ok,
),
);
if (name == null) return;
Expand Down Expand Up @@ -345,7 +342,6 @@ class _SettingPageState extends State<SettingPage> {
),
actions: Btns.oks(
onTap: () => context.pop(ctrl.text),
okStr: l10n.ok,
),
);
if (result == null) return;
Expand Down Expand Up @@ -375,7 +371,6 @@ class _SettingPageState extends State<SettingPage> {
),
actions: Btns.oks(
onTap: () => context.pop(ctrl.text),
okStr: l10n.ok,
),
);
if (result == null) return;
Expand All @@ -386,7 +381,6 @@ class _SettingPageState extends State<SettingPage> {
actions: Btns.oks(
onTap: () => context.pop(true),
red: true,
okStr: l10n.ok,
),
);
if (sure != true) return;
Expand Down Expand Up @@ -422,10 +416,7 @@ class _SettingPageState extends State<SettingPage> {
context.showRoundDialog(
title: l10n.attention,
child: Text(l10n.needOpenAIKey),
actions: Btns.oks(
onTap: () => context.pop(),
okStr: l10n.ok,
),
actions: Btns.oks(onTap: context.pop),
);
return;
}
Expand All @@ -441,6 +432,26 @@ class _SettingPageState extends State<SettingPage> {
items: modelStrs,
initial: val,
title: l10n.model,
actions: [
TextButton(
onPressed: () {
context.pop();
context.showRoundDialog(
title: l10n.custom,
child: Input(
hint: kChatModel,
onSubmitted: (s) {
context.pop();
OpenAICfg.current = OpenAICfg.current.copyWith(model: s);
_cfgRN.build();
},
),
actions: Btns.oks(onTap: context.pop),
);
},
child: Text(l10n.custom),
),
],
);
if (model != null) {
OpenAICfg.current = OpenAICfg.current.copyWith(model: model);
Expand All @@ -462,10 +473,7 @@ class _SettingPageState extends State<SettingPage> {
context.showRoundDialog(
title: l10n.attention,
child: Text(l10n.needOpenAIKey),
actions: Btns.oks(
onTap: () => context.pop(),
okStr: l10n.ok,
),
actions: Btns.oks(onTap: context.pop),
);
return;
}
Expand Down Expand Up @@ -502,10 +510,7 @@ class _SettingPageState extends State<SettingPage> {
context.showRoundDialog(
title: l10n.attention,
child: Text(l10n.needOpenAIKey),
actions: Btns.oks(
onTap: () => context.pop(),
okStr: l10n.ok,
),
actions: Btns.oks(onTap: context.pop),
);
return;
}
Expand Down Expand Up @@ -542,10 +547,7 @@ class _SettingPageState extends State<SettingPage> {
context.showRoundDialog(
title: l10n.attention,
child: Text(l10n.needOpenAIKey),
actions: Btns.oks(
onTap: () => context.pop(),
okStr: l10n.ok,
),
actions: Btns.oks(onTap: context.pop),
);
return;
}
Expand Down Expand Up @@ -593,7 +595,6 @@ class _SettingPageState extends State<SettingPage> {
),
actions: Btns.oks(
onTap: () => context.pop(ctrl.text),
okStr: l10n.ok,
),
);
if (result == null) return;
Expand Down Expand Up @@ -623,7 +624,6 @@ class _SettingPageState extends State<SettingPage> {
),
actions: Btns.oks(
onTap: () => context.pop(ctrl.text),
okStr: l10n.ok,
),
);
if (result == null) return;
Expand Down
Loading

0 comments on commit de48ce6

Please sign in to comment.