From 3dacbbea035cdffb6a58665702a5ad1aa880be94 Mon Sep 17 00:00:00 2001 From: Trinh Ngoc Tu Date: Fri, 6 Dec 2024 11:16:15 +0100 Subject: [PATCH] Divide into summarize briefly and summarize in detail for summarize feature --- .../components/TextInsertion.jsx | 89 ++++++++++++++++--- src/taskpane/components/TextInsertion.jsx | 3 +- 2 files changed, 81 insertions(+), 11 deletions(-) diff --git a/src/summarizepane/components/TextInsertion.jsx b/src/summarizepane/components/TextInsertion.jsx index 5d5082ad..35f08b03 100644 --- a/src/summarizepane/components/TextInsertion.jsx +++ b/src/summarizepane/components/TextInsertion.jsx @@ -1,3 +1,6 @@ +/* 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"; @@ -44,7 +47,9 @@ const useStyles = makeStyles({ const TextInsertion = () => { const [showSpinner, setshowSpinner] = useState(false); + const [showSpinnerdetails, setshowSpinnerdetails] = useState(false); const [emailsummary, setEmailsummary] = useState(""); + const [emailsummarydetails, setEmailsummarydetails] = useState(""); const getEmailContent = () => new Promise((resolve, reject) => { @@ -74,7 +79,7 @@ const TextInsertion = () => { messages: [ { role: 'user', - content: 'Summarize the content of the following email body: ' + emailContent, + content: 'Summarize briefly less than 50 words the content of the following email body: ' + emailContent, }, ], }), @@ -83,7 +88,7 @@ const TextInsertion = () => { if (!res.ok) { throw new Error(`HTTP error! status: ${res.status}`); } - + const data = await res.json(); console.log(data); const textContent = data.choices[0].message.content; @@ -96,15 +101,50 @@ const TextInsertion = () => { }; + const handleSummaryLong = async () => { + try { + setshowSpinnerdetails(true); + const emailContent_detail = await getEmailContent(); + console.log(emailContent_detail); + // Summarize email content in details 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: 'user', + content: 'Summarize in detail the content of the following email body: ' + emailContent_detail, + }, + ], + }), + }); + + 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; + setEmailsummarydetails(textContentdetail); + } catch (error) { + console.error('Error fetching data:', error); + } + + setshowSpinnerdetails(false); + + }; + const styles = useStyles(); return (
Summarize with AI - Generate your read email by AI. - - {/* 3. Check if you want also AI to generate the email subject. - setWriteSubject(data.checked)} value={writeSubject}/> */} +
+ {emailsummarydetails && ( +
+ +
)} ); diff --git a/src/taskpane/components/TextInsertion.jsx b/src/taskpane/components/TextInsertion.jsx index 9e5cd353..ec51865d 100644 --- a/src/taskpane/components/TextInsertion.jsx +++ b/src/taskpane/components/TextInsertion.jsx @@ -1,3 +1,4 @@ +/* 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"; @@ -65,7 +66,7 @@ const TextInsertion = () => { messages: [ { role: 'user', - content: 'write the email body without subject email with the following content: ' + text, + content: 'write the email body without subject email, and having line spaces with the following content: ' + text, }, ], }),