Mayx's Home Page https://mabbs.github.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

384 lines
9.7 KiB

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Cloudflare AI</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="icon"
  8. href="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2016%2016'%3E%3Ctext%20x='0'%20y='14'%20style='filter:%20invert(100%);'%3E☁️%3C/text%3E%3C/svg%3E"
  9. type="image/svg+xml" />
  10. <style>
  11. body {
  12. font-family: 'Raleway', sans-serif;
  13. margin: 0;
  14. padding: 20px;
  15. background-color: #222;
  16. color: #fff;
  17. backdrop-filter: blur(10px);
  18. overflow: hidden;
  19. height: 100vh;
  20. }
  21. h1 {
  22. text-align: center;
  23. font-weight: 900;
  24. text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  25. font-size: 64px;
  26. }
  27. h2 {
  28. text-align: center;
  29. font-weight: bold;
  30. text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  31. font-size: 20px;
  32. }
  33. form {
  34. margin-bottom: 20px;
  35. display: flex;
  36. justify-content: center;
  37. /* Center items horizontally */
  38. align-items: center;
  39. /* Center items vertically */
  40. position: fixed;
  41. bottom: 12px;
  42. width: 100vw;
  43. border-radius: 10px;
  44. padding: 10px;
  45. /* Add some padding to give space around the items */
  46. }
  47. label {
  48. font-weight: bold;
  49. color: #ccc;
  50. }
  51. input[type="text"] {
  52. width: 50%;
  53. padding: 10px;
  54. background-color: rgba(0, 0, 0, 0.3);
  55. color: #fff;
  56. border: none;
  57. border-radius: 5px;
  58. }
  59. textarea {
  60. width: 50%;
  61. padding: 9px;
  62. color: whitesmoke;
  63. border: none;
  64. border-radius: 5px;
  65. font-size: 18px;
  66. background-color: #222222;
  67. }
  68. textarea::-webkit-scrollbar {
  69. display: none;
  70. }
  71. textarea:focus {
  72. outline: none;
  73. }
  74. #response {
  75. max-width: 80%;
  76. height: calc(100% - 250px);
  77. margin-left: 10%;
  78. overflow-y: scroll;
  79. }
  80. #response::-webkit-scrollbar {
  81. width: 10px;
  82. border-radius: 50%;
  83. }
  84. .user-message {
  85. background-color: rgba(71, 71, 71, 0.3);
  86. padding: 10px;
  87. margin-bottom: 10px;
  88. margin-left: 40%;
  89. max-width: 60%;
  90. border-radius: 10px;
  91. box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
  92. backdrop-filter: blur(4px);
  93. -webkit-backdrop-filter: blur(4px);
  94. border-radius: 10px;
  95. border: 1px solid rgba(255, 255, 255, 0.18);
  96. color: whitesmoke;
  97. }
  98. .ai-message {
  99. background-color: rgba(71, 71, 71, 0.3);
  100. padding: 10px;
  101. margin-bottom: 10px;
  102. margin-right: 40%;
  103. max-width: 60%;
  104. border-radius: 10px;
  105. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  106. color: whitesmoke;
  107. }
  108. p {
  109. margin: 0;
  110. padding: 0;
  111. }
  112. .smaller {
  113. font-size: 15;
  114. }
  115. .fa-github {
  116. text-decoration: none;
  117. color: inherit;
  118. position: fixed;
  119. bottom: 0;
  120. right: 0;
  121. padding: 15px;
  122. }
  123. .dropbtn {
  124. background-color: #191b1c;
  125. color: white;
  126. padding: 16px;
  127. font-size: 16px;
  128. border: none;
  129. cursor: pointer;
  130. }
  131. .dropdown {
  132. position: relative;
  133. display: inline-block;
  134. position: absolute;
  135. top: 5px;
  136. left: 5px;
  137. padding: 10px;
  138. color: #fff;
  139. border: none;
  140. border-radius: 5px;
  141. cursor: pointer;
  142. }
  143. .dropdown-content {
  144. display: none;
  145. position: absolute;
  146. background-color: #191b1c;
  147. min-width: 160px;
  148. box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  149. z-index: 1;
  150. }
  151. .dropdown-content a {
  152. color: #fff;
  153. padding: 12px 16px;
  154. text-decoration: none;
  155. display: block;
  156. }
  157. .dropdown-content a:hover {
  158. background-color: black
  159. }
  160. .dropdown:hover .dropdown-content {
  161. display: block;
  162. }
  163. .dropdown:hover .dropbtn {
  164. background-color: #444;
  165. }
  166. button {
  167. font-size: 18px;
  168. color: #e1e1e1;
  169. font-family: inherit;
  170. font-weight: 800;
  171. cursor: pointer;
  172. position: relative;
  173. border: none;
  174. background: none;
  175. text-transform: uppercase;
  176. transition-timing-function: cubic-bezier(0.25, 0.8, 0.25, 1);
  177. transition-duration: 400ms;
  178. transition-property: color;
  179. }
  180. button:focus,
  181. button:hover {
  182. color: #fff;
  183. }
  184. button:focus:after,
  185. button:hover:after {
  186. width: 100%;
  187. left: 0%;
  188. }
  189. button:after {
  190. content: "";
  191. pointer-events: none;
  192. bottom: -2px;
  193. left: 50%;
  194. position: absolute;
  195. width: 0%;
  196. height: 2px;
  197. background-color: #fff;
  198. transition-timing-function: cubic-bezier(0.25, 0.8, 0.25, 1);
  199. transition-duration: 400ms;
  200. transition-property: width, left;
  201. }
  202. .github-icon {
  203. position: fixed;
  204. right: 50px;
  205. bottom: 50px;
  206. }
  207. /* if screen width<1000 then max -width=100% */
  208. @media screen and (max-width: 1000px) {
  209. #response {
  210. max-width: 100%;
  211. margin-left: 0;
  212. height: calc(100% - 280px);
  213. }
  214. textarea {
  215. width: 80%;
  216. }
  217. .github-icon {
  218. visibility: hidden;
  219. }
  220. form {
  221. bottom: 0;
  222. }
  223. .ai-message {
  224. max-width: 80%;
  225. min-width: 80%;
  226. }
  227. }
  228. </style>
  229. <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
  230. <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
  231. <link rel="preconnect" href="https://fonts.googleapis.com">
  232. <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  233. <link href="https://fonts.googleapis.com/css2?family=Raleway:wght@700&display=swap" rel="stylesheet">
  234. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  235. </head>
  236. <body>
  237. <h1>Cloudflare AI</h1>
  238. <div class="dropdown">
  239. <button class="dropbtn">Settings</button>
  240. <div class="dropdown-content">
  241. <a href="#" onclick='setApiUrl()'>Custom API URL</a>
  242. <a href="#" onclick='setIDsession()'>Custom ID Session</a>
  243. </div>
  244. </div>
  245. <div id="response">
  246. <div class="ai-message">Hey there, how can i assist you?</div>
  247. </div>
  248. <form id="chatForm">
  249. <textarea id="input" type="text" placeholder="Send a message"></textarea>
  250. <button type="submit"></button>
  251. </form>
  252. <a class="fa fa-github github-icon" href="https://github.com/localuser-isback/Cloudflare-AI" style="font-size:36px">
  253. <script>
  254. // --------------- CONFIG --------------- //
  255. // modify URL to your API
  256. let apiUrl = "https://llama.mayx.eu.org"
  257. // ----------- END OF CONFIG ------------ //
  258. let uuid = '';
  259. function setApiUrl() {
  260. const customUrl = prompt("Enter custom API URL: ");
  261. if (customUrl) {
  262. apiUrl = customUrl;
  263. }
  264. }
  265. function setIDsession() {
  266. const customUUID = prompt("Enter custom session ID: ");
  267. if (customUUID) {
  268. uuid = customUUID;
  269. }
  270. }
  271. function generateUUID() {
  272. let newUUID = '';
  273. const chars = 'abcdef0123456789';
  274. for (let i = 0; i < 32; i++) {
  275. const charIndex = Math.floor(Math.random() * chars.length);
  276. newUUID += chars[charIndex];
  277. if (i === 7 || i === 11 || i === 15 || i === 19) {
  278. newUUID += '-';
  279. }
  280. }
  281. return newUUID;
  282. }
  283. const chatForm = document.getElementById('chatForm');
  284. const inputField = document.getElementById('input');
  285. const responseDiv = document.getElementById('response');
  286. function chat() {
  287. var input = inputField.value;
  288. input = encodeURIComponent(input)
  289. const userMessageDiv = document.createElement('div');
  290. userMessageDiv.className = 'user-message';
  291. userMessageDiv.innerText = decodeURIComponent(input);
  292. responseDiv.appendChild(userMessageDiv);
  293. const loadingDiv = document.createElement('div');
  294. loadingDiv.className = 'loading';
  295. loadingDiv.innerHTML = `<svg width="30" height="30" viewBox="0 0 50 50"><circle cx="25" cy="25" r="20" stroke="black" stroke-width="4" fill="none" /><circle cx="25" cy="25" r="20" stroke="#3498db" stroke-width="4" fill="none" stroke-dasharray="90" stroke-dashoffset="0"><animateTransform attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="1s" repeatCount="indefinite"/></circle></svg><center class="smaller">If you recive an error than wait 1-2 minutes refresh and try again.</center>`;
  296. responseDiv.appendChild(loadingDiv);
  297. axios.get(`${apiUrl}/${uuid}?q=${encodeURIComponent(input)}`)
  298. .then((response) => {
  299. responseDiv.removeChild(loadingDiv);
  300. const aiMessages = response.data[0].response.filter(message => message.role === 'system' && message.content.response);
  301. if (aiMessages.length > 0) {
  302. const lastAiMessage = aiMessages[aiMessages.length - 1];
  303. const aiMessageDiv = document.createElement('div');
  304. aiMessageDiv.className = 'ai-message';
  305. aiMessageDiv.innerHTML = marked.parse(lastAiMessage.content.response);
  306. responseDiv.appendChild(aiMessageDiv);
  307. }
  308. inputField.value = '';
  309. })
  310. .catch((error) => {
  311. console.log("Error receiving response:", error);
  312. });
  313. }
  314. chatForm.addEventListener('submit', (event) => {
  315. event.preventDefault();
  316. chat()
  317. });
  318. inputField.addEventListener('keydown', (event) => {
  319. if (event.key === 'Enter') {
  320. if (!event.shiftKey) {
  321. event.preventDefault();
  322. chat()
  323. }
  324. }
  325. });
  326. if (!uuid) {
  327. uuid = generateUUID();
  328. }
  329. </script>
  330. </body>
  331. </html>

Powered by TurnKey Linux.