Skip to content

Latest commit

 

History

History
54 lines (51 loc) · 1.76 KB

chat.md

File metadata and controls

54 lines (51 loc) · 1.76 KB
toc comments layout title author permalink
true
true
base
map
rachit
/chat

Chat Testing

User Message:

System Message:

<script> // JavaScript to handle form submission document.getElementById('messageForm').addEventListener('submit', function(e) { e.preventDefault(); // Prevents default form submission behavior // Get the input values from the form var userMessage = document.getElementById('userMessage').value; var systemMessage = document.getElementById('systemMessage').value; // Construct the request payload var data = { "messages": [ {"role": "user", "content": userMessage}, {"role": "system", "content": systemMessage} ] }; // Send the POST request fetch('https://codemaxxers.stu.nighthawkcodingsociety.com/api/chat', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(data), }) .then(response => response.json()) .then(data => { console.log('Success:', data); // Display the response - example: get content of index 0 document.getElementById('apiResponse').innerText = data.choices[0].message.content; }) .catch((error) => { console.error('Error:', error); }); }); </script>