Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Task Suggestion Prompt #97

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>com.salessparrow</groupId>
<artifactId>salessparrow-api</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>
<name>api</name>
<description>Salessparrow apis</description>

Expand Down
6 changes: 6 additions & 0 deletions repo-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# SalesSparrow APIs

## 0.2.3

### Enhancements:

- Improve Task Suggestion to show correct Due Date and empty description if no task found [#94](https://github.com/TrueSparrowSystems/AI-SalesSparrow-API/issues/94)

## 0.2.2

### Enhancements:
Expand Down
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
Loading