Skip to content

Commit

Permalink
Updated prompt for task suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Raj-Shah1 committed Sep 20, 2023
1 parent 2f6fb1b commit 6aea154
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
54 changes: 29 additions & 25 deletions src/main/java/com/salessparrow/api/lib/GetCrmActionSuggestions.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,36 +63,40 @@ private CrmActionSuggestionsFormatterDto parseResponse(String responseBody) {

try {
Util util = new Util();
JsonNode rootNode = util.getJsonNode(responseBody);
JsonNode argumentsNode = rootNode.get("choices")
.get(0)
.get("message")
.get("function_call")
.get("arguments");

ObjectMapper objectMapper = new ObjectMapper();
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
String argumentsJson = objectMapper.convertValue(argumentsNode, String.class);
JsonNode rootNode = util.getJsonNode(responseBody);

Map<String, List<AddTaskSuggestionEntityDto>> arguments = objectMapper.readValue(argumentsJson,
new TypeReference<Map<String, List<AddTaskSuggestionEntityDto>>>() {
});
List<AddTaskSuggestionEntityDto> addTaskList = arguments.get("add_task");
JsonNode functionNode = rootNode.get("choices").get(0).get("message").get("function_call");

List<AddTaskSuggestionEntityDto> formattedTaskSuggestionEntityDtos = new ArrayList<>();
if (addTaskList != null) {
for (AddTaskSuggestionEntityDto addTask : addTaskList) {
AddTaskSuggestionEntityDto addTaskSuggestionEntityDto = new AddTaskSuggestionEntityDto();
addTaskSuggestionEntityDto.setDescription(addTask.getDescription());

// Format the response check if duedate format is YYYY-MM-DD else
// remove duedate
String dueDate = addTask.getDueDate();
if (dateFormatValidator.isValid(dueDate, null)) {
addTaskSuggestionEntityDto.setDueDate(dueDate);
}

formattedTaskSuggestionEntityDtos.add(addTaskSuggestionEntityDto);
if (functionNode != null) {

JsonNode argumentsNode = functionNode.get("arguments");

ObjectMapper objectMapper = new ObjectMapper();
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
String argumentsJson = objectMapper.convertValue(argumentsNode, String.class);

Map<String, List<AddTaskSuggestionEntityDto>> arguments = objectMapper.readValue(argumentsJson,
new TypeReference<Map<String, List<AddTaskSuggestionEntityDto>>>() {
});
List<AddTaskSuggestionEntityDto> addTaskList = arguments.get("add_task");

if (addTaskList != null) {
for (AddTaskSuggestionEntityDto addTask : addTaskList) {
AddTaskSuggestionEntityDto addTaskSuggestionEntityDto = new AddTaskSuggestionEntityDto();
addTaskSuggestionEntityDto.setDescription(addTask.getDescription());

// Format the response check if duedate format is YYYY-MM-DD else
// remove duedate
String dueDate = addTask.getDueDate();
if (dateFormatValidator.isValid(dueDate, null)) {
addTaskSuggestionEntityDto.setDueDate(dueDate);
}

formattedTaskSuggestionEntityDtos.add(addTaskSuggestionEntityDto);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,28 @@ public class OpenAiPayloadBuilder {
*/
public String payloadForCrmActionsSuggestions(String text) {

String todayDate = getTodaysDate();

return "{\n" + " \"model\": \"gpt-3.5-turbo-0613\",\n" + " \"messages\": [\n" + " {\n"
+ " \"role\": \"user\",\n"
+ " \"content\": \"You are an AI assistant which gives suggestion on creating task in crm using the input message.Only use the functions you have been provided with. \\nInput message: \\n"
+ " \"role\": \"system\",\n"
+ " \"content\": \"You are an AI assistant that provides suggestions for creating tasks in CRM based solely on the content of the input message. The content of task if any found should only be from input message. If no task suggestions are found in the input message, return empty data. If task suggestions are found, they should include description and due date. Due Date format should be YYYY-MM-DD. Today's date is "
+ todayDate
+ ". Use the functions provided to determine task suggestions. If no tasks are possible for the given input message, return an empty response. For example, If Input Message: Had a call with product team. They need a pitch desk by tomorrow. Then it should return description: Create pitch deck. For 2nd Example, If Input Message: 3 tasks. Then it should return empty response as no tasks can be suggested from input message\"\n"
+ " },\n" + " {\n" + " \"role\": \"user\",\n" + " \"content\": \" Input message: \\n"
+ text + "\\n\"\n" + " }\n" + " ],\n" + " \"functions\": [\n" + " {\n"
+ " \"name\": \"suggest_actions\",\n"
+ " \"description\": \"This is function for suggesting actions in crm(example salesforce, freshsales) based on input message.\",\n"
+ " \"parameters\": {\n" + " \"type\": \"object\",\n" + " \"properties\": {\n"
+ " \"add_task\": {\n" + " \"name\": \"add_task\",\n"
+ " \"description\": \"Tasks using input message.\",\n"
+ " \"description\": \"Tasks using input message. The task should be created only from the input message and if no task can be generated from input message then empty data should be returned.\",\n"
+ " \"type\": \"array\",\n" + " \"items\": {\n"
+ " \"type\": \"object\",\n" + " \"properties\": {\n"
+ " \"description\": {\n" + " \"type\": \"string\",\n"
+ " \"description\": \"Description for task to add. This is mandatory\"\n"
+ " },\n" + " \"due_date\": {\n"
+ " \"type\": \"string\",\n"
+ " \"description\": \"Description for task to add.\"\n" + " },\n"
+ " \"due_date\": {\n" + " \"type\": \"string\",\n"
+ " \"description\": \"Due date for task in YYYY-MM-DD format. Today's date is "
+ getTodaysDate() + ". This is mandatory\"\n" + " }\n" + " },\n"
+ " \"required\": [\"description\", \"due_date\"]\n" + " }\n" + " }\n"
+ " }\n" + " }\n" + " }\n" + " ]\n" + "}";
+ todayDate + ".\"\n" + " }\n" + " }\n" + " }\n"
+ " }\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}";
}

/**
Expand Down

0 comments on commit 6aea154

Please sign in to comment.