function fetchStuff(prompt){ updateChat(messages, "user", prompt); var to_send = []; // tres 4/6 iterate through messages array and only load relevant samples foreach (message in messages) { if (message["user"] == socket.id || message["user"] == "all") { to_send.push(message); } } fetch("https://api.openai.com/v1/chat/completions", { method: "POST", headers: { "Content-Type": "application/json", Authorization: "Bearer sk-(your key goes here)", }, body: JSON.stringify({ "model": "gpt-3.5-turbo", // tres 4/6 updated to send to_send "messages": to_send }), }) .then((response) => response.json()) .then((data) => { let answer = data.choices[0].message.content; updateChat(messages, "assistant",data.choices[0].message.content); console.log(answer); io.sockets.emit('gpt-response', { message: "\n" + answer}) console.log(messages) }) .catch((error) => console.error(error)); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter