Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
chtrembl committed Sep 27, 2024
1 parent 6020db7 commit a5cea9c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 37 deletions.
2 changes: 2 additions & 0 deletions petstore/petstoreassistant/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ build/

### VS Code ###
.vscode/

.fake
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.chtrembl.petstoreassistant;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
Expand Down Expand Up @@ -60,6 +60,9 @@ public class PetStoreAssistantBot extends ActivityHandler {
@Autowired
private ICosmosDB cosmosDB;

public String at1 = "";
public String at2 = "";

private String WELCOME_MESSAGE = "Hello and welcome to the Azure Pet Store, you can ask me questions about our products, your shopping cart and your order, you can also ask me for information about pet animals. How can I help you?";
private String RATE_LIMIT_EXCEEDED_MESSAGE = "I am sorry, you have exceeded your Azure Open AI rate limit, please try again shortly.";
private String SESSION_MISSING_ERROR_MESSAGE = "I am sorry, there is an error with audio translation, please try interacting via text or restarting your browser.";
Expand Down Expand Up @@ -112,6 +115,38 @@ public CompletableFuture<Void> onTurn(TurnContext turnContext) {

@Override
protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {

//customer demo/temp hack
if(turnContext.getActivity().getText().startsWith("at1:"))
{
String patternString = "at1:(.*?)(https://|$)";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(turnContext.getActivity().getText());

if (matcher.find()) {
this.at1 = matcher.group(1).trim();
}

return turnContext.sendActivity(
MessageFactory.text("at1 set thank you..."))
.thenApply(sendResult -> null);
}

if(turnContext.getActivity().getText().startsWith("at2:"))
{
String patternString = "at2:(.*?)(https://|$)";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(turnContext.getActivity().getText());

if (matcher.find()) {
this.at2 = matcher.group(1).trim();
}

return turnContext.sendActivity(
MessageFactory.text("at2 set thank you..."))
.thenApply(sendResult -> null);
}

String text = turnContext.getActivity().getText().toLowerCase().trim();

LOGGER.info("onMessageActivity incoming text: " + text);
Expand All @@ -127,21 +162,6 @@ protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
text = azurePetStoreSessionInfo.getNewText();
}

if(text.startsWith("at1:"))
{
azurePetStoreSessionInfo.setAt1(text.substring(4));
return turnContext.sendActivity(
MessageFactory.text("at1 set thank you..."))
.thenApply(sendResult -> null);
}
if(text.startsWith("at2:"))
{
azurePetStoreSessionInfo.setAt2(text.substring(4));
return turnContext.sendActivity(
MessageFactory.text("at2 set thank you..."))
.thenApply(sendResult -> null);
}

// the client browser initialized
if (text.equals("...")) {
LOGGER.info("onMessageActivity new session established, " + azurePetStoreSessionInfo != null ? "session id: " + azurePetStoreSessionInfo.getId() + " id: " + azurePetStoreSessionInfo.getId() : "session id: null");
Expand Down Expand Up @@ -178,7 +198,7 @@ protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
switch (dpResponse.getClassification()) {
case VIEW_AZURE_RESOURCES_DEMO:
if (azurePetStoreSessionInfo != null) {
dpResponse = this.azureDemo.getAzureResources(azurePetStoreSessionInfo);
dpResponse = this.azureDemo.getAzureResources(this.at1, azurePetStoreSessionInfo);
}
break;
case EXECUTE_ADO_PIPELINES_DEMO:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public class AzurePetStoreSessionInfo implements Serializable{
private String id = null;

private List<Prompt> prompts = null;

private String at1 = null;
private String at2 = null;

public AzurePetStoreSessionInfo(String sessionID, String csrfToken, String arrAffinity, String newText) {
super();
Expand Down Expand Up @@ -65,17 +62,4 @@ public void addPrompt(Prompt prompt) {
}
this.prompts.add(prompt);
}

public void setAt1(String at1) {
this.at1 = at1;
}
public String getAt1() {
return this.at1;
}
public void setAt2(String at2) {
this.at2 = at2;
}
public String getAt2() {
return this.at2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void initialize() throws Exception {
}

@Override
public DPResponse getAzureResources(AzurePetStoreSessionInfo azurePetStoreSessionInfo) {
public DPResponse getAzureResources(String at1, AzurePetStoreSessionInfo azurePetStoreSessionInfo) {
LOGGER.info("getAzureResources invoked, text: {}", azurePetStoreSessionInfo.getNewText());

DPResponse dpResponse = new DPResponse();
Expand All @@ -58,7 +58,7 @@ public DPResponse getAzureResources(AzurePetStoreSessionInfo azurePetStoreSessio

String azureResponse = this.azureClient.post()
.header("Content-Type", "application/json")
.header("Authorization", "Bearer " + azurePetStoreSessionInfo.getAt1())
.header("Authorization", "Bearer " + at1)
.bodyValue((String.format(this.azureResourcesDemoBodyBodyString, subscriptionId, days)))
.retrieve()
.bodyToMono(String.class)
Expand Down Expand Up @@ -93,6 +93,7 @@ public DPResponse getAzureResources(AzurePetStoreSessionInfo azurePetStoreSessio
{
dpResponse.setRateLimitExceeded(true);
}

dpResponse.setDpResponseText("I'm sorry, I wasn't able to get the Azure resources, check at.");
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
import com.chtrembl.petstoreassistant.model.DPResponse;

public interface IAzureDemo {
public DPResponse getAzureResources(AzurePetStoreSessionInfo azurePetStoreSessionInfo);
public DPResponse getAzureResources(String at1, AzurePetStoreSessionInfo azurePetStoreSessionInfo);
public DPResponse executeDevopsPipeline(AzurePetStoreSessionInfo azurePetStoreSessionInfo);
}

0 comments on commit a5cea9c

Please sign in to comment.