2017-05-02 155 views
-1

爲核心的Java對話服務的例子做工精細的Spring MVC,沃森談話

對於Spring MVC的是顯示錯誤一樣,

"Exception in thread "main" java.lang.NoSuchMethodError: com.ibm.watson.developer_cloud.conversation.v1.ConversationService.createServiceCall(Lokhttp3/Request;Lcom/ibm/watson/developer_cloud/http/ResponseConverter;)Lcom/ibm/watson/developer_cloud/http/ServiceCall; at com.ibm.watson.developer_cloud.conversation.v1.ConversationService.message(ConversationService.java:89)"

我使用下面的例子

ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2017_02_03,"username", "password"); 

Scanner sc = new Scanner(System.in); 
String workspaceId = "workspaceId "; 
String str = "open",response1; 

do { 
    System.out.println("Start chat"); 
    str = sc.nextLine(); 
    MessageRequest newMessage = new MessageRequest.Builder().inputText(str).build(); 
    MessageResponse response = service.message(workspaceId, newMessage).execute(); 
    response1 = response.getText().toString(); 
    System.out.println(response1.replace("[","").replace("]","")); 
    //System.out.println(response1); 
} while(!(str.contains("bye"))); 

回答

1

你可以請參閱Official Documentation JAVA SDK以使用IBM Watson API,他們使用此示例:

依賴(Maven的)

<dependency> 
    <groupId>com.ibm.watson.developer_cloud</groupId> 
    <artifactId>conversation</artifactId> 
    <version>3.8.0</version> 
</dependency> 

搖籃:

'com.ibm.watson.developer_cloud:conversation:3.8.0' 

代碼來使用會話服務,以確定意圖,實體和行爲的對話:

//set version 
ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2017_03_02); 

//setUsername and you Password inside your Conversation Service (Service Credentials) 
service.setUsernameAndPassword("<username>", "<password>"); 
//send a Message from your code, in this case "Hi" 
MessageRequest newMessage = new MessageRequest.Builder().inputText("Hi").build(); 
//set your workspace_id for use the conversation you wants 
MessageResponse response = service.message("<workspace-id>", newMessage).execute(); 
System.out.println(response); 

我不是Java語言的專家,但是,這對我來說很好。您可以在SDK中看到對話服務正在等待參數version_dateusernamepassword。但是,他們使用一個條件setUsernameAndPassword。我認爲這是問題。

檢查從Java SDK中的#83線使用會話:

public ConversationService(final String versionDate, String username, String password) { 
    this(versionDate); 
    //set username with this 
    setUsernameAndPassword(username, password); 
    }