tyqw.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>小天-AI</title>
  7. <style>
  8. body {
  9. font-family: 'Roboto', Arial, sans-serif;
  10. margin: 0;
  11. padding: 0;
  12. background-color: #f4f4f9;
  13. display: flex;
  14. justify-content: center;
  15. align-items: center;
  16. height: 100vh;
  17. }
  18. .container {
  19. width: 500px;
  20. background-color: #fff;
  21. box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  22. border-radius: 8px;
  23. overflow: hidden;
  24. }
  25. h1 {
  26. background-color: #007bff;
  27. color: #fff;
  28. text-align: center;
  29. padding: 15px;
  30. margin: 0;
  31. font-size: 1.5em;
  32. }
  33. form {
  34. padding: 20px;
  35. }
  36. label {
  37. display: block;
  38. margin-bottom: 10px;
  39. font-weight: bold;
  40. }
  41. textarea {
  42. width: 100%;
  43. height: 100px;
  44. border: 1px solid #ccc;
  45. border-radius: 4px;
  46. padding: 10px;
  47. resize: none;
  48. }
  49. button {
  50. width: 100%;
  51. padding: 10px;
  52. background-color: #007bff;
  53. color: #fff;
  54. border: none;
  55. border-radius: 4px;
  56. cursor: pointer;
  57. transition: background-color 0.3s ease;
  58. }
  59. button:hover {
  60. background-color: #0056b3;
  61. }
  62. #response {
  63. margin-top: 20px;
  64. padding: 10px;
  65. background-color: #f9f9f9;
  66. border-top: 1px solid #ccc;
  67. max-height: 200px;
  68. overflow-y: auto;
  69. font-family: monospace;
  70. white-space: pre-wrap;
  71. }
  72. </style>
  73. </head>
  74. <body>
  75. <div class="container">
  76. <h1>小天-AI</h1>
  77. <form id="chatForm">
  78. <label for="content">你的问题:</label>
  79. <textarea id="content" name="content" placeholder="请输入你的问题在这里..."></textarea>
  80. <button type="submit">发送</button>
  81. </form>
  82. <div id="response"></div>
  83. <div id="sessionId" style="margin-top: 10px; font-size: 0.9em; color: #666;"></div>
  84. </div>
  85. <script>
  86. document.getElementById('chatForm').addEventListener('submit', function(event) {
  87. event.preventDefault();
  88. const content = document.getElementById('content').value;
  89. const requestBody = JSON.stringify({content: content});
  90. const token = "eyJhbGciOiJIUzUxMiJ9.eyIiOjEwMDMsInVzZXJfaWQiOjIxMywidXNlcl9rZXkiOiJlYzUxODMzNjdmYTk0ODgwOGQwZjEwODEyOWVmNjgwOSIsInVzZXJuYW1lIjoi6LW16YeR6ZuoIn0.zWulXcesI1TRcDmiAHuQ9P2WHDE2l7mDmuunx13TmVl6E5Yvs8nZvu1ddtINdw0lrnnR3Q5lZaRH3mJJTaDhig";
  91. fetch('/ai/aliTyqw', {
  92. method: 'POST',
  93. headers: {
  94. 'Content-Type': 'application/json',
  95. 'Authorization': `Bearer ${token}`
  96. },
  97. body: requestBody
  98. })
  99. .then(response => {
  100. if (!response.ok) {
  101. throw new Error('Network response was not ok');
  102. }
  103. return response.text();
  104. })
  105. .then(data => {
  106. document.getElementById('response').innerText = '';
  107. // 解析数据,提取 reasoningContent
  108. const lines = data.split('\n');
  109. let responseLines = [];
  110. for (let line of lines) {
  111. try {
  112. const parsedLine = JSON.parse(line.replace('data: ', '').trim());
  113. if (parsedLine.reasoningContent !== null) {
  114. responseLines.push(parsedLine.reasoningContent);
  115. }
  116. } catch (e) {
  117. console.error('Error parsing line:', e);
  118. }
  119. }
  120. // 将 reasoningContent 的内容拼接成完整字符串
  121. const fullResponse = responseLines.join('');
  122. // 逐字显示响应内容
  123. let index = 0;
  124. const responseElement = document.getElementById('response');
  125. const interval = setInterval(() => {
  126. if (index < fullResponse.length) {
  127. responseElement.innerText += fullResponse[index];
  128. index++;
  129. } else {
  130. clearInterval(interval);
  131. }
  132. }, 50);
  133. })
  134. .catch(error => {
  135. document.getElementById('response').innerText = 'Error: ' + error.message;
  136. });
  137. })
  138. </script>
  139. </body>
  140. </html>