Skip to content

Commit

Permalink
Word & Excel
Browse files Browse the repository at this point in the history
  • Loading branch information
msveshnikov committed Mar 19, 2024
1 parent 1f9bfc5 commit d32429c
Show file tree
Hide file tree
Showing 10 changed files with 410 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ALLCHAT

Node.js backend and a React MUI frontend for an application that interacts with the Gemini Pro model, with history, image painting by Amazon Titan, PDF upload and markdown support. Written fully by _Claude 3 Sonnet_.
Node.js backend and a React MUI frontend for an application that interacts with the Gemini Pro model, with history, image painting by Amazon Titan, PDF/Word/Excel upload and markdown support. Written fully by _Claude 3 Sonnet_.

![image](https://github.com/msveshnikov/allchat/assets/8682996/42b2e4f2-b91b-4712-8ef2-630ebb8919e9)

Expand Down
30 changes: 26 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "allchat",
"version": "1.0.0",
"version": "1.1.0",
"dependencies": {
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.0",
Expand Down Expand Up @@ -31,5 +31,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11"
}
}
39 changes: 37 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,52 @@
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>AllChat - Intelligent Conversational AI Assistant</title>
<meta name="title" content="AllChat - Intelligent Conversational AI Assistant" />
<meta
name="description"
content="AllChat is a powerful AI-driven conversational assistant that can help you with writing, analysis, question answering, math, coding, and more. Engage in intelligent conversations and get accurate responses in real-time."
/>
<meta name="theme-color" content="#000000" />
<meta name="description" content="Chat with Gemini Pro" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />

<!-- Open Graph / Facebook -->
<meta property="og:type" content="website" />
<meta property="og:url" content="https://allchat.online/" />
<meta property="og:title" content="AllChat - Intelligent Conversational AI Assistant" />
<meta
property="og:description"
content="AllChat is a powerful AI-driven conversational assistant that can help you with writing, analysis, question answering, math, coding, and more. Engage in intelligent conversations and get accurate responses in real-time."
/>
<meta property="og:image" content="https://allchat.online/og-image.png" />

<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:url" content="https://allchat.online/" />
<meta property="twitter:title" content="AllChat - Intelligent Conversational AI Assistant" />
<meta
property="twitter:description"
content="AllChat is a powerful AI-driven conversational assistant that can help you with writing, analysis, question answering, math, coding, and more. Engage in intelligent conversations and get accurate responses in real-time."
/>
<meta property="twitter:image" content="https://allchat.online/twitter-card.png" />

<!-- Other Meta Tags -->
<meta
name="keywords"
content="AI assistant, conversational AI, natural language processing, chatbot, intelligent assistant, question answering, writing assistance, coding assistance, math assistance"
/>
<meta name="author" content="Max Sveshnikov" />
<meta name="robots" content="index, follow" />
<meta name="googlebot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
<meta name="bingbot" content="index, follow, max-snippets:2, max-image-preview:large, max-video-preview:-1" />

<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=PT+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap"
rel="stylesheet"
/>
<title>Allchat</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
42 changes: 34 additions & 8 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { getTextGemini } from "./gemini.js";
import { getImageTitan } from "./aws.js";
import hasPaintWord from "./paint.js";
import pdfParser from "pdf-parse";
import mammoth from "mammoth";
import * as xlsx from "xlsx";

const MAX_CONTEXT_LENGTH = 8000;

Expand All @@ -15,9 +17,9 @@ app.use(express.json({ limit: "10mb" }));

morgan.token("body", (req, res) => {
const body = req.body;
if (body && typeof body === "object" && "pdfBytesBase64" in body) {
if (body && typeof body === "object" && "fileBytesBase64" in body) {
const clonedBody = { ...body };
clonedBody.pdfBytesBase64 = "<PDF_BYTES_REDACTED>";
clonedBody.fileBytesBase64 = "<FILE_BYTES_REDACTED>";
return JSON.stringify(clonedBody);
}
return JSON.stringify(body);
Expand All @@ -28,21 +30,45 @@ app.use(morgan(loggerFormat));

const limiter = rateLimit({
windowMs: 60 * 1000,
max: 10,
limit: 10,
standardHeaders: "draft-7",
legacyHeaders: false,
});

app.use(limiter);

app.post("/interact", async (req, res) => {
let userInput = req.body.input;
const chatHistory = req.body.chatHistory || [];
const temperature = req.body.temperature || 0.5;
const pdfBytesBase64 = req.body.pdfBytesBase64;
const fileBytesBase64 = req.body.fileBytesBase64;
const fileType = req.body.fileType;

try {
if (pdfBytesBase64) {
const pdfBytes = Buffer.from(pdfBytesBase64, "base64");
const data = await pdfParser(pdfBytes);
userInput = data.text;
if (fileBytesBase64) {
const fileBytes = Buffer.from(fileBytesBase64, "base64");
if (fileType === "pdf") {
const data = await pdfParser(fileBytes);
userInput = data.text;
} else if (
fileType === "msword" ||
fileType === "vnd.openxmlformats-officedocument.wordprocessingml.document"
) {
const docResult = await mammoth.convertToHtml({ buffer: fileBytes });
userInput = docResult.value;
} else if (fileType === "xlsx" || fileType === "vnd.openxmlformats-officedocument.spreadsheetml.sheet") {
const workbook = xlsx.read(fileBytes, { type: "buffer" });
const sheetNames = workbook.SheetNames;
let excelText = "";
sheetNames.forEach((sheetName) => {
const worksheet = workbook.Sheets[sheetName];
excelText += xlsx.utils.sheet_to_txt(worksheet);
});
userInput = excelText;
} else {
console.error("Unsupported file type");
return res.status(400).json({ error: "Unsupported file type" });
}
}

const contextPrompt = `${chatHistory
Expand Down
Loading

0 comments on commit d32429c

Please sign in to comment.