Skip to content

Commit cfdd4cb

Browse files
committed
added: chat now remember previous messages
1 parent ec21436 commit cfdd4cb

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/components/Chat.jsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function Chat() {
4949
{isHuman: false, content: output, timestamp: dayjs().calendar().toString(),}
5050
]);
5151
}
52+
5253
}, [output])
5354

5455
useEffect(() => {
@@ -67,7 +68,7 @@ function Chat() {
6768
DecreaseAvailableActions()
6869
SendMessage(input, (errorMessage) => {
6970
setMessageSnackbar(errorMessage);
70-
}).then(async (response) => {
71+
}, messages).then(async (response) => {
7172
IncreaseAvailableActions()
7273
setOutput(response)
7374
}).catch((error) => {
@@ -89,7 +90,7 @@ function Chat() {
8990
DecreaseAvailableActions()
9091
SendMessage(tip, (errorMessage) => {
9192
setMessageSnackbar(errorMessage);
92-
}).then(async (response) => {
93+
}, messages).then(async (response) => {
9394
IncreaseAvailableActions()
9495
setOutput(response)
9596
}).catch((error) => {

src/lib/OpenAi.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ export function SetOpenAiParams(newParams) {
1717
openAiParams = {...openAiParams, ...newParams};
1818
}
1919

20-
export async function SendMessage(message, setError) {
20+
export async function SendMessage(message, setError, messages) {
2121
try {
2222
const chatCompletion = await openai.chat.completions.create({
2323
messages: [{
24-
"role": "system",
25-
"content": "You are NeuraChat, an AI chat system developed by Michael Teida."
26-
}, {"role": "user", "content": message}],
24+
"role": "system", "content": "You are NeuraChat, an AI chat system developed by Michael Teida. You are designed to provide accurate, detailed, and contextually relevant responses. You understand and respect user's privacy and confidentiality. You are capable of generating creative content, identifying errors, and rectifying them. You strive to be the best AI assistant, always learning and improving."},
25+
...messages.map(({isHuman, content}) => ({"role": isHuman ? "user" : "assistant", "content": content})),
26+
{"role": "user", "content": message}],
2727
...openAiParams
2828
})
2929
return chatCompletion.choices[0].message.content;

0 commit comments

Comments
 (0)