|
|
@@ -74,9 +74,6 @@ class ScanImageReplyController extends BaseController {
|
|
|
/// 是否有识别结果
|
|
|
Rx<bool> hasScanResult = false.obs;
|
|
|
|
|
|
- /// 对话分析的订阅(SSE)
|
|
|
- StreamSubscription<Message>? _intimacyReplyAnalyzeSubscription;
|
|
|
-
|
|
|
ScanImageReplyController(
|
|
|
this.intimacyAnalyzeConfigHelper,
|
|
|
this.uploadFileManager,
|
|
|
@@ -91,13 +88,6 @@ class ScanImageReplyController extends BaseController {
|
|
|
_initReplyModeList();
|
|
|
}
|
|
|
|
|
|
- @override
|
|
|
- void onClose() {
|
|
|
- // 取消SSE流数据订阅
|
|
|
- _intimacyReplyAnalyzeSubscription?.cancel();
|
|
|
- super.onClose();
|
|
|
- }
|
|
|
-
|
|
|
/// 初始化回复语气列表
|
|
|
void _initReplyToneOptionSelectConfigList() {
|
|
|
// 语气列表
|
|
|
@@ -260,9 +250,6 @@ class ScanImageReplyController extends BaseController {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 用于累计生成的内容
|
|
|
- StringBuffer buffer = StringBuffer();
|
|
|
-
|
|
|
// 切换为生成中
|
|
|
isResultGenerating.value = true;
|
|
|
hasScanResult.value = false;
|
|
|
@@ -273,60 +260,41 @@ class ScanImageReplyController extends BaseController {
|
|
|
replyToneList.refresh();
|
|
|
|
|
|
// 请求分析截图
|
|
|
- Stream<Message> stream = await intimacyAnalyzeRepository
|
|
|
- .intimacyReplyAnalyze(
|
|
|
- IntimacyReplyAnalyzeRequest(imageList, title, mode),
|
|
|
- );
|
|
|
- _intimacyReplyAnalyzeSubscription = stream.listen(
|
|
|
- (message) {
|
|
|
- // 流数据更新
|
|
|
- String json = message.data;
|
|
|
- // 解析json为实体类
|
|
|
- IntimacyReplyAnalyzeResponse response =
|
|
|
- IntimacyReplyAnalyzeResponse.fromJson(jsonDecode(json));
|
|
|
-
|
|
|
- List<String> contentList =
|
|
|
- response.choices?.map((item) {
|
|
|
- return item.delta?.content ?? "";
|
|
|
- }).toList() ??
|
|
|
- [];
|
|
|
- // 数组转字符串
|
|
|
- String content = contentList.join("");
|
|
|
-
|
|
|
- // 累计内容
|
|
|
- buffer.write(content);
|
|
|
-
|
|
|
- // 刷新列表
|
|
|
- replyToneList.clear();
|
|
|
- replyToneList.add(buffer.toString());
|
|
|
- replyToneList.refresh();
|
|
|
-
|
|
|
- // 改为已有识别结果
|
|
|
- hasScanResult.value = true;
|
|
|
- },
|
|
|
- onError: (error) {
|
|
|
- // 发生异常
|
|
|
- isResultGenerating.value = false;
|
|
|
- hasScanResult.value = false;
|
|
|
-
|
|
|
- AtmobLog.e(_tag, error.toString());
|
|
|
- if (error is ServerErrorException) {
|
|
|
- // 需要Vip权限
|
|
|
- if (error.code == 1005) {
|
|
|
- ToastUtil.show(error.message);
|
|
|
- StorePage.start();
|
|
|
- } else {
|
|
|
- ToastUtil.show(error.message);
|
|
|
- }
|
|
|
+ try {
|
|
|
+ IntimacyReplyAnalyzeResponse response = await intimacyAnalyzeRepository
|
|
|
+ .intimacyReplyAnalyze(
|
|
|
+ IntimacyReplyAnalyzeRequest(imageList, title, mode),
|
|
|
+ );
|
|
|
+ var newList = response.list ?? [];
|
|
|
+
|
|
|
+ // 刷新列表
|
|
|
+ replyToneList.clear();
|
|
|
+ replyToneList.addAll(newList);
|
|
|
+ replyToneList.refresh();
|
|
|
+
|
|
|
+ // 改为已有识别结果
|
|
|
+ hasScanResult.value = true;
|
|
|
+ } catch (error) {
|
|
|
+ // 发生异常
|
|
|
+ isResultGenerating.value = false;
|
|
|
+ hasScanResult.value = false;
|
|
|
+
|
|
|
+ AtmobLog.e(_tag, error.toString());
|
|
|
+ if (error is ServerErrorException) {
|
|
|
+ // 需要Vip权限
|
|
|
+ if (error.code == 1005) {
|
|
|
+ ToastUtil.show(error.message);
|
|
|
+ StorePage.start();
|
|
|
} else {
|
|
|
- ErrorHandler.toastError(error);
|
|
|
+ ToastUtil.show(error.message);
|
|
|
}
|
|
|
- },
|
|
|
- onDone: () {
|
|
|
- // 流关闭
|
|
|
- isResultGenerating.value = false;
|
|
|
- },
|
|
|
- );
|
|
|
+ } else {
|
|
|
+ ErrorHandler.toastError(error);
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ // 生成结束
|
|
|
+ isResultGenerating.value = false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// 删除上传信息
|