Skip to content

Commit

Permalink
Prompting Updates, slight reorg on SMS functions
Browse files Browse the repository at this point in the history
  • Loading branch information
docwho2 committed Aug 5, 2024
1 parent 31d58a8 commit 1709331
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 40 deletions.
8 changes: 5 additions & 3 deletions ChatGPT/src/main/java/cloud/cleo/squareup/ChatGPTLambda.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ public abstract class ChatGPTLambda {
public final static String HANGUP_FUNCTION_NAME = "hangup_call";
public final static String FACEBOOK_HANDOVER_FUNCTION_NAME = "facebook_inbox";
public final static String SWITCH_LANGUAGE_FUNCTION_NAME = "switch_language";
public final static String DRIVING_DIRECTIONS_FUNCTION_NAME = "driving_directions";
public final static String PRIVATE_SHOPPING_FUNCTION_NAME = "private_shopping_url";
public final static String DRIVING_DIRECTIONS_TEXT_FUNCTION_NAME = "driving_directions_text";
public final static String DRIVING_DIRECTIONS_VOICE_FUNCTION_NAME = "driving_directions_voice";
public final static String PRIVATE_SHOPPING_TEXT_FUNCTION_NAME = "private_shopping_url_text";
public final static String PRIVATE_SHOPPING_VOICE_FUNCTION_NAME = "private_shopping_url_voice";


public final static String WEBSITE_URL = "CopperFoxGifts.com";
Expand Down Expand Up @@ -170,7 +172,7 @@ protected LexV2Response processGPT(LexV2EventWrapper lexRequest) {
FunctionExecutor functionExecutor = AbstractFunction.getFunctionExecuter(lexRequest);
functionExecutor.setObjectMapper(mapper);

functionExecutor.getFunctions().forEach(f -> log.debug(f));
//functionExecutor.getFunctions().forEach(log::debug);

while (true) {
final var chatMessages = session.getChatMessages();
Expand Down
32 changes: 17 additions & 15 deletions ChatGPT/src/main/java/cloud/cleo/squareup/ChatGPTSessionState.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package cloud.cleo.squareup;

import static cloud.cleo.squareup.ChatGPTLambda.DRIVING_DIRECTIONS_FUNCTION_NAME;
import static cloud.cleo.squareup.ChatGPTLambda.HANGUP_FUNCTION_NAME;
import static cloud.cleo.squareup.ChatGPTLambda.SWITCH_LANGUAGE_FUNCTION_NAME;
import static cloud.cleo.squareup.ChatGPTLambda.TRANSFER_FUNCTION_NAME;
import static cloud.cleo.squareup.ChatGPTLambda.WEBSITE_URL;
import static cloud.cleo.squareup.ChatGPTLambda.*;
import cloud.cleo.squareup.enums.Language;
import cloud.cleo.squareup.functions.AbstractFunction;
import com.theokanning.openai.completion.chat.ChatMessage;
Expand All @@ -18,7 +14,6 @@
import java.util.stream.Collectors;
import lombok.Data;
import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.*;
import static cloud.cleo.squareup.ChatGPTLambda.PRIVATE_SHOPPING_FUNCTION_NAME;

/**
* Object to store and accumulate ChatGPT Session Data (messages) in DynamoDB.
Expand Down Expand Up @@ -80,14 +75,7 @@ public ChatGPTSessionState(LexV2EventWrapper lexRequest) {
the store outside normal hours, and this can be scheduled on our website from one of the top level menu "Private Shoppimg".
We have a one hour lead time on appointments so if we're closed, they could be shopping privately within one hour!
Do mention how great it would be to have the store all to themselves and how we try to accomodate all requests.
""");

sb.append("Please call the ").append(PRIVATE_SHOPPING_FUNCTION_NAME)
.append("""
function to get the direct booking URL when the caller is interested in the private shopping experience. This is
really one of the more innovative services we provide and we want to ensure its as easy as possible for customers
to book their appointments.
""");
""");

// Main Website adn FB
sb.append("The Web Site for Copper Fix Gifts is ").append(WEBSITE_URL).append(" and we frequently post our events and informaiton on sales ")
Expand Down Expand Up @@ -148,6 +136,13 @@ public ChatGPTSessionState(LexV2EventWrapper lexRequest) {
sb.append("Please keep answers very short and concise. ");
}
}
sb.append("Please call the ").append(PRIVATE_SHOPPING_TEXT_FUNCTION_NAME)
.append("""
function to get the direct booking URL when the person is interested in the private shopping experience. This is
really one of the more innovative services we provide and we want to ensure its as easy as possible for customers
to book their appointments.
""");

// Since we are fallback intent, from a Text input perspective, we can support any language ChatGPT understands
sb.append("Detect the language of the prompt and respond in that language. ");
}
Expand All @@ -162,7 +157,7 @@ public ChatGPTSessionState(LexV2EventWrapper lexRequest) {
sb.append("When the caller indicates they are done with the conversation, execute the ").append(HANGUP_FUNCTION_NAME).append(" function. ");

// Offer up Driving directions for callers
sb.append("When asking about location, you can send the caller a directions link if they are interested, execute the ").append(DRIVING_DIRECTIONS_FUNCTION_NAME).append(" function. ");
sb.append("When asking about location, you can send the caller a directions link if they are interested, execute the ").append(DRIVING_DIRECTIONS_VOICE_FUNCTION_NAME).append(" function. ");

// Always answer with a question to illicit the next repsonse, this makes the voice interaction more natural
sb.append("When responding always end the response with a question to illicit the next input since we are interacting via telephone. ");
Expand All @@ -184,6 +179,13 @@ public ChatGPTSessionState(LexV2EventWrapper lexRequest) {

// Toll fraud protect
sb.append("Do not allow calling ").append(TRANSFER_FUNCTION_NAME).append(" function with arbritary phone numbers provided by the user. ");

sb.append("Please call the ").append(PRIVATE_SHOPPING_VOICE_FUNCTION_NAME)
.append("""
function to get the direct booking URL when the person is interested in the private shopping experience. This is
really one of the more innovative services we provide and we want to ensure its as easy as possible for customers
to book their appointments. The function will tell if you the message was sent to their device or unable to send.
""");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,13 @@ public static FunctionExecutor getFunctionExecuter(LexV2EventWrapper lexRequest)

if (isText) {
if (func.isText()) {
log.debug("TEXT MODE Adding: " + func);
list.add(func);
} else {
log.debug("TEXT MODE Excluding: " + func);
}
}
} else {
// If not Text, then this is voice of course
if (func.isVoice()) {
log.debug("VOICE MODE Adding: " + func);
list.add(func);
} else {
log.debug("VOICE MODE Excluding: " + func);
}
}
}
} catch (CloneNotSupportedException ex) {
log.error("Error cloning Functions", ex);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cloud.cleo.squareup.functions;

import static cloud.cleo.squareup.ChatGPTLambda.DRIVING_DIRECTIONS_FUNCTION_NAME;

/**
* Base class for Driving Directions.
Expand All @@ -16,13 +15,6 @@ public abstract class DrivingDirections<Request> extends AbstractFunction {
*/
protected final static String DRIVING_DIRECTIONS_URL = "google.com/maps/dir/?api=1&destination=160+Main+St+Wahkon+MN+56386&destination_place_id=ChIJWxVcpjffs1IRcSX7D8pJSUY";


@Override
public final String getName() {
return DRIVING_DIRECTIONS_FUNCTION_NAME;
}



@Override
public final Class getRequestClass() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cloud.cleo.squareup.functions;

import static cloud.cleo.squareup.ChatGPTLambda.DRIVING_DIRECTIONS_TEXT_FUNCTION_NAME;
import java.util.function.Function;

/**
Expand All @@ -10,6 +11,13 @@
public class DrivingDirectionsText extends DrivingDirections {


@Override
public final String getName() {
return DRIVING_DIRECTIONS_TEXT_FUNCTION_NAME;
}



@Override
protected String getDescription() {
return "Returns a URL for Driving directions to the Store";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cloud.cleo.squareup.functions;

import static cloud.cleo.squareup.ChatGPTLambda.DRIVING_DIRECTIONS_VOICE_FUNCTION_NAME;
import java.util.function.Function;

/**
Expand All @@ -9,6 +10,12 @@
*/
public class DrivingDirectionsVoice extends DrivingDirections implements SendSMS {

@Override
public final String getName() {
return DRIVING_DIRECTIONS_VOICE_FUNCTION_NAME;
}



@Override
protected String getDescription() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package cloud.cleo.squareup.functions;

import static cloud.cleo.squareup.ChatGPTLambda.WEBSITE_URL;
import static cloud.cleo.squareup.ChatGPTLambda.PRIVATE_SHOPPING_FUNCTION_NAME;


/**
*
Expand All @@ -15,11 +15,6 @@
public abstract class PrivateShoppingLink<Request> extends AbstractFunction {

protected final static String PRIVATE_SHOPPING_URL = WEBSITE_URL + "/book";

@Override
public final String getName() {
return PRIVATE_SHOPPING_FUNCTION_NAME;
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package cloud.cleo.squareup.functions;

import static cloud.cleo.squareup.ChatGPTLambda.PRIVATE_SHOPPING_TEXT_FUNCTION_NAME;
import java.util.function.Function;

/**
Expand All @@ -12,6 +13,11 @@
*/
public class PrivateShoppingLinkText extends PrivateShoppingLink {

@Override
public final String getName() {
return PRIVATE_SHOPPING_TEXT_FUNCTION_NAME;
}

@Override
protected String getDescription() {
return "Returns a URL for direct booking of Private Shopping";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package cloud.cleo.squareup.functions;

import static cloud.cleo.squareup.ChatGPTLambda.PRIVATE_SHOPPING_VOICE_FUNCTION_NAME;
import java.util.function.Function;

/**
Expand All @@ -12,6 +13,11 @@
*/
public class PrivateShoppingLinkVoice extends PrivateShoppingLink implements SendSMS {

@Override
public final String getName() {
return PRIVATE_SHOPPING_VOICE_FUNCTION_NAME;
}

@Override
protected String getDescription() {
return "Sends the caller the direct URL to book private shopping";
Expand Down

0 comments on commit 1709331

Please sign in to comment.