From c97ae00426475225a36943a41ddda1f5f2f96b44 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Sat, 24 May 2025 10:50:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E8=B0=83=E8=AF=95=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open_ai_service/OpenAIService.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/OpenAIService.kt b/local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/OpenAIService.kt index 829e872c7..54cfa3347 100644 --- a/local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/OpenAIService.kt +++ b/local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/OpenAIService.kt @@ -514,10 +514,9 @@ class OpenAIService(private val context: Context? = null) : CoroutineScope { if (tools.length() > 0) { put("tools", tools) } - Log.i(TAG, "请求Ai对话: 携带工具数据 ${tools.length()}") - + Log.i(TAG, "liwei------------------- 请求Ai对话: context:${messages.getJSONObject(messages.length() - 1).get("content").toString()} 携带工具数据 ${tools.length()}") } - + val mediaType = "application/json".toMediaTypeOrNull() val request = Request.Builder() .url(baseUrl) @@ -678,6 +677,8 @@ class OpenAIService(private val context: Context? = null) : CoroutineScope { if (function.has("arguments")) { toolCallInfo.arguments += function.getString("arguments") } + Log.d(TAG, "liwei---------------------- AI发起工具调用: tool=$function") + } } } @@ -706,7 +707,7 @@ class OpenAIService(private val context: Context? = null) : CoroutineScope { put("arguments", firstToolCall.arguments) put("id", firstToolCall.id) } - Log.d(TAG, "工具调用: id=${firstToolCall.id}, name=${firstToolCall.name} arguments=${firstToolCall.arguments}") + Log.d(TAG, "liwei---------------------- 工具调用: id=${firstToolCall.id}, name=${firstToolCall.name} arguments=${firstToolCall.arguments}") // 通知上层工具调用事件 callback.onFunctionCall(functionCall) @@ -721,7 +722,7 @@ class OpenAIService(private val context: Context? = null) : CoroutineScope { val args = mcpClient?.parseJsonArguments(firstToolCall.arguments) ?: mapOf() mcpClient?.callTool(firstToolCall.name, args) } catch (e: Exception) { - Log.e(TAG, "工具调用错误: ${e.message}") + Log.e(TAG, "liwei----------------------- 工具调用错误: ${e.message}") JSONObject().put("context", "工具调用失败: ${e.message}") } @@ -733,7 +734,7 @@ class OpenAIService(private val context: Context? = null) : CoroutineScope { val context = resultObj.optString("context", "工具调用失败").let { if (it.isNullOrEmpty()) "工具调用失败" else it } - Log.d(TAG, "mcp工具调用完成: name=${firstToolCall.name}, context=$context") + Log.d(TAG, "liwei----------------------- mcp工具调用完成: name=${firstToolCall.name}, context=$context") // 将结果发送回OpenAI继续对话 sendFunctionCallResult( @@ -746,7 +747,7 @@ class OpenAIService(private val context: Context? = null) : CoroutineScope { } } catch (e: Exception) { if (!isCanceled) { - Log.e(TAG, "处理工具调用异常: ${e.message}") + Log.e(TAG, "liwei----------------------- 处理工具调用异常: ${e.message}") try { val errorMessage = "工具调用处理失败: ${e.message}" sendFunctionCallResult(