Skip to content

Commit

Permalink
last changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AitorAlgorta committed Aug 14, 2023
1 parent 0a9acfe commit f3e59e1
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 85 deletions.
171 changes: 86 additions & 85 deletions frontend/inbox/src/components/ConversationSuggestions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,100 +32,101 @@ const ConversationSuggestion = (props: ConversationSuggestionProps) => {
const [actionItemsLoader, setActionItemsLoader] = useState<boolean>(true);

useEffect(() => {
if (conversation && conversation.lastMessage) {
setTopicLoader(true);
toolkitAI
.askQuestion(
`Analyse these messages of this email thread and give me the top 3 topics being mentioned (no more than 50 characters per topic) in the email: ${JSON.stringify(
conversation.lastMessage
)}`
)
.then((value: any) => {
if (timeoutTopics) clearTimeout(timeoutTopics);
setTopicLoader(true);
setTopics(value.trim());
timeoutTopics = setTimeout(() => {
setTopicLoader(false);
}, 1000);
});
return () => clearTimeout(timeoutTopics);
}
toolkitAI.chatQuestion('Who was Albert Einstein?')
// if (conversation && conversation.lastMessage) {
// setTopicLoader(true);
// toolkitAI
// .askQuestion(
// `Analyse these messages of this email thread and give me the top 3 topics being mentioned (no more than 50 characters per topic) in the email: ${JSON.stringify(
// conversation.lastMessage
// )}`
// )
// .then((value: any) => {
// if (timeoutTopics) clearTimeout(timeoutTopics);
// setTopicLoader(true);
// setTopics(value.trim());
// timeoutTopics = setTimeout(() => {
// setTopicLoader(false);
// }, 1000);
// });
// return () => clearTimeout(timeoutTopics);
// }
}, [conversation.lastMessage]);

useEffect(() => {
if (conversation && conversation.lastMessage) {
setSummaryLoader(true);
toolkitAI
.askQuestion(
`Analyse these messages of this email give me a summary of the outcome of the email (no more than 150 characters): ${JSON.stringify(
conversation.lastMessage
)}`
)
.then((value: any) => {
if (timeoutSummary) clearTimeout(timeoutSummary);
setSummaryLoader(true);
setSummary(value.trim());
timeoutSummary = setTimeout(() => {
setSummaryLoader(false);
}, 1000);
});
return () => clearTimeout(timeoutSummary);
}
// if (conversation && conversation.lastMessage) {
// setSummaryLoader(true);
// toolkitAI
// .askQuestion(
// `Analyse these messages of this email give me a summary of the outcome of the email (no more than 150 characters): ${JSON.stringify(
// conversation.lastMessage
// )}`
// )
// .then((value: any) => {
// if (timeoutSummary) clearTimeout(timeoutSummary);
// setSummaryLoader(true);
// setSummary(value.trim());
// timeoutSummary = setTimeout(() => {
// setSummaryLoader(false);
// }, 1000);
// });
// return () => clearTimeout(timeoutSummary);
// }
}, [conversation.lastMessage]);

useEffect(() => {
if (conversation && conversation.lastMessage) {
setActionItemsLoader(true);
toolkitAI
.askQuestion(
`Analyse the messages of this email give me a 3 actions items to do with this email (no more than 30 characters per item): ${JSON.stringify(
conversation.lastMessage
)}`
)
.then((value: any) => {
if (actionItemsSummary) clearTimeout(actionItemsSummary);
setActionItemsLoader(true);
setActionItems(value.trim());
actionItemsSummary = setTimeout(() => {
setActionItemsLoader(false);
}, 1000);
});
return () => clearTimeout(actionItemsSummary);
}
// if (conversation && conversation.lastMessage) {
// setActionItemsLoader(true);
// toolkitAI
// .askQuestion(
// `Analyse the messages of this email give me a 3 actions items to do with this email (no more than 30 characters per item): ${JSON.stringify(
// conversation.lastMessage
// )}`
// )
// .then((value: any) => {
// if (actionItemsSummary) clearTimeout(actionItemsSummary);
// setActionItemsLoader(true);
// setActionItems(value.trim());
// actionItemsSummary = setTimeout(() => {
// setActionItemsLoader(false);
// }, 1000);
// });
// return () => clearTimeout(actionItemsSummary);
// }
}, [conversation.lastMessage]);

useEffect(() => {
if (conversation && conversation.lastMessage) {
toolkitAI
.askQuestion(
`Generate three suggested email replies that make sense to this messages of an email thread (separate them by /). Keep in mind that these messages are an email thread and might be spam, marketing email or job opportunities. Also, don't add any title or numeration before each suggestion: ${JSON.stringify(
conversation.lastMessage
)}`
)
.then((value: string) => {
const suggestions = value.split('/');
suggestReplies({
message_id: conversation.lastMessage.id,
suggestions: {
'suggestion-1': {
content: {
text: suggestions[0].trim(),
},
},
'suggestion-2': {
content: {
text: suggestions[1].trim(),
},
},
'suggestion-3': {
content: {
text: suggestions[2].trim(),
},
},
},
});
});
}
// if (conversation && conversation.lastMessage) {
// toolkitAI
// .askQuestion(
// `Generate three suggested email replies that make sense to this messages of an email thread (separate them by /). Keep in mind that these messages are an email thread and might be spam, marketing email or job opportunities. Also, don't add any title or numeration before each suggestion: ${JSON.stringify(
// conversation.lastMessage
// )}`
// )
// .then((value: string) => {
// const suggestions = value.split('/');
// suggestReplies({
// message_id: conversation.lastMessage.id,
// suggestions: {
// 'suggestion-1': {
// content: {
// text: suggestions[0].trim(),
// },
// },
// 'suggestion-2': {
// content: {
// text: suggestions[1].trim(),
// },
// },
// 'suggestion-3': {
// content: {
// text: suggestions[2].trim(),
// },
// },
// },
// });
// });
// }
}, [conversation.lastMessage]);

return (
Expand Down
1 change: 1 addition & 0 deletions frontend/inbox/src/services/ai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class ToolkitAI {
});

private static chat = new ChatOpenAI({
openAIApiKey: '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',
maxTokens: 100,
streaming: true,
});
Expand Down

0 comments on commit f3e59e1

Please sign in to comment.