Browse Source

处理部分卡片不需要播放的问题

weicu
liwei1dao 1 year ago
parent
commit
06c76bd828
  1. 20
      local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt

20
local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt

@ -662,7 +662,7 @@ object AgentService : CoroutineScope {
val responseBuilder = StringBuilder()
var aiMetadata:String = ""
var userMetadata = JSONObject()
var nobroadcast = false
// 如果有图片,添加图片信息到元数据
if (hasImage) {
userMetadata.put("hasImage", true)
@ -717,7 +717,7 @@ object AgentService : CoroutineScope {
callback = object : OpenAIService.StreamCallback {
override fun onToken(token: String) {
responseBuilder.append(token)
if (speakResponse) {
if (speakResponse && !nobroadcast) {
ttsService?.speakStream(token)
}
// 发送流式回复token
@ -748,8 +748,6 @@ object AgentService : CoroutineScope {
// 保存聊天记录
saveChatMessage(displayText, response,aiMetadata,userMetadata.toString())
}
// 标记AI流式输出已完成
@ -792,7 +790,9 @@ object AgentService : CoroutineScope {
"result" to functionCallResult.toString(),
))
Log.d(TAG, "mcp调用结果: $functionCallResult")
aiMetadata = autoHandleFcunCallResult(functionCallResult);
val (metestr, broadcast)= autoHandleFcunCallResult(functionCallResult);
aiMetadata = metestr;
nobroadcast = broadcast
}
}
)
@ -1108,8 +1108,9 @@ object AgentService : CoroutineScope {
/*
* 自动播放音乐
* */
fun autoHandleFcunCallResult(functionCallResult: JSONObject): String{
fun autoHandleFcunCallResult(functionCallResult: JSONObject): Pair<String, Boolean>{
val metaStr = functionCallResult.optString("meta")
var broadcast = false;
if (metaStr.isNotEmpty()) {
val meta = JSONObject(metaStr)
// Log.d(TAG, "mcp调用结果: $metaStr")
@ -1122,6 +1123,7 @@ object AgentService : CoroutineScope {
val sgener = cardMusic.optString("sgener", "")
val image = cardMusic.optString("image", "")
processMusicPlay(mapOf("id" to id,"url" to url, "title" to name, "artist" to sgener,"coverUrl" to image))
broadcast = true;
}else if (meta.has("card_musiclist")) { //音乐列表
val cardMusiclist = meta.getJSONObject("card_musiclist")
val musics = cardMusiclist.optJSONArray("musics")
@ -1138,6 +1140,7 @@ object AgentService : CoroutineScope {
}
if (playlist.isNotEmpty()) {
Log.w(TAG, "自动播放音乐列表 ${playlist}")
broadcast = true;
processMusicPlayList(playlist)
} else {
Log.w(TAG, "card_musiclist 中没有有效的音乐条目")
@ -1149,11 +1152,12 @@ object AgentService : CoroutineScope {
val cardNavigation = meta.getJSONObject("card_navigation")
val start = cardNavigation.optString("start", "")
val end = cardNavigation.optString("end", "")
broadcast = true;
processNavigation(start,end);
}
return metaStr;
return Pair(metaStr, broadcast);
}
return "";
return Pair("", false);
}
/**

Loading…
Cancel
Save