对话服务的Java代码写为
import com.ibm.watson.developer_cloud.conversation.v1.ConversationService;
import com.ibm.watson.developer_cloud.conversation.v1.model.MessageRequest;
import com.ibm.watson.developer_cloud.conversation.v1.model.MessageResponse;
/*
some code written here
*/
MessageRequest newMessage = new MessageRequest.Builder().inputText(input).context(context).build();
我的主要问题是如何写这个
**MessageRequest newMessage = new MessageRequest.Builder().inputText(input).context(context).build();**
在clojure。
这是我到目前为止所做的
(ns clj.core
(:import
(com.ibm.watson.developer_cloud.conversation.v1 ConversationService)
(com.ibm.watson.developer_cloud.conversation.v1.model MessageRequest)
(com.ibm.watson.developer_cloud.conversation.v1.model MessageResponse)))
(let [username "foo"
password "bar"
input "hello"
context {}
workspaceId "ibm-watson-id"
service (ConversationService. "2017-08-26")
userPass (.setUsernameAndPassword service username password)
;obviously this is wrong
;dont know how to get this right
newMessage (.build (.context context (.inputText input (MessageRequest.Builder.))))
response (.message service workspaceId newMessage)]
response)
请帮忙。谢谢
最佳答案
啊哈,最终弄清楚了,似乎MessageRequest类还有另一个名为Builder的类
我所做的只是参考这节课并调整了有需要的人
(ns clj.core
(:import
(com.ibm.watson.developer_cloud.conversation.v1 ConversationService)
(com.ibm.watson.developer_cloud.conversation.v1.model MessageRequest)
(com.ibm.watson.developer_cloud.conversation.v1.model MessageResponse)))
(let [username "foo"
password "bar"
input "hello"
context {}
workspaceId "ibm-watson-id"
service (ConversationService. "2017-08-26")
userPass (.setUsernameAndPassword service username password)
;just wanna make it work
msgReq (MessageRequest$Builder.)
inputText (.inputText msgReq input)
content (.context inputText context)
newMessage (.build content)
response (.execute (.message service workspaceId newMessage))]
(println "Watson Response: " response))