fix: 修复LogInterceptor 导致message不能流式吐字的问题
This commit is contained in:
@@ -4,6 +4,7 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
// 负责录音相关功能
|
||||
@Deprecated('AudioRecorderService Deprecated')
|
||||
class AudioRecorderService {
|
||||
final AudioRecorder _recorder = AudioRecorder();
|
||||
bool _isRecording = false;
|
||||
|
||||
@@ -7,6 +7,8 @@ import '../utils/tts_util.dart';
|
||||
|
||||
import '../utils/common_util.dart';
|
||||
|
||||
@Deprecated('ChatSseService Deprecated, Use ai_chat_core/ChatSseService instead')
|
||||
/// SSE 服务类,处理与后端的流式通信
|
||||
class ChatSseService {
|
||||
// 缓存用户ID和会话ID
|
||||
String? _cachedUserId;
|
||||
@@ -112,14 +114,17 @@ class ChatSseService {
|
||||
break;
|
||||
}
|
||||
if (line.startsWith('data:')) {
|
||||
print('SSE line: $line');
|
||||
final jsonStr = line.substring(5).trim();
|
||||
if (jsonStr == '[DONE]' || jsonStr.contains('message_end')) {
|
||||
TtsUtil.complete();
|
||||
onStreamResponse(messageId, responseText, true);
|
||||
break;
|
||||
}
|
||||
print('SSE json: $jsonStr');
|
||||
try {
|
||||
final jsonData = json.decode(jsonStr);
|
||||
print('SSE jsonData: $jsonData');
|
||||
if (jsonData.containsKey('conversation_id') &&
|
||||
_cachedConversationId == null) {
|
||||
_cachedConversationId = jsonData['conversation_id'];
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class TextClassificationService {
|
||||
Future<int> classifyText(String text) async {
|
||||
try {
|
||||
final uri = Uri.parse('http://143.64.185.20:18606/classify');
|
||||
|
||||
final response = await http.post(
|
||||
uri,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: json.encode({'text': text}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return json.decode(response.body)['category'];
|
||||
} else {
|
||||
print(
|
||||
'Classification failed: ${response.statusCode}, ${response.body}');
|
||||
return -1;
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error during text classification: $e');
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import 'package:flutter/services.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import '../services/chat_sse_service.dart' as Service;
|
||||
import '../services/classification_service.dart';
|
||||
import '../services/control_recognition_service.dart';
|
||||
// import '../services/audio_recorder_service.dart';
|
||||
// import '../services/voice_recognition_service.dart';
|
||||
@@ -86,8 +85,8 @@ class MessageService extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
// final ChatSseService _chatSseService = ChatSseService(PlatformTtsService(aliSdkChannelName));
|
||||
final Service.ChatSseService _chatSseService = Service.ChatSseService();
|
||||
final ChatSseService _chatSseService = ChatSseService(PlatformTtsService(aliSdkChannelName));
|
||||
// final Service.ChatSseService _chatSseService = Service.ChatSseService();
|
||||
|
||||
// final LocalTtsService _ttsService = LocalTtsService();
|
||||
// final AudioRecorderService _audioService = AudioRecorderService();
|
||||
|
||||
Reference in New Issue
Block a user