Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
chtrembl committed Jan 8, 2024
1 parent d01f2e0 commit 15da801
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableAsync;

import com.microsoft.bot.builder.Bot;
import com.microsoft.bot.builder.UserState;
Expand All @@ -16,6 +17,8 @@
import com.microsoft.bot.integration.spring.BotController;
import com.microsoft.bot.integration.spring.BotDependencyConfiguration;

@EnableAsync

//
// This is the starting point of the Sprint Boot Bot application.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {

switch (dpResponse.getClassification()) {
case UPDATE_SHOPPING_CART:
dpResponse.setClassification(Classification.UPDATE_SHOPPING_CART);
if (azurePetStoreSessionInfo != null) {
dpResponse = this.azureOpenAI.search(text, Classification.SEARCH_FOR_PRODUCTS);
if (dpResponse.getProducts() != null) {
Expand All @@ -127,15 +126,13 @@ protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
}
break;
case VIEW_SHOPPING_CART:
dpResponse.setClassification(Classification.VIEW_SHOPPING_CART);
if (azurePetStoreSessionInfo != null) {
dpResponse = this.azurePetStore.viewCart(azurePetStoreSessionInfo);
} else {
dpResponse.setDpResponseText("view shopping cart request without session... text: " + text);
}
break;
case PLACE_ORDER:
dpResponse.setClassification(Classification.PLACE_ORDER);
if (azurePetStoreSessionInfo != null) {
dpResponse = this.azurePetStore.completeCart(azurePetStoreSessionInfo);
} else {
Expand Down Expand Up @@ -190,7 +187,7 @@ protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
return PetStoreAssistantUtilities.getImageCard(turnContext, dpResponse);
}

LOGGER.info("classificateion on text: " + text + " is: " + dpResponse.getClassification());
LOGGER.info("classification on text: " + text + " is: " + dpResponse.getClassification());

return turnContext.sendActivity(
MessageFactory.text(dpResponse.getDpResponseText())).thenApply(sendResult -> null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public DPResponse updateCart(AzurePetStoreSessionInfo azurePetStoreSessionInfo,
+ azurePetStoreSessionInfo.getCsrfToken());
}

dpResponse.setClassification(Classification.UPDATE_SHOPPING_CART);

return dpResponse;
}

Expand Down Expand Up @@ -99,6 +101,8 @@ public DPResponse viewCart(AzurePetStoreSessionInfo azurePetStoreSessionInfo) {
}
}

dpResponse.setClassification(Classification.VIEW_SHOPPING_CART);

return dpResponse;
}

Expand Down Expand Up @@ -139,6 +143,8 @@ public DPResponse completeCart(AzurePetStoreSessionInfo azurePetStoreSessionInfo
response.body().close();
}
}

dpResponse.setClassification(Classification.PLACE_ORDER);
return dpResponse;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.chtrembl.petstoreassistant.service;

import java.util.HashMap;
import java.util.concurrent.Future;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import com.azure.cosmos.CosmosClient;
Expand Down Expand Up @@ -63,7 +66,8 @@ public HashMap<String, Product> getProducts() {
return this.products;
}

public void storePrompt(AzurePetStoreSessionInfo azurePetStoreSessionInfo) {
@Async
public Future<String> storePrompt(AzurePetStoreSessionInfo azurePetStoreSessionInfo) {
CosmosContainer container = client.getDatabase(DATABASE_ID).getContainer(this.PROMPTS_CONTAINER_ID);

try
Expand All @@ -76,5 +80,7 @@ public void storePrompt(AzurePetStoreSessionInfo azurePetStoreSessionInfo) {
{
LOGGER.error("Error upserting prompt in CosmosDB " + e.getMessage());
}

return new AsyncResult<>("prompt stored");
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.chtrembl.petstoreassistant.service;

import java.util.HashMap;
import java.util.concurrent.Future;

import com.chtrembl.petstoreassistant.model.AzurePetStoreSessionInfo;
import com.chtrembl.petstoreassistant.model.Product;

public interface ICosmosDB {
public HashMap<String, Product> getProducts();
public void storePrompt(AzurePetStoreSessionInfo azurePetStoreSessionInfo);
public Future<String> storePrompt(AzurePetStoreSessionInfo azurePetStoreSessionInfo);
}

0 comments on commit 15da801

Please sign in to comment.