Watson Conversation:无法执行ServiceCall

时间:2016-07-14 15:11:56

标签: java ibm-watson

我正在使用Watson Conversation。尝试在ResponseUtils的第90行(在getObject中)执行ServiceCall时出现异常:

final T model = GsonSingleton.getGsonWithoutPrettyPrinting().fromJson(reader, type);

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 1 column 647 path $.output.text

我探索了回应,我看到了这个: 响应{protocol = http / 1.1,code = 200,message = OK,url = https://gateway.watsonplatform.net/conversation-experimental/api/v1/workspaces/200afa7d-c71f-472a-ab6e-5bf162f6e319/message?version=2016-05-19}

这是我的代码:

import com.ibm.watson.developer_cloud.conversation.v1_experimental.ConversationService;
import com.ibm.watson.developer_cloud.conversation.v1_experimental.model.Message;
import com.ibm.watson.developer_cloud.conversation.v1_experimental.model.NewMessageOptions;
import com.ibm.watson.developer_cloud.conversation.v1_experimental.model.NewMessageOptions.Builder;
import com.ibm.watson.developer_cloud.http.ServiceCall;

public class TestConversation {
    public static void main(String[] args) throws Exception{

        ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2016_05_19);
        service.setEndPoint("https://gateway.watsonplatform.net/conversation-experimental/api");
        service.setUsernameAndPassword("xxxxxxxx", "xxxxxx");

        Builder builder = new NewMessageOptions.Builder().workspaceId("xxxxxxxxxxxx");
        NewMessageOptions newMessageOptions = builder.inputText("hi").build();

        ServiceCall<Message> serviceCall = service.message(newMessageOptions);
        Message answer = serviceCall.execute();
    }
}

1 个答案:

答案 0 :(得分:0)

解决。我换成了Watson的其他sdk: https://github.com/watson-developer-cloud/java-sdk/tree/7db5d534250200625691a186c8b2aa4f98bb6a20

所以,我使用这段代码并且工作正常:

ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2016_05_19);
service.setUsernameAndPassword("xxxxxxxxx", "xxxxxxx");
service.setEndPoint("https://gateway.watsonplatform.net/conversation-experimental/api");

MessageRequest newMessage = new MessageRequest.Builder().inputText("Hola").build();
MessageResponse response = service.message("xxxxxxxx", newMessage).execute();
System.out.println(response.getText());