沃森对话:无法执行ServiceCall [英] Watson Conversation: cannot execute ServiceCall

查看:95
本文介绍了沃森对话:无法执行ServiceCall的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using Watson Conversation. I get an exception when trying to execute a ServiceCall, at line 90 of ResponseUtils (in getObject):

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 =

I explore the response and I see this: Response{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();
    }
}

推荐答案

已解决.我改用了Watson的其他SDK: https://github.com/watson-developer-cloud/java-sdk /tree/7db5d534250200625691a186c8b2aa4f98bb6a20

Solved. I changed to other sdk of Watson: https://github.com/watson-developer-cloud/java-sdk/tree/7db5d534250200625691a186c8b2aa4f98bb6a20

因此,我使用此代码,它可以正常工作:

So, I use this code and it works fine:

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());

这篇关于沃森对话:无法执行ServiceCall的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆