Browse Source

上传ai超时逻辑代码

newdev_shunjiawei
liwei1dao 1 year ago
parent
commit
399958cea0
  1. 16
      local_plugins/chat_api/android/src/main/kotlin/com/yunqiinnovation/chat_api/ChatApiService.kt
  2. 2
      pubspec.yaml

16
local_plugins/chat_api/android/src/main/kotlin/com/yunqiinnovation/chat_api/ChatApiService.kt

@ -404,12 +404,24 @@ class ChatApiService(private val context: android.content.Context? = null) : Cor
throw IllegalStateException("OpenAI客户端未初始化")
}
Log.e("ChatApiService", "liwei---------,发送AI请求 model:${currentModel} messages:${chatMessages}")
val flow = openAI!!.chatCompletions(chatCompletionRequest)
// 添加超时控制,10秒超时
val flow = withTimeout(10.seconds) {
openAI!!.chatCompletions(chatCompletionRequest)
}
Log.d(TAG, "liwei-------------------------开始AI 对话 6")
flow
} catch (e: Exception) {
Log.e("ChatApiService", "创建ChatCompletionRequest或调用chatCompletions失败: ${e.message}", e)
throw e
if (sessionid == currSessionId) {
try {
getSessionCallback(sessionid)?.onError(sessionid,ChatApiException("流式请求失败: ${e.message}"))
} catch (ex: Exception) {
Log.e(TAG, "onError回调异常: ${ex.message}", ex)
}
clearCurrentSession()
}
return@launch
// throw e
}
var replyContext = "";

2
pubspec.yaml

@ -53,7 +53,7 @@ dependencies:
flutter_local_notifications: ^18.0.1
device_info_plus: ^11.5.0
uuid: ^4.3.3
record: ^5.2.1
record: ^6.0.0
share_plus: ^11.0.0
image_picker: ^1.1.2
audio_waveforms: ^1.3.0

Loading…
Cancel
Save