private ConversationMemorySnapshot runTestCase(String botId, TestCase testCase) throws Exception { IRestBotEngine botEngine = restInterfaceFactory.get(IRestBotEngine.class, apiServerURI); Response ConversationResponse = botEngine.startConversation(Deployment.Environment.test, botId, "testCaseRunner"); URI conversationURI = ConversationResponse.getLocation(); String conversationURIPath = conversationURI.getPath(); String conversationId = conversationURIPath.substring(conversationURIPath.lastIndexOf("/") + 1); ConversationMemorySnapshot expected = testCase.getExpected(); List<ConversationMemorySnapshot.ConversationStepSnapshot> expectedConversationSteps = expected.getConversationSteps(); //we skip the first one, since the initial run has already been done at this point (at startConversation) for (int i = 1; i < expectedConversationSteps.size(); i++) { ConversationMemorySnapshot.ConversationStepSnapshot expectedConversationStep = expectedConversationSteps.get(i); String input = getFirstInput(expectedConversationStep); if (RuntimeUtilities.isNullOrEmpty(input)) { input = " "; } botEngine.say(Deployment.Environment.test, botId, conversationId, true, false, Collections.emptyList(), input, new MockAsyncResponse()); while (botEngine.getConversationState(Deployment.Environment.test, conversationId) == ConversationState.IN_PROGRESS) { Thread.sleep(1000); } } return conversationMemoryStore.loadConversationMemorySnapshot(conversationId); }
private void mergeConversationMemory(IConversationMemory currentConversationMemory, ConversationMemorySnapshot callbackMemorySnapshot) { if (callbackMemorySnapshot != null && !callbackMemorySnapshot.getConversationSteps().isEmpty()) { var currentStep = currentConversationMemory.getCurrentStep(); var callbackConversationMemory = convertConversationMemorySnapshot(callbackMemorySnapshot); var currentCallbackStep = callbackConversationMemory.getCurrentStep(); Set<String> callbackKeys = currentCallbackStep.getAllKeys(); for (String callbackKey : callbackKeys) { currentStep.storeData(currentCallbackStep.getData(callbackKey)); } } }
public static IConversationMemory convertConversationMemorySnapshot(ConversationMemorySnapshot snapshot) { ConversationMemory conversationMemory = new ConversationMemory(snapshot.getConversationId(), snapshot.getBotId(), snapshot.getBotVersion(), snapshot.getUserId()); conversationMemory.setConversationState(snapshot.getConversationState()); conversationMemory.getConversationProperties().putAll(snapshot.getConversationProperties()); List<IConversationMemory.IConversationStep> redoSteps = iterateRedoCache(snapshot.getRedoCache()); for (IConversationMemory.IConversationStep redoStep : redoSteps) { conversationMemory.getRedoCache().add(redoStep); } List<ConversationMemorySnapshot.ConversationStepSnapshot> conversationSteps = snapshot.getConversationSteps(); for (int i = 0; i < conversationSteps.size(); i++) { ConversationOutput conversationOutput = snapshot.getConversationOutputs().get(i); ConversationMemorySnapshot.ConversationStepSnapshot conversationStepSnapshot = conversationSteps.get(i); if (i > 0) { conversationMemory.startNextStep(conversationOutput); } for (ConversationMemorySnapshot.PackageRunSnapshot packageRunSnapshot : conversationStepSnapshot.getPackages()) { for (ConversationMemorySnapshot.ResultSnapshot resultSnapshot : packageRunSnapshot.getLifecycleTasks()) { Data data = new Data(resultSnapshot.getKey(), resultSnapshot.getResult(), resultSnapshot.getPossibleResults(), resultSnapshot.getTimestamp(), resultSnapshot.isPublic()); conversationMemory.getCurrentStep().storeData(data); } } } return conversationMemory; }
public static ConversationMemorySnapshot convertConversationMemory(IConversationMemory conversationMemory) { ConversationMemorySnapshot snapshot = new ConversationMemorySnapshot(); if (conversationMemory.getUserId() != null) { snapshot.setUserId(conversationMemory.getUserId()); } if (conversationMemory.getConversationId() != null) { snapshot.setConversationId(conversationMemory.getConversationId()); } snapshot.setBotId(conversationMemory.getBotId()); snapshot.setBotVersion(conversationMemory.getBotVersion()); snapshot.setConversationState(conversationMemory.getConversationState()); for (IConversationMemory.IConversationStep redoStep : conversationMemory.getRedoCache()) { ConversationMemorySnapshot.ConversationStepSnapshot redoStepSnapshot = iterateConversationStep(redoStep); snapshot.getRedoCache().push(redoStepSnapshot); } for (int i = conversationMemory.getAllSteps().size() - 1; i >= 0; i--) { IConversationMemory.IConversationStep conversationStep = conversationMemory.getAllSteps().get(i); snapshot.getConversationSteps().add(iterateConversationStep(conversationStep)); } snapshot.getConversationOutputs().addAll(conversationMemory.getConversationOutputs()); snapshot.getConversationProperties().putAll(conversationMemory.getConversationProperties()); return snapshot; }
conversationDescriptor.setConversationStepSize(memorySnapshot.getConversationSteps().size()); URI createdBy = conversationDescriptor.getCreatedBy(); if (createdBy != null) {
public static SimpleConversationMemorySnapshot convertSimpleConversationMemory(ConversationMemorySnapshot conversationMemorySnapshot, boolean returnDetailed) { SimpleConversationMemorySnapshot simpleSnapshot = new SimpleConversationMemorySnapshot(); if (conversationMemorySnapshot.getUserId() != null) { simpleSnapshot.setUserId(conversationMemorySnapshot.getUserId()); } simpleSnapshot.setBotId(conversationMemorySnapshot.getBotId()); simpleSnapshot.setBotVersion(conversationMemorySnapshot.getBotVersion()); simpleSnapshot.setConversationState(conversationMemorySnapshot.getConversationState()); simpleSnapshot.setEnvironment(conversationMemorySnapshot.getEnvironment()); simpleSnapshot.setRedoCacheSize(conversationMemorySnapshot.getRedoCache().size()); simpleSnapshot.getConversationOutputs().addAll(conversationMemorySnapshot.getConversationOutputs()); simpleSnapshot.getConversationProperties().putAll(conversationMemorySnapshot.getConversationProperties()); for (ConversationMemorySnapshot.ConversationStepSnapshot conversationStepSnapshot : conversationMemorySnapshot.getConversationSteps()) { SimpleConversationMemorySnapshot.SimpleConversationStep simpleConversationStep = new SimpleConversationMemorySnapshot.SimpleConversationStep(); simpleSnapshot.getConversationSteps().add(simpleConversationStep); for (ConversationMemorySnapshot.PackageRunSnapshot packageRunSnapshot : conversationStepSnapshot.getPackages()) { for (ConversationMemorySnapshot.ResultSnapshot resultSnapshot : packageRunSnapshot.getLifecycleTasks()) { if (returnDetailed || resultSnapshot.isPublic()) { Object result = resultSnapshot.getResult(); simpleConversationStep.getConversationStep().add( new SimpleConversationMemorySnapshot.ConversationStepData(resultSnapshot.getKey(), result)); } else { continue; } simpleConversationStep.setTimestamp(resultSnapshot.getTimestamp()); } } } return simpleSnapshot; }