123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>小天-AI</title>
- <style>
- body {
- font-family: 'Roboto', Arial, sans-serif;
- margin: 0;
- padding: 0;
- background-color: #f4f4f9;
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100vh;
- }
- .container {
- width: 500px;
- background-color: #fff;
- box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
- border-radius: 8px;
- overflow: hidden;
- }
- h1 {
- background-color: #007bff;
- color: #fff;
- text-align: center;
- padding: 15px;
- margin: 0;
- font-size: 1.5em;
- }
- form {
- padding: 20px;
- }
- label {
- display: block;
- margin-bottom: 10px;
- font-weight: bold;
- }
- textarea {
- width: 100%;
- height: 100px;
- border: 1px solid #ccc;
- border-radius: 4px;
- padding: 10px;
- resize: none;
- }
- button {
- width: 100%;
- padding: 10px;
- background-color: #007bff;
- color: #fff;
- border: none;
- border-radius: 4px;
- cursor: pointer;
- transition: background-color 0.3s ease;
- }
- button:hover {
- background-color: #0056b3;
- }
- #response {
- margin-top: 20px;
- padding: 10px;
- background-color: #f9f9f9;
- border-top: 1px solid #ccc;
- max-height: 200px;
- overflow-y: auto;
- font-family: monospace;
- white-space: pre-wrap;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <h1>小天-AI</h1>
- <form id="chatForm">
- <label for="content">你的问题:</label>
- <textarea id="content" name="content" placeholder="请输入你的问题在这里..."></textarea>
- <button type="submit">发送</button>
- </form>
- <div id="response"></div>
- <div id="sessionId" style="margin-top: 10px; font-size: 0.9em; color: #666;"></div>
- </div>
- <script>
- document.getElementById('chatForm').addEventListener('submit', function(event) {
- event.preventDefault();
- const content = document.getElementById('content').value;
- const requestBody = JSON.stringify({content: content});
- const token = "eyJhbGciOiJIUzUxMiJ9.eyIiOjEwMDMsInVzZXJfaWQiOjIxMywidXNlcl9rZXkiOiJlYzUxODMzNjdmYTk0ODgwOGQwZjEwODEyOWVmNjgwOSIsInVzZXJuYW1lIjoi6LW16YeR6ZuoIn0.zWulXcesI1TRcDmiAHuQ9P2WHDE2l7mDmuunx13TmVl6E5Yvs8nZvu1ddtINdw0lrnnR3Q5lZaRH3mJJTaDhig";
- fetch('/ai/aliTyqw', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': `Bearer ${token}`
- },
- body: requestBody
- })
- .then(response => {
- if (!response.ok) {
- throw new Error('Network response was not ok');
- }
- return response.text();
- })
- .then(data => {
- document.getElementById('response').innerText = '';
- // 解析数据,提取 reasoningContent
- const lines = data.split('\n');
- let responseLines = [];
- for (let line of lines) {
- try {
- const parsedLine = JSON.parse(line.replace('data: ', '').trim());
- if (parsedLine.reasoningContent !== null) {
- responseLines.push(parsedLine.reasoningContent);
- }
- } catch (e) {
- console.error('Error parsing line:', e);
- }
- }
- // 将 reasoningContent 的内容拼接成完整字符串
- const fullResponse = responseLines.join('');
- // 逐字显示响应内容
- let index = 0;
- const responseElement = document.getElementById('response');
- const interval = setInterval(() => {
- if (index < fullResponse.length) {
- responseElement.innerText += fullResponse[index];
- index++;
- } else {
- clearInterval(interval);
- }
- }, 50);
- })
- .catch(error => {
- document.getElementById('response').innerText = 'Error: ' + error.message;
- });
- })
- </script>
- </body>
- </html>
|