diff --git a/local_plugins/chat_api/android/src/main/kotlin/com/yunqiinnovation/chat_api/ChatApiService.kt b/local_plugins/chat_api/android/src/main/kotlin/com/yunqiinnovation/chat_api/ChatApiService.kt index 6e3300759..bb0c13109 100644 --- a/local_plugins/chat_api/android/src/main/kotlin/com/yunqiinnovation/chat_api/ChatApiService.kt +++ b/local_plugins/chat_api/android/src/main/kotlin/com/yunqiinnovation/chat_api/ChatApiService.kt @@ -628,21 +628,21 @@ class ChatApiService(private val context: android.content.Context? = null) : Cor mapOf("context" to "Tool not found: $functionName") } if (sessionid == currSessionId) { - // 处理结果 - try { - if(!isError){ - getSessionCallback(sessionid)?.onFunctionCallResult( - sessionid, - convertMapToJsonObject(functionCall), - convertMapToJsonObject(result) - ) - }else{ - getSessionCallback(sessionid)?.onError(sessionid, ChatApiException(errorText)) - } - } catch (e: Exception) { - Log.e(TAG, "onFunctionCallResult回调异常: ${e.message}", e) - } if (functionName != "set_user_profile_field"){ + // 处理结果 + try { + if(!isError){ + getSessionCallback(sessionid)?.onFunctionCallResult( + sessionid, + convertMapToJsonObject(functionCall), + convertMapToJsonObject(result) + ) + }else{ + getSessionCallback(sessionid)?.onError(sessionid, ChatApiException(errorText)) + } + } catch (e: Exception) { + Log.e(TAG, "onFunctionCallResult回调异常: ${e.message}", e) + } // 将结果发送回OpenAI继续对话 sendFunctionCallResultInternal( sessionid= sessionid, @@ -650,6 +650,13 @@ class ChatApiService(private val context: android.content.Context? = null) : Cor functionCall = functionCall, functionResult = gson.toJson(result) ) + }else{ + try { + getSessionCallback(sessionid)?.onComplete(sessionid) + } catch (ex: Exception) { + Log.e(TAG, "onComplete回调异常: ${ex.message}", ex) + } + clearCurrentSession() } } } diff --git a/local_plugins/chat_api/ios/chat_api/Sources/chat_api/ChatApiService.swift b/local_plugins/chat_api/ios/chat_api/Sources/chat_api/ChatApiService.swift index 6c6415f72..341279185 100644 --- a/local_plugins/chat_api/ios/chat_api/Sources/chat_api/ChatApiService.swift +++ b/local_plugins/chat_api/ios/chat_api/Sources/chat_api/ChatApiService.swift @@ -465,8 +465,8 @@ private func processToolCalls(_ sessionId:String) async -> Bool { "id": firstToolCall.id ] // 转换为JSON对象格式 -let jsonFunctionCall = convertMapToJsonObject(functionCall) -getSessionCallback(sessionId)?.onFunctionCall(sessionId, jsonFunctionCall) + let jsonFunctionCall = convertMapToJsonObject(functionCall) + getSessionCallback(sessionId)?.onFunctionCall(sessionId, jsonFunctionCall) // 通知上层工具调用事件 // getSessionCallback(sessionId)?.onFunctionCall(sessionId, functionCall) @@ -541,8 +541,10 @@ getSessionCallback(sessionId)?.onFunctionCall(sessionId, jsonFunctionCall) functionCall: functionCall, functionResult: self.jsonToString(result) ?? "{}" ) + }else{ + self.getSessionCallback(sessionId)?.onComplete(sessionId) + self.clearCurrentSession() } - } } } catch {