From d38589aeece5edc76b8b44007d6680899f45e662 Mon Sep 17 00:00:00 2001 From: Trinh Ngoc Tu Date: Sun, 1 Dec 2024 14:33:54 +0100 Subject: [PATCH] Update the manifest.xml and add the summary function --- .DS_Store | Bin 6148 -> 6148 bytes manifest.xml | 22 ++-- .../components/TextInsertion.jsx | 102 +++++++++++------- src/taskpane/components/TextInsertion.jsx | 2 +- 4 files changed, 74 insertions(+), 52 deletions(-) diff --git a/.DS_Store b/.DS_Store index 2bbdd4270c550afc218097557a0c310b2399581f..fbab92ed165857b0883586fa0111eb55469f3684 100644 GIT binary patch delta 64 zcmZoMXffDO&oX&C%LZjmh9Cx421f=L245hp$B@gA;+d15oRpKF#K6EHz`($~adI82 T*ycRenM@NK*fz6s{N)D#Cm#_n delta 61 zcmZoMXffDO&!V2okjRk7kjaq7kjhZZP{N?cP{EMPkmH$?pPZDFpTxkxAi%)DC_6ci R<>2N-)&)$P**X650|4xp5Ig_? diff --git a/manifest.xml b/manifest.xml index 1b07bf64..05c8187e 100644 --- a/manifest.xml +++ b/manifest.xml @@ -2,15 +2,15 @@ eb774e01-2b8b-4518-8a0b-0475615abdd0 1.0.0.0 - OutlookLLM Rizlum + OutlookLLM RizLum en-US - - + + - http://localhost + https://localhost @@ -23,7 +23,7 @@
- + 250
@@ -95,14 +95,14 @@
- - - + + + - - - + + + diff --git a/src/summarizepane/components/TextInsertion.jsx b/src/summarizepane/components/TextInsertion.jsx index 9c36a60a..5d5082ad 100644 --- a/src/summarizepane/components/TextInsertion.jsx +++ b/src/summarizepane/components/TextInsertion.jsx @@ -1,6 +1,7 @@ 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"; import { insertText } from "../outlook"; import Taskpane from "../taskpane"; @@ -42,54 +43,59 @@ const useStyles = makeStyles({ }); const TextInsertion = () => { - const [text, setText] = useState("Write an email to make a meeting with client"); const [showSpinner, setshowSpinner] = useState(false); - const [writeSubject, setWriteSubject] = useState(false); + const [emailsummary, setEmailsummary] = 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 handleTextInsertion = async () => { try { - setshowSpinner(true); + const emailContent = await getEmailContent(); + console.log(emailContent); + // Summarize email content with AI + const res = 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 the content of the following email body: ' + emailContent, + }, + ], + }), + }); - // const response = await fetch("http://localhost:11434/api/generate", { - // method: "POST", - // headers: { - // "Content-Type": "application/json", - // }, - // body: JSON.stringify({ - // model: "llama3.2", - // prompt: text, - // }) - // }); - const response = "Hello World, we are Rizlum"; - console.log(response); - - // if (!response.ok) { - // throw new Error("Network response was not ok"); - // } - - // Handle success response if needed - console.log('Data sent successfully'); - - //const textContent = await response.json(); - const textContent = "Insert this magic text from Riz Lum :D"; - //await insertText(textContent, writeSubject); - await insertText(textContent); - setshowSpinner(false); - + 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; + setEmailsummary(textContent); } catch (error) { + console.error('Error fetching data:', error); + } + setshowSpinner(false); - console.error('Error sending data:',error); - } - }; - const handleTextChange = async (event) => { - setText(event.target.value); - }; - const styles = useStyles(); return ( @@ -103,13 +109,29 @@ const TextInsertion = () => { {showSpinner && ( )} - {showSpinner ? ' Generating email...' : 'Summarize with AI'} + {showSpinner ? ' Summarizing email...' : 'Summarize with AI'} {/* */} - {!showSpinner && ( + {emailsummary && (
- -
+ + )} ); diff --git a/src/taskpane/components/TextInsertion.jsx b/src/taskpane/components/TextInsertion.jsx index f7c87728..9e5cd353 100644 --- a/src/taskpane/components/TextInsertion.jsx +++ b/src/taskpane/components/TextInsertion.jsx @@ -65,7 +65,7 @@ const TextInsertion = () => { messages: [ { role: 'user', - content: text, + content: 'write the email body without subject email with the following content: ' + text, }, ], }),