forked from React-Group/interstellar_ai
start of chatHistory
This commit is contained in:
parent
dc44bd22d7
commit
dbf30fa8a7
3 changed files with 38 additions and 27 deletions
|
@ -1,30 +1,28 @@
|
||||||
|
|
||||||
type Message = {
|
// type Message = {
|
||||||
role: string;
|
// role: string;
|
||||||
content:string
|
// content:string
|
||||||
}
|
// }
|
||||||
|
|
||||||
type Chat = {
|
// type Chat = {
|
||||||
name: string;
|
// name: string;
|
||||||
messages: Message[];
|
// messages: Message[];
|
||||||
timestamp: number;
|
// timestamp: number;
|
||||||
};
|
// };
|
||||||
|
|
||||||
export let chatHistory: Chat[] = [];
|
// export function addMessageToHistory(index: number, chat: Chat): void {
|
||||||
|
// if (index >= 0 && index < chatHistory.length) {
|
||||||
|
// chatHistory[index] = chat;
|
||||||
|
// chatHistory.sort((a, b) => b.timestamp - a.timestamp)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
export function addMessageToHistory(index: number, chat: Chat): void {
|
// export function removeMessageFromHistory(timestamp: number): void {
|
||||||
if (index >= 0 && index < chatHistory.length) {
|
// const index = chatHistory.findIndex((msg) => msg.timestamp === timestamp);
|
||||||
chatHistory[index] = chat;
|
// if (index > -1) {
|
||||||
chatHistory.sort((a, b) => b.timestamp - a.timestamp)
|
// chatHistory.splice(index, 1);
|
||||||
}
|
// console.log(`Removed message with timestamp: ${timestamp}`);
|
||||||
}
|
// } else {
|
||||||
|
// console.log(`Message not found with timestamp: ${timestamp}`);
|
||||||
export function removeMessageFromHistory(timestamp: number): void {
|
// }
|
||||||
const index = chatHistory.findIndex((msg) => msg.timestamp === timestamp);
|
// }
|
||||||
if (index > -1) {
|
|
||||||
chatHistory.splice(index, 1);
|
|
||||||
console.log(`Removed message with timestamp: ${timestamp}`);
|
|
||||||
} else {
|
|
||||||
console.log(`Message not found with timestamp: ${timestamp}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import InputFrontend from "../components/InputFrontend";
|
||||||
import { sendToVoiceRecognition } from "./voice_backend"
|
import { sendToVoiceRecognition } from "./voice_backend"
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { changeHistory, checkCredentials, getHistory } from './database';
|
import { changeHistory, checkCredentials, getHistory } from './database';
|
||||||
import { addMessageToHistory, removeMessageFromHistory } from "./ChatHistory";
|
|
||||||
|
|
||||||
interface InputOutputHandlerProps {
|
interface InputOutputHandlerProps {
|
||||||
selectedIndex: number;
|
selectedIndex: number;
|
||||||
|
|
14
app/hooks/useChatHistory.tsx
Normal file
14
app/hooks/useChatHistory.tsx
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import { useState } from "react"
|
||||||
|
|
||||||
|
const useChatHistory = () => {
|
||||||
|
type ChatMessages = {
|
||||||
|
name: string
|
||||||
|
messages: {}
|
||||||
|
timestamp: number
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const [chathistory, setChatHistory] = useState<ChatMessages[]>()
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useChatHistory
|
Loading…
Reference in a new issue