| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>AI 测试页面</title>
- <style>
- body {
- display: flex;
- justify-content: center;
- align-items: center;
- min-height: 100vh;
- padding: 20px;
- }
- .container {
- display: grid;
- container-type: inline-size;
- width: 100%;
- max-width: 900px;
- gap: 20px;
- }
- textarea {
- width: 100%;
- padding: 10px;
- min-height: 120px;
- }
- button {
- width: 100%;
- padding: 10px;
- }
- button:disabled {
- opacity: 0.6;
- }
- .loading {
- display: none;
- }
- .loading.active {
- display: block;
- }
- .spinner {
- width: 20px;
- height: 20px;
- border: 3px solid #f3f3f3;
- border-top: 3px solid #000;
- border-radius: 50%;
- animation: spin 1s linear infinite;
- display: inline-block;
- }
- @keyframes spin {
- 0% { transform: rotate(0deg); }
- 100% { transform: rotate(360deg); }
- }
- .result-box {
- padding: 20px;
- min-height: 200px;
- max-height: 500px;
- overflow-y: auto;
- white-space: pre-wrap;
- border: 1px solid #ccc;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <textarea id="prompt" placeholder="请输入提示词..."></textarea>
-
- <button id="sendBtn" onclick="sendRequest()">
- <span>发送</span>
- </button>
- <div class="loading" id="loading">
- <div class="spinner"></div>
- <span>正在处理...</span>
- </div>
- <div class="result-box" id="resultBox"></div>
- </div>
- <script>
- const apiUrl = 'https://' + window.location.hostname;
- const promptTextarea = document.getElementById('prompt');
- const sendBtn = document.getElementById('sendBtn');
- const loadingDiv = document.getElementById('loading');
- const resultBox = document.getElementById('resultBox');
- async function sendRequest() {
- const prompt = promptTextarea.value.trim();
- if (!prompt) {
- alert('请输入提示词!');
- return;
- }
- sendBtn.disabled = true;
- loadingDiv.classList.add('active');
- resultBox.textContent = '';
- try {
- const response = await fetch(`${apiUrl}/api/chat`, {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ prompt })
- });
- const data = await response.json();
- resultBox.textContent = data.success
- ? JSON.stringify(data.data, null, 2)
- : `错误: ${data.error}`;
- } catch (error) {
- resultBox.textContent = `请求失败: ${error.message}`;
- } finally {
- sendBtn.disabled = false;
- loadingDiv.classList.remove('active');
- }
- }
- promptTextarea.addEventListener('keydown', (e) => {
- if (e.key === 'Enter' && e.ctrlKey) sendRequest();
- });
- </script>
- </body>
- </html>
|