• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java AIServiceException类的典型用法和代码示例

java 4次浏览

本文整理汇总了Java中ai.api.AIServiceException的典型用法代码示例。如果您正苦于以下问题:Java AIServiceException类的具体用法?Java AIServiceException怎么用?Java AIServiceException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

AIServiceException类属于ai.api包,在下文中一共展示了AIServiceException类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: voiceRequest

点赞 3

import ai.api.AIServiceException; //导入依赖的package包/类
/**
 * @see AIDataService#voiceRequest(InputStream, RequestExtras, AIServiceContext)
 */
@Override
public AIResponse voiceRequest(InputStream voiceStream, RequestExtras requestExtras,
		AIServiceContext serviceContext) throws AIServiceException {
	
  RecognizeResponse response;
	try {
	    SpeechClient speechClient = SpeechClient.create();
		RecognitionAudio recognitionAudio = createRecognitionAudio(voiceStream);

        response = speechClient.recognize(config.getRecognitionConfig(), recognitionAudio);
	} catch (IOException | StatusRuntimeException e) {
		throw new AIServiceException("Failed to recognize speech", e);
	}
	if ((response.getResultsCount() == 0) || (response.getResults(0).getAlternativesCount() == 0)) {
		throw new AIServiceException("No speech");
	}
	String transcript = response.getResults(0).getAlternatives(0).getTranscript();
	AIRequest request = new AIRequest(transcript);
	return request(request, requestExtras, serviceContext);
}
 

开发者ID:dialogflow,
项目名称:dialogflow-java-client,
代码行数:24,
代码来源:GcpAIDataService.java

示例2: legacySpeechTest

点赞 3

import ai.api.AIServiceException; //导入依赖的package包/类
@Test
public void legacySpeechTest() throws MalformedURLException, AIServiceException {
    final AIConfiguration config = new AIConfiguration(
            "3485a96fb27744db83e78b8c4bc9e7b7",
            AIConfiguration.SupportedLanguages.English);

    config.setProtocolVersion(PROTOCOL_VERSION);

    final SimpleProtocolTestingService aiService = new SimpleProtocolTestingService(config);

    final AIRequest aiRequest = new AIRequest();
    aiRequest.setQuery("hello");
    prepareRequest(aiRequest, config);

    final String textRequest = gson.toJson(aiRequest);
    final String textResponse = aiService.doDefaultProtocolTextRequest(textRequest);

    final AIResponseV20150204 aiResponse = gson.fromJson(textResponse, AIResponseV20150204.class);

    assertNotNull(aiResponse);
    assertEquals("Hi! How are you?", aiResponse.getResult().getSpeech());
}
 

开发者ID:dialogflow,
项目名称:dialogflow-java-client,
代码行数:23,
代码来源:V20150204ProtocolTest.java

示例3: legacyContextsWithoutParametersTest

点赞 3

import ai.api.AIServiceException; //导入依赖的package包/类
@Test
public void legacyContextsWithoutParametersTest() throws AIServiceException {
    final AIConfiguration config = new AIConfiguration(
            "3485a96fb27744db83e78b8c4bc9e7b7",
            AIConfiguration.SupportedLanguages.English,
            AIConfiguration.RecognitionEngine.System);

    config.setProtocolVersion(PROTOCOL_VERSION);

    final AIDataService aiDataService = new AIDataService(RuntimeEnvironment.application, config);

    final AIContext weatherContext = new AIContext("weather");
    weatherContext.setParameters(Collections.singletonMap("location", "London"));

    final List<AIContext> contexts = Collections.singletonList(weatherContext);

    final AIRequest aiRequest = new AIRequest();
    aiRequest.setQuery("and for tomorrow");
    aiRequest.setContexts(contexts);

    final AIResponse aiResponse = aiDataService.request(aiRequest);

    // Old protocol doesn't support parameters, so response will not contains city name
    assertEquals("Weather in for tomorrow", aiResponse.getResult().getFulfillment().getSpeech());

}
 

开发者ID:dialogflow,
项目名称:dialogflow-android-client,
代码行数:27,
代码来源:V20150415ProtocolTest.java

示例4: sendRequest

点赞 2

import ai.api.AIServiceException; //导入依赖的package包/类
private void sendRequest(Message message, String request) {
    try {
        AIResponse response = service.request(new AIRequest(request));

        String action = response.getResult().getAction();
        AvaIre.getLogger().info(ACTION_OUTPUT
            .replace("%action%", action)
            .replace("%author%", generateUsername(message))
            .replace("%server%", generateServer(message))
            .replace("%channel%", generateChannel(message))
            .replace("%message%", message.getRawContent())
            .replace("%response%", response.getResult().getFulfillment().getSpeech())
        );

        if (response.getStatus().getCode() != 200) {
            MessageFactory.makeError(message, response.getStatus().getErrorDetails()).queue();
            return;
        }

        for (Map.Entry<IntentAction, Intent> entry : INTENTS.entrySet()) {
            if (entry.getKey().isWildcard() && action.startsWith(entry.getKey().getAction())) {
                invokeIntent(message, response, entry.getValue());
                return;
            }

            if (entry.getKey().getAction().equals(action)) {
                invokeIntent(message, response, entry.getValue());
                return;
            }
        }
    } catch (AIServiceException e) {
        e.printStackTrace();
    }
}
 

开发者ID:avaire,
项目名称:avaire,
代码行数:35,
代码来源:IntelligenceManager.java

示例5: fetch

点赞 2

import ai.api.AIServiceException; //导入依赖的package包/类
public Pair<Boolean, String> fetch() {

        final AIRequest aiRequest = new AIRequest();
        aiRequest.setQuery(utterance);

        try {

            final AIResponse response = aiDataService.request(aiRequest);

            if (response != null) {

                final String gsonString = new GsonBuilder().disableHtmlEscaping().create().toJson(response);

                if (DEBUG) {
                    MyLog.i(CLS_NAME, "gsonString: " + response.toString());
                }

                return new Pair<>(true, gsonString);
            } else {
                if (DEBUG) {
                    MyLog.w(CLS_NAME, "response null");
                }
            }

        } catch (final AIServiceException e) {
            if (DEBUG) {
                MyLog.e(CLS_NAME, "AIResponse AIServiceException");
                e.printStackTrace();
            }
        }

        return new Pair<>(false, null);
    }
 

开发者ID:brandall76,
项目名称:Saiy-PS,
代码行数:34,
代码来源:RemoteAPIAI.java

示例6: legacyContextsTest

点赞 2

import ai.api.AIServiceException; //导入依赖的package包/类
@Test
public void legacyContextsTest() {
    final AIConfiguration config = new AIConfiguration(
            "3485a96fb27744db83e78b8c4bc9e7b7",
            AIConfiguration.SupportedLanguages.English);

    config.setProtocolVersion(null);

    final SimpleProtocolTestingService aiDataService = new SimpleProtocolTestingService(config);

    try {
        final AIRequest aiRequest = new AIRequest();
        aiRequest.setQuery("weather");
        prepareRequest(aiRequest, config);

        final String textRequest = gson.toJson(aiRequest);

        final String textResponse = aiDataService.doDefaultProtocolTextRequest(textRequest);

        final AIResponseDefault aiResponse = gson.fromJson(textResponse, AIResponseDefault.class);

        assertFalse(StringUtils.isEmpty(aiResponse.getResult().getResolvedQuery()));
        assertEquals("showWeather", aiResponse.getResult().getAction());

        final String[] contexts = aiResponse.getResult().getMetadata().getContexts();
        assertNotNull(contexts);
        boolean contextLoaded = false;
        for (int i = 0; i < contexts.length; i++) {
            if ("weather".equalsIgnoreCase(contexts[i])) {
                contextLoaded = true;
            }
        }
        assertTrue(contextLoaded);

    } catch (final AIServiceException | MalformedURLException e) {
        e.printStackTrace();
        assertTrue(e.getMessage(), false);
    }
}
 

开发者ID:dialogflow,
项目名称:dialogflow-java-client,
代码行数:40,
代码来源:DefaultProtocolTest.java

示例7: doGet

点赞 2

import ai.api.AIServiceException; //导入依赖的package包/类
/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
  try {
    AIResponse aiResponse = request(request.getParameter("query"), request.getSession());
    response.setContentType("text/plain");
    response.getWriter().append(aiResponse.getResult().getFulfillment().getSpeech());
  } catch (AIServiceException e) {
    e.printStackTrace();
  }
}
 

开发者ID:dialogflow,
项目名称:dialogflow-java-client,
代码行数:14,
代码来源:ServiceServletSample.java

示例8: doInBackground

点赞 2

import ai.api.AIServiceException; //导入依赖的package包/类
@Override
protected AIResponse doInBackground(final Void... params) {
    try {
        return aiDataService.voiceRequest(recorderStream, requestExtras);
    } catch (final AIServiceException e) {
        aiError = new AIError(e);
    }
    return null;
}
 

开发者ID:dialogflow,
项目名称:dialogflow-android-client,
代码行数:10,
代码来源:SpeaktoitRecognitionServiceImpl.java

示例9: textRequest

点赞 2

import ai.api.AIServiceException; //导入依赖的package包/类
public AIResponse textRequest(final AIRequest request) throws AIServiceException {
    if (aiService != null) {
        return aiService.textRequest(request);
    } else {
        throw new IllegalStateException("Call initialize method before usage");
    }
}
 

开发者ID:dialogflow,
项目名称:dialogflow-android-client,
代码行数:8,
代码来源:AIButton.java

示例10: AIError

点赞 2

import ai.api.AIServiceException; //导入依赖的package包/类
public AIError(final AIServiceException e) {
    aiResponse = e.getResponse();
    message = e.getMessage();
    exception = e;
}
 

开发者ID:dialogflow,
项目名称:dialogflow-java-client,
代码行数:6,
代码来源:AIError.java

示例11: doDefaultProtocolTextRequest

点赞 2

import ai.api.AIServiceException; //导入依赖的package包/类
public String doDefaultProtocolTextRequest(final String requestJson) throws MalformedURLException, AIServiceException {
    return doTextRequest(requestJson);
}
 

开发者ID:dialogflow,
项目名称:dialogflow-java-client,
代码行数:4,
代码来源:SimpleProtocolTestingService.java

示例12: doDefaultProtocolSoundRequest

点赞 2

import ai.api.AIServiceException; //导入依赖的package包/类
public String doDefaultProtocolSoundRequest(final InputStream voiceStream, final String queryData) throws MalformedURLException, AIServiceException {
    return doSoundRequest(voiceStream, queryData);
}
 

开发者ID:dialogflow,
项目名称:dialogflow-java-client,
代码行数:4,
代码来源:SimpleProtocolTestingService.java

示例13: textRequest

点赞 2

import ai.api.AIServiceException; //导入依赖的package包/类
public AIResponse textRequest(final AIRequest request) throws AIServiceException {
    return aiButton.textRequest(request);
}
 

开发者ID:dialogflow,
项目名称:dialogflow-android-client,
代码行数:4,
代码来源:AIDialog.java

示例14: textRequest

点赞 2

import ai.api.AIServiceException; //导入依赖的package包/类
public AIResponse textRequest(final AIRequest request) throws AIServiceException {
    return aiDataService.request(request);
}
 

开发者ID:dialogflow,
项目名称:dialogflow-android-client,
代码行数:4,
代码来源:AIService.java

示例15: request

点赞 1

import ai.api.AIServiceException; //导入依赖的package包/类
/**
 * Perform request to AI data service
 * @param aiRequest Request object. Cannot be <code>null</code>.
 * @param serviceContext Service context. If <code>null</code> then default context will be used.
 * @return Response object
 * @throws AIServiceException Thrown on server access error
 */
protected final AIResponse request(AIRequest aiRequest, AIServiceContext serviceContext)
    throws AIServiceException {
  return aiDataService.request(aiRequest, serviceContext);
}
 

开发者ID:dialogflow,
项目名称:dialogflow-java-client,
代码行数:12,
代码来源:AIServiceServlet.java

示例16: uploadUserEntity

点赞 1

import ai.api.AIServiceException; //导入依赖的package包/类
/**
 * Upload user entity for using while session
 * @param userEntity entity to upload
 * @return uploading result
 * @throws AIServiceException
 */
public AIResponse uploadUserEntity(final Entity userEntity) throws AIServiceException {
    return aiDataService.uploadUserEntity(userEntity);
}
 

开发者ID:dialogflow,
项目名称:dialogflow-android-client,
代码行数:10,
代码来源:AIService.java

示例17: uploadUserEntities

点赞 1

import ai.api.AIServiceException; //导入依赖的package包/类
/**
 * Upload user entities for using while session
 * @param userEntities collection of user entities
 * @return uploading result
 * @throws AIServiceException if request to the API.AI service failed
 */
public AIResponse uploadUserEntities(final Collection<Entity> userEntities) throws AIServiceException {
    return aiDataService.uploadUserEntities(userEntities);
}
 

开发者ID:dialogflow,
项目名称:dialogflow-android-client,
代码行数:10,
代码来源:AIService.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)