Skip to content

Commit

Permalink
Save history
Browse files Browse the repository at this point in the history
  • Loading branch information
msveshnikov committed Mar 17, 2024
1 parent 90e52d9 commit 8fed1be
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 43 deletions.
4 changes: 2 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<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" />
<title>React App</title>
<title>Allchat</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
46 changes: 23 additions & 23 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
"short_name": "Allchat",
"name": "Chat with Gemini Pro",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 2 additions & 1 deletion server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getImageTitan } from "./aws.js";

const app = express();
const port = 5000;
const MAX_CONTEXT_LENGTH = 4000;

app.use(cors());
app.use(express.json());
Expand All @@ -30,7 +31,7 @@ app.post("/interact", async (req, res) => {
try {
const contextPrompt = `${chatHistory
.map((chat) => `${chat.user}\n${chat.assistant}`)
.join("\n")}\n\nHuman: ${userInput}\nAssistant:`;
.join("\n")}\n\nHuman: ${userInput}\nAssistant:`.slice(-MAX_CONTEXT_LENGTH);
const textResponse = await getTextGemini(contextPrompt, temperature);
userInput = userInput?.toLowerCase();
let imageResponse;
Expand Down
22 changes: 16 additions & 6 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ function App() {
const [isModelResponding, setIsModelResponding] = useState(false);
const chatContainerRef = useRef(null);

useEffect(() => {
const storedHistory = localStorage.getItem("chatHistory");
if (storedHistory) {
setChatHistory(JSON.parse(storedHistory));
}
}, []);

useEffect(() => {
if (chatContainerRef.current) {
chatContainerRef.current.scrollTop = chatContainerRef.current.scrollHeight;
}
if (chatHistory.length > 0) {
localStorage.setItem("chatHistory", JSON.stringify(chatHistory));
}
}, [chatHistory]);

const handleSubmit = async () => {
if (input.trim()) {
setChatHistory([...chatHistory, { user: input, assistant: null }]);
Expand Down Expand Up @@ -49,12 +65,6 @@ function App() {
}
};

useEffect(() => {
if (chatContainerRef.current) {
chatContainerRef.current.scrollTop = chatContainerRef.current.scrollHeight;
}
}, [chatHistory]);

return (
<Container maxWidth="md" style={{ display: "flex", flexDirection: "column", height: "95vh" }}>
<Box flex={1} overflow="auto" padding={2} display="flex" flexDirection="column" ref={chatContainerRef}>
Expand Down
16 changes: 5 additions & 11 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans",
"Droid Sans", "Helvetica Neue", sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

0 comments on commit 8fed1be

Please sign in to comment.