html Copy code
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Stories</title>
<style>
body,
html {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: hidden;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-family: Arial, sans-serif;
background: #f3f4f6;
}
#container {
width: 90%;
max-width: 600px;
display: flex;
flex-direction: column;
align-items: center;
gap: 15px;
height: 90%;
box-sizing: border-box;
}
h1 {
margin: 0;
font-size: 2.5em;
color: #333;
}
#language-switch {
position: absolute;
top: 10px;
right: 10px;
width: 80px;
user-select: none;
}
.custom-select {
position: relative;
display: inline-block;
}
.select-selected {
background-color: #4CAF50;
color: white;
padding: 8px 12px;
border-radius: 8px;
cursor: pointer;
text-align: center;
transition: background-color 0.3s ease;
}
.select-selected:hover {
background-color: #45a049;
}
.select-items {
position: absolute;
background-color: white;
border: 1px solid #ddd;
border-radius: 8px;
width: 100%;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
z-index: 99;
display: none;
animation: slideDown 0.3s forwards;
}
.select-items.open {
display: block;
animation: slideDown 0.3s forwards;
}
.select-items div {
color: #333;
padding: 8px 12px;
cursor: pointer;
transition: background-color 0.3s;
}
.select-items div:hover {
background-color: #f1f1f1;
}
textarea {
width: 100%;
flex-grow: 1;
resize: none;
padding: 10px;
font-size: 1em;
border-radius: 8px;
border: 1px solid #ccc;
box-sizing: border-box;
min-height: 100px;
max-height: 200px;
}
textarea:focus {
outline: none;
border-color: blue;
}
button {
padding: 10px 20px;
font-size: 1.2em;
border-radius: 8px;
border: none;
background-color: #4CAF50;
color: white;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #45a049;
}
@keyframes slideDown {
from {
max-height: 0;
opacity: 0;
}
to {
max-height: 500px;
opacity: 1;
}
}
</style>
</head>
<body>
<div id="language-switch" class="custom-select">
<div class="select-selected">RU</div>
<div class="select-items">
<div data-value="ru">RU</div>
<div data-value="en">EN</div>
</div>
</div>
<div id="container">
<h1 id="title">AI Stories</h1>
<textarea id="story-input" placeholder="Введите текст здесь..."></textarea>
<button id="generate-story">Придумать историю</button>
</div>
<script type="module">
import { translations } from './translations.js';
import { requestAI } from './aiRequest.js';
function switchLanguage(language) {
document.getElementById('title').innerText = translations.title[language];
document.getElementById('generate-story').innerText = translations.button[language];
document.getElementById('story-input').placeholder = translations.placeholder[language];
}
document.addEventListener('DOMContentLoaded', () => {
const selected = document.querySelector('.select-selected');
const items = document.querySelector('.select-items');
selected.addEventListener('click', function() {
items.classList.toggle('open');
});
document.querySelectorAll('.select-items div').forEach(item => {
item.addEventListener('click', function() {
selected.textContent = this.textContent;
items.classList.remove('open');
switchLanguage(this.getAttribute('data-value'));
});
});
document.addEventListener('click', function(e) {
if (!e.target.closest('.custom-select')) {
items.classList.remove('open');
}
});
document.getElementById('generate-story').addEventListener('click', () => {
const storyInput = document.getElementById('story-input').value;
const currentLanguage = document.querySelector('.select-selected').textContent.toLowerCase();
const prompt = `Придумай историю на основе запроса "${storyInput}" на языке "${currentLanguage}"`;
requestAI(prompt, {
responseCallback: ({ data, modData, message }) => {
console.log('Response message:', message);
},
errorCallback: ({ message }) => {
console.error(message);
},
});
});
});
</script>
<script type="module">
// translations.js
export const translations = {
title: { ru: "AI Stories", en: "AI Stories" },
button: { ru: "Придумать историю", en: "Generate Story" },
placeholder: { ru: "Введите текст здесь...", en: "Enter text here..." }
};
</script>
<script type="module">
// aiRequest.js
export function requestAI(prompt, {
url = 'https://nexra.aryahcr.cc/api/chat/complements',
model = 'gpt-4o',
stream = false,
markdown = false,
type = 'text',
messages = [],
responseCallback = () => {},
successCallback = () => {},
errorCallback = () => {},
} = {}) {
if (type === 'text') {
messages.push({ role: 'user', content: prompt });
let body = {
messages,
model,
stream,
markdown,
};
if (url.indexOf('/gptweb') !== -1) {
body = {
prompt,
markdown,
};
}
if (messages.length > 1 && model === 'llama-3.1') {
body.messages = [{ role: 'user', content: JSON.stringify({ messages: messages }) }];
}
if (model === 'Bing') {
body['conversation_style'] = 'balanced';
}
if (model === 'blackbox') {
body['websearch'] = false;
}
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
}).then(response => response.text()).then((data) => {
const modData = JSON.parse(data.slice(data.indexOf('{')));
const message = modData.message || modData.gpt;
responseCallback({ data, modData, message, isStream: stream, isStreaming: false });
successCallback({ data, modData, message, isStream: stream, isStreaming: false });
}).catch((error) => {
errorCallback({ message: `Ошибка в функции requestAI (type: text, stream: false): ${error}`, error });
});
}
}
</script>
</body>
</html>