dpsk.html 4.7 KB

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