Tidak dapat mengonversi nilai tipe '[RuntimeIntent]' ke tipe argumen yang diharapkan '[Intent]'

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:

masukkan deskripsi gambar di sini


person Gurtej Khanooja    schedule 15.12.2017    source sumber
comment
Harap jangan mengambil tangkapan layar kode Anda. Sertakan dalam jawaban Anda sebagai contoh kode.   -  person Tamás Sengel    schedule 15.12.2017
comment
@ the4kman diperbarui!   -  person Gurtej Khanooja    schedule 15.12.2017
comment
Saya memiliki masalah yang sama.   -  person Thomas Suedbroecker    schedule 11.01.2018
comment
Mike telah menulis Jawaban yang berlaku untuk dokumentasi baru. Yang dapat ditemukan di sini: ibm.com/watson/developercloud/conversation/api/v1/#send_message Bagi saya solusinya berhasil, saya masih memiliki masalah lain dengan perubahan lain di API dan realisasi di Swift. Contoh: MessageRequest(input: teks, konteks: self.context) Tidak dapat mengonversi nilai tipe 'String' ke tipe argumen yang diharapkan 'InputData?'   -  person Thomas Suedbroecker    schedule 12.01.2018


Jawaban (1)


Mengapa tidak mengubah tanda tangan issueCommand menjadi RuntimeIntents dan RuntimeEntities saja, seperti:

func issueCommand(intents: [RuntimeIntent], entities: [RuntimeEntity]) {
person Mike Kistler    schedule 22.12.2017