Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/view/page/home/bottom/bottom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ final class _HomeBottomState extends State<_HomeBottom> {
final rs = BakSync.instance.remoteStorage;
if (rs == null) return UIs.placeholder;
return IconButton(
onPressed: () => _onTapSyncChats(context),
onPressed: _onTapSyncChats,
icon: const Icon(Icons.sync, size: 19),
tooltip: libL10n.sync,
);
Expand Down Expand Up @@ -301,7 +301,7 @@ $jsonRaw
);
}

void _onTapSyncChats(BuildContext context) async {
void _onTapSyncChats() async {
await BakSync.instance.sync();
}
}
28 changes: 24 additions & 4 deletions lib/view/page/home/req.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,13 @@ Future<void> _onCreateImg(

final userQuestion = ChatHistoryItem.single(role: ChatRole.user, raw: prompt);
workingChat.items.add(userQuestion);
final assistReply = ChatHistoryItem.gen(
role: ChatRole.assist,
content: [],
);
Comment on lines +351 to +354
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Revisit adding an empty assist reply before the async call.

Since assistReply is added to workingChat.items before initiating the image creation, if the request fails the empty entry remains. Consider whether it should be removed or marked as failed so that the chat history remains consistent.

workingChat.items.add(assistReply);
_chatRN.notify();
_autoScroll(chatId);

final cfg = Cfg.current;
final imgModel = cfg.imgModel;
Expand All @@ -359,6 +365,10 @@ Future<void> _onCreateImg(
return;
}

_loadingChatIds.value.add(chatId);
_loadingChatIds.notify();
_autoHideCtrl.autoHideEnabled = false;

try {
final resp = await Cfg.client.createImage(
request: CreateImageRequest(
Expand All @@ -379,14 +389,23 @@ Future<void> _onCreateImg(
context.showSnackBar(msg);
return;
}
workingChat.items.add(ChatHistoryItem.gen(
role: ChatRole.assist,
content: imgs.map((e) => ChatContent.image(e)).toList(),
));

final imgContents = imgs.map((e) => ChatContent.image(e)).toList();
assistReply.content.addAll(imgContents);

_storeChat(chatId);
_chatRN.notify();
_autoScroll(chatId);

// Only sync if success
BakSync.instance.sync();
} catch (e, s) {
// _onErr handles removing loading state and enabling auto-hide
_onErr(e, s, chatId, 'Create image');
} finally {
_loadingChatIds.value.remove(chatId);
_loadingChatIds.notify();
_autoHideCtrl.autoHideEnabled = true;
}
}

Expand Down Expand Up @@ -615,6 +634,7 @@ void _onReplay({
void _onErr(Object e, StackTrace s, String chatId, String action) {
Loggers.app.warning('$action: $e');
_onStopStreamSub(chatId);
// Ensure loading state is removed and auto-hide is enabled on error
_loadingChatIds.value.remove(chatId);
_loadingChatIds.notify();
_autoHideCtrl.autoHideEnabled = true;
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "v1.0.266"
resolved-ref: e871d4378464393276efdca949e471c7bd7c7efb
ref: "v1.0.268"
resolved-ref: "88908c4e838b15e1bde5b2685ccd016b7578e8a4"
url: "https://github.com/lppcg/fl_lib"
source: git
version: "0.0.1"
Expand Down Expand Up @@ -1018,8 +1018,8 @@ packages:
dependency: "direct main"
description:
path: "packages/openai_dart"
ref: "v1.0.743"
resolved-ref: b3c98f18e39523805503dc545b7370f5cbeaaf7b
ref: "v1.0.744"
resolved-ref: ceb38486df0a49fddb4cb5a3283e566d4462f8ac
url: "https://github.com/lollipopkit/langchain_dart"
source: git
version: "0.4.5"
Expand Down
12 changes: 6 additions & 6 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ dependencies:
image_picker: ^1.0.7
screenshot: ^3.0.0
shortid: ^0.1.2
openai_dart:
git:
url: https://github.com/lollipopkit/langchain_dart
ref: v1.0.743
path: packages/openai_dart
json_annotation: ^4.9.0
freezed_annotation: ^2.4.4
# flutter_riverpod: ^2.6.1
Expand All @@ -41,10 +36,15 @@ dependencies:
ref: master
url: https://github.com/lollipopkit/highlight.dart
path: flutter_highlight
openai_dart:
git:
url: https://github.com/lollipopkit/langchain_dart
ref: v1.0.744
path: packages/openai_dart
fl_lib:
git:
url: https://github.com/lppcg/fl_lib
ref: v1.0.266
ref: v1.0.268

dependency_overrides:
# fl_lib:
Expand Down