Saya mencoba menerapkan Watson Conversation API di aplikasi iOS saya. Saat meneruskan respon.intents dan respon.entitities ke fungsi issueCommand, saya mendapatkan kesalahan "Tidak dapat mengonversi nilai tipe '[RuntimeIntent]' ke tipe argumen yang diharapkan '[Intent]'". Saya mencoba mengetikkan kedua argumen dari argumen issueCommand tetapi tidak berguna. Alangkah baiknya jika seseorang dapat membimbing saya ke arah yang benar? Terima kasih!
Kodenya adalah sebagai berikut:
func conversationRequestResponse(_ text: String) {
let failure = { (error: Error) in print(error) }
let request = MessageRequest(input: InputData.init(text: text), context: self.context)
self.conversation?.message(workspaceID: Credentials.ConversationWorkspaceID,
request: request,
failure: failure) {
response in
print(response.output.text)
self.didReceiveConversationResponse(response.output.text)
self.context = response.context
var entities: ConversationV1.RuntimeEntity
/// An array of name-confidence pairs for the user input. Include the intents from the previous response when they do not need to change and to prevent Watson from trying to identify them.
// issue command based on intents and entities
print("appl_action: \(response.context.json["appl_action"])")
self.issueCommand(intents: response.intents, entities: response.entities)
}
}
func issueCommand(intents: [Intent], entities: [Entity]) {
for intent in intents {
print("intent: \(intent.intent), confidence: \(intent.confidence) ")
}
for entity in entities {
print("entity: \(entity.entity), value: \(entity.value)")
}
for intent in intents {
if intent.confidence > 0.9 {
switch intent.intent {
case "OnLight":
let command = Command(action: "On", object: "Light", intent: intent.intent)
sendToDevice(command, subtopic: "light")
case "OffLight":
let command = Command(action: "Off", object: "Light", intent: intent.intent)
sendToDevice(command, subtopic: "light")
case "TakePicture":
let command = Command(action: "Take", object: "Picture", intent: intent.intent)
sendToDevice(command, subtopic: "camera")
default:
print("No such command")
return
}
}
}
}
Kesalahannya dapat dilihat pada gambar di bawah ini: