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 = {
|
||||
role: string;
|
||||
content:string
|
||||
}
|
||||
// type Message = {
|
||||
// role: string;
|
||||
// content:string
|
||||
// }
|
||||
|
||||
type Chat = {
|
||||
name: string;
|
||||
messages: Message[];
|
||||
timestamp: number;
|
||||
};
|
||||
// type Chat = {
|
||||
// name: string;
|
||||
// messages: Message[];
|
||||
// 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 {
|
||||
if (index >= 0 && index < chatHistory.length) {
|
||||
chatHistory[index] = chat;
|
||||
chatHistory.sort((a, b) => b.timestamp - a.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}`);
|
||||
}
|
||||
}
|
||||
// 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 axios from "axios";
|
||||
import { changeHistory, checkCredentials, getHistory } from './database';
|
||||
import { addMessageToHistory, removeMessageFromHistory } from "./ChatHistory";
|
||||
|
||||
interface InputOutputHandlerProps {
|
||||
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