From 1d9584f71f222d998f463c1a18a5f7e010d64c74 Mon Sep 17 00:00:00 2001 From: Trinh Ngoc Tu Date: Mon, 9 Dec 2024 23:07:23 +0100 Subject: [PATCH] Update prompt & add beginning of quick response --- src/summarizepane/components/App.jsx | 2 + .../components/QuickResponse.jsx | 135 ++++++++++++++++++ .../components/TextInsertion.jsx | 23 +-- src/taskpane/components/TextInsertion.jsx | 3 +- 4 files changed, 151 insertions(+), 12 deletions(-) create mode 100644 src/summarizepane/components/QuickResponse.jsx diff --git a/src/summarizepane/components/App.jsx b/src/summarizepane/components/App.jsx index eb40f2ee..c593163e 100644 --- a/src/summarizepane/components/App.jsx +++ b/src/summarizepane/components/App.jsx @@ -5,6 +5,7 @@ import HeroList from "./HeroList"; import TextInsertion from "./TextInsertion"; import { makeStyles } from "@fluentui/react-components"; import { Ribbon24Regular, LockOpen24Regular, DesignIdeas24Regular } from "@fluentui/react-icons"; +import QuickResponse from "./QuickResponse"; const useStyles = makeStyles({ root: { @@ -18,6 +19,7 @@ const App = (props) => { return (
+
); }; diff --git a/src/summarizepane/components/QuickResponse.jsx b/src/summarizepane/components/QuickResponse.jsx new file mode 100644 index 00000000..d895be9c --- /dev/null +++ b/src/summarizepane/components/QuickResponse.jsx @@ -0,0 +1,135 @@ +/* eslint-disable no-undef */ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable prettier/prettier */ +import * as React from "react"; +import { useState } from "react"; +import { Button, Field, Title3, Checkbox, Textarea, Text, Spinner, tokens, makeStyles} from "@fluentui/react-components"; +import { TextField } from "@fluentui/react"; + +const useStyles = makeStyles({ + + textPromptAndInsertion: { + display: "flex", + flexDirection: "column", + alignItems: "center", + justifyContent: "flex-start" + }, + + textField: { + marginLeft: "15px", + marginTop: "30px", + marginRight: "15px", + + }, + + textAreaField: { + marginLeft: "15px", + marginTop: "10px", + + marginRight: "15px", + minHeight: "150px", + }, + + textCheck: { + marginTop: "10px", + marginLeft: "15px", + marginRight: "15px", + + }, + + checkStyle: { + marginBottom: "15px", + } + +}); + +const QuickResponse = () => { + const [showSpinnerdetails, setshowSpinnerdetails] = useState(false); + const [emailresponse, setEmailresponse] = useState(""); + + const getEmailContent = () => + new Promise((resolve, reject) => { + Office.context.mailbox.item.body.getAsync(Office.CoercionType.Text, (result) => { + if (result.status === Office.AsyncResultStatus.Succeeded) { + resolve(result.value); + } else { + reject(result.error.message); + } + }); + }); + + const handleQuickResponse = async () => { + try { + setshowSpinnerdetails(true); + const emailContent_detail = await getEmailContent(); + console.log(emailContent_detail); + // Propose a quick responsee with AI + const res_detail = await fetch('https://ai.rizlum.com/chat/completions', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: 'Bearer sk-xo6s1sEAjUJupYAj7kjaZqRm6D3QgpYbS', + }, + body: JSON.stringify({ + model: 'riz-text', + messages: [ + { role: "system", content: "You are an email assistant." }, + {role: 'user', + content: 'Generate two possible quick response emails for the following email body: ' + emailContent_detail + '. Each response email is numbered and have a short subject and detailed content, not other things.'}, + ], + }), + }); + + if (!res_detail.ok) { + throw new Error(`HTTP error! status: ${res_detail.status}`); + } + + const data_detail = await res_detail.json(); + console.log(data_detail); + const textContentdetail = data_detail.choices[0].message.content; + setEmailresponse(textContentdetail); + } catch (error) { + console.error('Error fetching data:', error); + } + + setshowSpinnerdetails(false); + + }; + + const styles = useStyles(); + + return ( +
+ + {emailresponse && ( +
+ +
+ )} +
+ ); +}; + +export default QuickResponse; diff --git a/src/summarizepane/components/TextInsertion.jsx b/src/summarizepane/components/TextInsertion.jsx index 35f08b03..3ee25524 100644 --- a/src/summarizepane/components/TextInsertion.jsx +++ b/src/summarizepane/components/TextInsertion.jsx @@ -77,9 +77,10 @@ const TextInsertion = () => { body: JSON.stringify({ model: 'riz-text', messages: [ + { role: "system", content: "You are an email assistant." }, { role: 'user', - content: 'Summarize briefly less than 50 words the content of the following email body: ' + emailContent, + content: 'Summarize briefly less than 40 words the content of the following email body: ' + emailContent, }, ], }), @@ -116,9 +117,10 @@ const TextInsertion = () => { body: JSON.stringify({ model: 'riz-text', messages: [ + { role: "system", content: "You are an email assistant." }, { role: 'user', - content: 'Summarize in detail the content of the following email body: ' + emailContent_detail, + content: 'Summarize in detail less than 200 words the content of the following email body: ' + emailContent_detail, }, ], }), @@ -145,7 +147,7 @@ const TextInsertion = () => { return (
Summarize with AI -
)} -
- -
{emailsummarydetails && (
{ body: JSON.stringify({ model: 'riz-text', messages: [ + { role: "system", content: "You are an email assistant." }, { role: 'user', - content: 'write the email body without subject email, and having line spaces with the following content: ' + text, + content: 'Write an email content without subject with the following content: ' + text, }, ], }),