Skip to content

Commit 1d1b13a

Browse files
committed
added: avatar, message colors, messages positioning
1 parent 2d0c37f commit 1d1b13a

File tree

4 files changed

+38
-26
lines changed

4 files changed

+38
-26
lines changed
-2.84 KB
Loading

src/components/Chat.jsx

+35-21
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import {Box, Button, Card, CardContent, FormControl, Input as JoyInput, Sheet, Stack, Typography} from "@mui/joy";
1+
import {Box, Button, Card, FormControl, Input as JoyInput, Sheet, Stack, Typography, Avatar} from "@mui/joy";
22
import EditIcon from "@mui/icons-material/Edit";
33
import ArrowUpwardIcon from "@mui/icons-material/ArrowUpward";
44
import {useEffect, useState, useRef} from "react";
55
import {sendMessage} from "../lib/OpenAi.jsx";
6+
import NeuraChatLogoSquare from "../assets/logo NeuraChatAi 100x100.png"
67

78
function Chat() {
89
const [input, setInput] = useState("")
910
const [output, setOutput] = useState("")
1011
const [messages, setMessages] = useState([{
1112
isHuman: false,
12-
content: "Example text from NeuraChat",
13+
content: "Hello, how can I help you?",
1314
timestamp: new Date(Date.now())
1415
}])
1516

@@ -25,7 +26,7 @@ function Chat() {
2526
}, [output])
2627

2728
useEffect(() => {
28-
messagesEndRef.current.scrollIntoView({ behavior: "smooth" })
29+
messagesEndRef.current.scrollIntoView({behavior: "smooth"})
2930
}, [messages])
3031

3132
const handleSend = async () => {
@@ -38,7 +39,7 @@ function Chat() {
3839
}
3940

4041
const handleClick = async (event) => {
41-
if(event.key === 'Enter') {
42+
if (event.key === 'Enter') {
4243
event.preventDefault()
4344
await handleSend()
4445
}
@@ -50,26 +51,39 @@ function Chat() {
5051
flex: 1,
5152
minHeight: 0,
5253
overflowY: 'scroll',
53-
flexDirection: 'column',
54+
backgroundColor: 'background.level1'
5455
}}>
5556
{messages.map((el, index) => {
5657
return (
57-
<Box key={index} sx={{maxWidth: {xs: 'auto', sm: "60%"}, minWidth: 'auto'}}>
58-
<Stack direction="row" justifyContent="space-between" spacing={2}>
59-
<Typography level="body-xs">
60-
{el.isHuman ? "You" : "NeuraChat"}
61-
</Typography>
62-
<Typography level="body-xs">
63-
{el.timestamp.getHours()}:{el.timestamp.getMinutes()}:{el.timestamp.getSeconds()}
64-
</Typography>
65-
</Stack>
66-
<Sheet variant="outlined"
67-
sx={{p: 1, borderRadius: "sm", backgroundColor: "background.level1"}}>
68-
<Typography component="p" fontSize={{xs: "sm", sm: "md"}}
69-
sx={{wordBreak: "break-word"}}>
70-
{el.content}
71-
</Typography>
72-
</Sheet>
58+
<Box key={index} display="flex">
59+
{el.isHuman ? null : <Avatar alt="NeuraChat Avatar" src={NeuraChatLogoSquare} sx={{marginRight: 1, mt: 0.4}}/>}
60+
<Box display="flex" flexDirection="column" alignItems={el.isHuman ? "flex-end" : "flex-start"} width="100%">
61+
<Box sx={{width: {xs: 'auto', sm: "60%"}, minWidth: 'auto'}}>
62+
<Stack direction="row" justifyContent="space-between" spacing={2}>
63+
<Typography level="body-xs">
64+
{el.isHuman ? "You" : "NeuraChat"}
65+
</Typography>
66+
<Typography level="body-xs">
67+
{el.timestamp.getHours()}:{el.timestamp.getMinutes()}:{el.timestamp.getSeconds()}
68+
</Typography>
69+
</Stack>
70+
<Sheet variant="outlined"
71+
sx={{
72+
p: 1,
73+
borderRadius: "sm",
74+
backgroundColor: el.isHuman ? "primary.500" : "primary.50",
75+
"&:hover": {filter: "brightness(97%)"}
76+
}}>
77+
<Typography component="p" fontSize={{xs: "sm", sm: "md"}}
78+
sx={{
79+
color: el.isHuman ? "neutral.50" : "text.primary",
80+
wordBreak: "break-word"
81+
}}>
82+
{el.content}
83+
</Typography>
84+
</Sheet>
85+
</Box>
86+
</Box>
7387
</Box>
7488
)
7589
})}

src/lib/OpenAi.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ const openai = new OpenAI({
77

88
export async function sendMessage(message) {
99
const params = {
10-
model: 'gpt-3.5-turbo',
10+
model: 'gpt-3.5-turbo-16k',
1111
temperature: 0.7, // how creative OpenAi should be (0 - 1)
12-
max_tokens: 400,
12+
max_tokens: 10000,
1313
frequency_penalty: 0.01, // parametr frequency_penalty pozwala sterować różnorodnością generowanego tekstu przez model GPT, modyfikując rozkład prawdopodobieństwa, aby rzadziej generować słowa, które model częściej widział podczas treningu.
1414
top_p: 1, // shrinks or grows the “pool” of available tokens to choose from, the domain to select over. 1=big pool, 0=small pool
1515
};
1616

1717
const chatCompletion = await openai.chat.completions.create({
18-
messages: [{"role": "user", "content": message}],
18+
messages: [{"role": "system", "content": "You are NeuraChat, an AI chat system developed by Michael Teida."},{"role": "user", "content": message}],
1919
...params
2020
})
2121

src/pages/About.jsx

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ export function About() {
44
return (
55
<Card spacing={2} sx={{my: 2}}>
66
<Box>About NeuraChatAi</Box>
7-
<Box>About NeuraChatAi</Box>
8-
<Box>About NeuraChatAi</Box>
97
</Card>
108
);
119
}

0 commit comments

Comments
 (0)