|
|
|
@ -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 = ""; |
|
|
|
|