import requests from "./request.js"; class Initialize{ constructor(uiManager){ this.convId; this.convTitle; this.uiManager = uiManager; this.systemPrompt = `your response syntax should be: ###for heading### \n ** for sub heading ** \n *** for text highlight/bold text ***`; this.model = null; } async initialize(model=null){ this.convTitle=null; this.convId=null; this.uiManager.messagesDiv.innerHTML = ''; this.uiManager.prevChatsCont.innerHTML = ''; await this.fetchConvs(); document.querySelectorAll('.prevChat').forEach((elem)=>{ elem.addEventListener('click', ()=>{ this.reInitialize(elem.id) }) }) if(model!=null){ this.model = model; } else{ await this.fetchModels() } } async reInitialize(id){ this.convTitle=null; this.convId=id; this.uiManager.messagesDiv.innerHTML = ''; await this.fetchConv(id); } async fetchConv(id){ try { const response = await requests.request('POST','/fetch',{"Content-Type": "application/json"},JSON.stringify({"convId": id}),false); if(!response.ok){ alert('error while fetching conversations') return } const data = await response.json(); this.convTitle = data['title']; const arr = data['messages']; for(let i=0;i{ const selected = e.target.value; this.initialize(selected) }) } } export default Initialize