【问题标题】:Watson Conversation: cannot execute ServiceCallWatson 对话:无法执行 ServiceCall
【发布时间】:2023-03-18 12:15:01
【问题描述】:

我正在使用 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();
    }
}

【问题讨论】:

    标签: java ibm-watson


    【解决方案1】:

    解决了。我换成了 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());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-20
      相关资源
      最近更新 更多