Create a single page html css js combind code for app which asnyc function to lode models name from this link content https://puter.com/puterai/chat/models
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here's a single-page HTML file that combines HTML, CSS, and JavaScript to asynchronously load and display model names and descriptions from the specified URL.
Key Features:
Single File: All code (HTML, CSS, JS) is within one .html file.
Asynchronous Fetch: Uses async/await with fetch to get data from https://puter.com/puterai/chat/models.
Loading Indicator: Shows a "Loading..." message while fetching data.
Error Handling: Displays an error message if the API call fails.
Dynamic Display: Creates list items (<li>) for each model name and its description.
Simple UI: A button to trigger the loading and a list to display the results.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Models Loader</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 20px;
background-color: #f8f9fa;
color: #333;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
}
h1 {
color: #0056b3;
margin-bottom: 25px;
font-size: 2.2em;
text-align: center;
}
button {
padding: 12px 25px;
font-size: 1.1em;
background-color: #007bff;
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.2s ease;
box-shadow: 0 4px 6px rgba(0, 123, 255, 0.2);
}
button:hover {
background-color: #0056b3;
transform: translateY(-2px);
}
button:active {
background-color: #004085;
transform: translateY(0);
}
#loadingStatus {
font-style: italic;
color: #6c757d;
margin-top: 20px;
display: none; /* Hidden by default */
}
#modelsList {
list-style: none; /* Remove bullet points */
padding: 0;
margin-top: 30px;
width: 90%;
max-width: 700px;
background-color: white;
border-radius: 10px;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
overflow: hidden; /* Ensures border-radius applies to inner elements */
}
#modelsList li {
padding: 15px 20px;
border-bottom: 1px solid #e9ecef;
display: flex;
flex-direction: column;
transition: background-color 0.2s ease;
}
#modelsList li:last-child {
border-bottom: none;
}
#modelsList li:hover {
background-color: #f0f8ff;
}
.model-name {
font-weight: bold;
color: #343a40;
font-size: 1.1em;
margin-bottom: 5px;
}
.model-description {
font-size: 0.95em;
color: #6c757d;
line-height: 1.5;
}
#errorDisplay {
margin-top: 20px;
padding: 15px;
background-color: #ffe0e6;
border: 1px solid #ffb3c0;
border-radius: 8px;
color: #d63384;
width: 90%;
max-width: 700px;
text-align: center;
font-weight: bold;
display: none; /* Hidden by default */
}
</style>
</head>
<body>
<h1>Puter.ai Chat Models</h1>
<button id="loadModelsBtn">Load Models</button>
<div id="loadingStatus">Loading models...</div>
<div id="errorDisplay"></div>
<ul id="modelsList">
<!-- Models will be loaded here by JavaScript -->
</ul>
<script>
document.addEventListener('DOMContentLoaded', () => {
const loadModelsBtn = document.getElementById('loadModelsBtn');
const modelsList = document.getElementById('modelsList');
const loadingStatus = document.getElementById('loadingStatus');
const errorDisplay = document.getElementById('errorDisplay');
const API_URL = 'https://puter.com/puterai/chat/models';
/**
* Asynchronously fetches AI model data from the specified API_URL
* and displays it on the page. Handles loading states and errors.
*/
async function fetchModels() {
// Clear previous content and error messages
modelsList.innerHTML = '';
errorDisplay.style.display = 'none';
errorDisplay.textContent = '';
loadingStatus.style.display = 'block'; // Show loading indicator
try {
const response = await fetch(API_URL);
// Check if the response was successful (status code 200-299)
if (!response.ok) {
// If not successful, throw an error with the status
throw new Error(`HTTP error! Status: ${response.status} - ${response.statusText}`);
}
const models = await response.json(); // Parse the JSON response
if (models.length === 0) {
const listItem = document.createElement('li');
listItem.textContent = 'No models found at this time.';
modelsList.appendChild(listItem);
} else {
// Iterate over each model and create a list item for it
models.forEach(model => {
const listItem = document.createElement('li');
const modelName = document.createElement('div');
modelName.className = 'model-name';
modelName.textContent = model.name;
const modelDescription = document.createElement('div');
modelDescription.className = 'model-description';
// Provide a fallback if description is missing
modelDescription.textContent = model.description || 'No description available for this model.';
listItem.appendChild(modelName);
listItem.appendChild(modelDescription);
modelsList.appendChild(listItem);
});
}
} catch (error) {
// Catch any errors during the fetch or parsing process
console.error('Failed to fetch models:', error);
errorDisplay.textContent = `Error loading models: ${error.message}. Please try again.`;
errorDisplay.style.display = 'block'; // Show error message
} finally {
// This block always executes, whether successful or not
loadingStatus.style.display = 'none'; // Hide loading indicator
}
}
// Add event listener to the button to trigger the fetch function
loadModelsBtn.addEventListener('click', fetchModels);
// Optional: You can uncomment the line below to load models automatically on page load
// fetchModels();
});
</script>
</body>
</html>