Browse Source

修改音乐播放

newdev_shunjiawei
tanlongsheng 2 years ago
parent
commit
6f78eeabaa
  1. 2
      local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/MCPClient.kt
  2. 25
      local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/OpenAIServicePlugin.kt

2
local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/MCPClient.kt

@ -391,7 +391,7 @@ class MCPSubClient(
else -> "" else -> ""
} }
} }
JSONObject().apply { put("name",name);put("meta",result?._meta.toString()); put("context",context) } JSONObject().apply { put("name",name);put("meta",result?._meta); put("context",context) }
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, "调用MCP工具失败: ${e.message}", e) Log.e(TAG, "调用MCP工具失败: ${e.message}", e)
JSONObject().apply { put("context", "调用MCP工具失败: ${e.message}")} JSONObject().apply { put("context", "调用MCP工具失败: ${e.message}")}

25
local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/OpenAIServicePlugin.kt

@ -22,6 +22,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlinx.serialization.json.JsonObject
import kotlin.math.min import kotlin.math.min
/** OpenAIServicePlugin */ /** OpenAIServicePlugin */
@ -168,25 +169,17 @@ class OpenAIServicePlugin : FlutterPlugin, MethodCallHandler, StreamHandler {
Log.e("OpenAIServicePlugin", "context:${functionCall.toString()}") Log.e("OpenAIServicePlugin", "context:${functionCall.toString()}")
val context = functionCall["context"] val context = functionCall["context"]
if (functionCall.has("meta")) { if (functionCall.has("meta")) {
Log.e("OpenAIServicePlugin", val meta = functionCall.get("meta")
""" val metaJsonObject:JsonObject = meta as JsonObject
工具调用结果 meta 类型: ${functionCall["meta"]?.javaClass?.canonicalName}
值内容: ${functionCall["meta"]}
""".trimIndent()
)
val meta = functionCall["meta"].toString()
// val meta = mapOf<String, Any>(
// "card_spotify" to mapOf<String, Any>(
// "name" to "泡沫",
// "image" to "https://i.scdn.co/image/ab67616d0000b2739f6a38e4bb9c2f824c215e58",
// "url" to "spotify:track:2IfSPLPDW6RGosdB5huwAA",
// "sgener" to "Xposed",
// )
// )
Log.e("OpenAIServicePlugin", "工具调用结果 context:${context} meta:${meta.toString()}") Log.e("OpenAIServicePlugin", "工具调用结果 context:${context} meta:${meta.toString()}")
// 发送函数调用事件 // 发送函数调用事件
mainHandler.post { mainHandler.post {
eventSink?.success(mapOf("type" to "functionCall", "content" to context,"meta" to meta)) eventSink?.success(mapOf("type" to "functionCall", "content" to context,"meta" to meta.toString()))
}
if (metaJsonObject.containsKey("card_spotify")) {
mainHandler.post {
eventSink?.success(mapOf("type" to "complete"))
}
} }
} }

Loading…
Cancel
Save