JSFiddle - React, Tailwind, and code Playground
by velo_ninja
HTML
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OpenAI API Example</title>
</head>
<body>
<script>
// API endpoint for your server
const apiUrl = 'http://localhost:3000/openai-proxy'; // Update with your server endpoint
// Request payload
const requestData = {
model: 'gpt-3.5-turbo',
messages: [
{ role: 'user', content: 'Say this is a test!' }
],
temperature: 0.7
};
// Fetch API request to your server
fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(requestData)
})
.then(response => response.json())
.then(data => {
// Handle the response data here
console.log(data);
})
.catch(error => {
// Handle errors here
console.error('Error:', error);
});
</script>
</body>
</html>