【问题标题】:How to use the Watson Conversation inside iOS Swift?如何在 iOS Swift 中使用 Watson Conversation?
【发布时间】:2018-01-12 09:39:29
【问题描述】:

我将根据Build a home assistant mobile application with Watson and IoT Platform services更新我的自定义示例

在这段代码中,我得到消息:

无法将“字符串”类型的值转换为预期的参数类型“输入数据”?

如何解决这个问题? 在documentation of developer cloud/conversation/api里面我可以找到InputData的定义,但是NO示例如何在Swift iOS中实现呢?

    // Based on API Changes
    // ====================
    // Incorrect argument label in call (have 'text:context:', expected 'input:context:')
    // Cannot convert value of type 'String' to expected argument type 'InputData?'
    let request = MessageRequest(input: 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
                                // issue command based on intents and entities
                                // Additional Properties:
                                // response.context.json -> response.context.additionalProperties
                                print("appl_action: \(response.context.additionalProperties["appl_action"])")
                                self.issueCommand(intents: response.intents, entities: response.entities)
    }

【问题讨论】:

    标签: ios swift watson-conversation


    【解决方案1】:

    MessageRequest 构造函数的input 参数采用InputData 对象,该对象很容易从文本字符串构造。试试

    let input = InputData(text: text)
    let request = MessageRequest(input: input, context: self.context)
    self.conversation?.message(workspaceID: Credentials.ConversationWorkspaceID,
                               request: request,
                               failure: failure) {
    

    【讨论】:

    • 你好,迈克,谢谢,但现在解决这个问题后,我遇到了“找不到框架 RestKit”的另一个问题。问候,托马斯
    • 如果您使用的是最新版本的 Watson Swift SDK,它不再将 RestKit 构建为单独的框架,而是将其直接链接到每个服务中。所以你应该能够从你的项目中删除 RestKit 框架。
    • 感谢您的反馈。我不确定这个你能看看这里吗:stackoverflow.com/questions/48277430/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-26
    • 2017-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-14
    相关资源
    最近更新 更多