Advertisement
Josiahiscool73

ai model stacking

Apr 22nd, 2025 (edited)
35
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.01 KB | None | 0 0
  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 Code Generator</title>
  7. <script src="https://cdn.tailwindcss.com"></script>
  8. <style>
  9. /* Custom scrollbar for the codebox */
  10. .codebox::-webkit-scrollbar {
  11. width: 8px;
  12. }
  13. .codebox::-webkit-scrollbar-track {
  14. background: #1e1e1e;
  15. border-radius: 10px;
  16. }
  17. .codebox::-webkit-scrollbar-thumb {
  18. background: #00bfa6;
  19. border-radius: 10px;
  20. }
  21. .codebox::-webkit-scrollbar-thumb:hover {
  22. background: #009e8e;
  23. }
  24. </style>
  25. </head>
  26. <body class="flex h-screen bg-gray-900 text-gray-100 font-sans">
  27.  
  28. <div class="sidebar w-64 bg-gray-800 p-6 border-r border-gray-700 flex flex-col">
  29. <h2 class="text-xl font-bold mb-4 text-teal-400">💻 Code Refinery</h2>
  30. <p class="text-sm mb-4 text-gray-400">5-Step AI Code Enhancement</p> <p class="text-sm mb-2 font-semibold">Models used:</p>
  31. <ul class="list-disc list-inside text-sm text-gray-400 space-y-1">
  32. <li>AI 5</li>
  33. <li>AI 4</li>
  34. <li>AI 3</li>
  35. <li>AI 2</li>
  36. <li>AI 1</li>
  37. </ul>
  38. </div>
  39.  
  40. <div class="main flex-1 flex flex-col p-8">
  41. <div class="chatbox flex flex-col gap-4 h-full">
  42. <textarea
  43. id="prompt"
  44. rows="5"
  45. placeholder="Describe what you want coded..."
  46. class="w-full p-4 bg-gray-800 border border-gray-700 text-white rounded-lg resize-none focus:outline-none focus:border-teal-500"
  47. ></textarea>
  48.  
  49. <button
  50. onclick="startPipeline()"
  51. class="px-6 py-3 bg-teal-600 text-white font-semibold rounded-lg cursor-pointer hover:bg-teal-700 transition duration-200 ease-in-out shadow-lg"
  52. >
  53. 🚀 Generate Code
  54. </button>
  55.  
  56. <div id="status" class="status mt-4 text-sm italic text-gray-500">Status: Waiting for input...</div>
  57.  
  58. <div
  59. id="output"
  60. class="codebox flex-1 bg-gray-800 p-4 rounded-lg border-l-4 border-teal-500 text-gray-300 font-mono whitespace-pre-wrap overflow-y-auto text-sm"
  61. style="min-height: 200px;" /* Ensure minimum height */
  62. >
  63. Your code will appear here...
  64. </div>
  65.  
  66. <button
  67. onclick="copyCode()"
  68. class="px-6 py-3 bg-gray-700 text-white font-semibold rounded-lg cursor-pointer hover:bg-gray-600 transition duration-200 ease-in-out shadow-lg"
  69. >
  70. 📋 Copy Final Code
  71. </button>
  72. </div>
  73. </div>
  74.  
  75. <script>
  76. // !!! IMPORTANT: Replace with your actual OpenRouter API Key !!!
  77. // Be cautious about exposing API keys in client-side code in production.
  78. const API_KEY = ""; // Your API key added here
  79.  
  80. // List of model IDs to use in the pipeline, change these with the ids/names in openrouter
  81. const MODELS = [
  82. "thudm/glm-z1-32b:free",
  83. "google/gemini-2.0-flash-exp:free",
  84. "moonshotai/kimi-vl-a3b-thinking:free",
  85. "deepseek/deepseek-chat-v3-0324:free",
  86. "deepseek/deepseek-r1-zero:free"
  87. ];
  88.  
  89. /**
  90. * Queries a specific AI model via the OpenRouter API.
  91. * @param {string} prompt - The prompt to send to the model.
  92. * @param {string} model - The model name to use.
  93. * @returns {Promise<string>} - A promise that resolves with the model's response or an error message.
  94. */
  95. async function queryModel(prompt, model) {
  96. const res = await fetch("https://openrouter.ai/api/v1/chat/completions", {
  97. method: "POST",
  98. headers: {
  99. "Authorization": `Bearer ${API_KEY}`,
  100. "Content-Type": "application/json",
  101. "X-Title": "AI Code Generator App" // Custom header for OpenRouter
  102. },
  103. body: JSON.stringify({
  104. model: model,
  105. messages: [
  106. { role: "user", content: prompt }
  107. ],
  108. // Optional: Add temperature, max_tokens, etc. here if needed
  109. temperature: 0.7,
  110. max_tokens: 65536 // Adjust as needed
  111. })
  112. });
  113.  
  114. // Check for non-OK HTTP status codes
  115. if (!res.ok) {
  116. const errorBody = await res.text(); // Get error response body
  117. throw new Error(`HTTP error ${res.status} from ${model}: ${errorBody}`);
  118. }
  119.  
  120. const data = await res.json();
  121.  
  122. // Check if the response structure is as expected
  123. if (!data.choices || data.choices.length === 0 || !data.choices[0].message || !data.choices[0].message.content) {
  124. console.error("Unexpected API response structure:", data);
  125. return `[${model} returned an unexpected response format.]`;
  126. }
  127.  
  128. return data.choices[0].message.content;
  129. }
  130.  
  131. /**
  132. * Starts the code generation pipeline, querying models sequentially.
  133. */
  134. async function startPipeline() {
  135. const userPrompt = document.getElementById("prompt").value.trim();
  136. const outputBox = document.getElementById("output");
  137. const statusBox = document.getElementById("status");
  138.  
  139. if (!userPrompt) {
  140. alert("Please enter a prompt first!");
  141. return;
  142. }
  143.  
  144. if (API_KEY === "YOUR_OPENROUTER_API_KEY") {
  145. statusBox.textContent = "Error: Please replace 'YOUR_OPENROUTER_API_KEY' with your actual API key.";
  146. alert("Please replace 'YOUR_OPENROUTER_API_KEY' with your actual API key.");
  147. return;
  148. }
  149.  
  150.  
  151. let code = ""; // Variable to hold the evolving code
  152. outputBox.textContent = "Starting AI pipeline..."; // Initial status
  153.  
  154. for (let i = 0; i < MODELS.length; i++) {
  155. const currentModel = MODELS[i];
  156. statusBox.textContent = `Step ${i + 1}/${MODELS.length}: Querying ${currentModel}...`;
  157. outputBox.textContent = `Waiting for ${currentModel} response...`; // Clear previous output while waiting
  158.  
  159. try {
  160. // For the first model, use the user's prompt.
  161. // For subsequent models, use the previous model's output as the prompt for improvement/debugging.
  162. const prompt = i === 0
  163. ? userPrompt
  164. : `Review and improve/debug the following code. Provide the complete, corrected code and say NOTHING else except the code:\n\n\`\`\`\n${code}\n\`\`\``; // Added markdown formatting for clarity
  165.  
  166. const modelResponse = await queryModel(prompt, currentModel);
  167.  
  168. // Update the code variable with the latest response
  169. code = modelResponse;
  170.  
  171. statusBox.textContent = `Step ${i + 1}/${MODELS.length}: ${currentModel} responded.`;
  172. outputBox.textContent = code; // Display the current model's output
  173.  
  174. } catch (err) {
  175. // If any model fails, log the error and stop the pipeline
  176. console.error(`Error during pipeline step ${i + 1} with ${currentModel}:`, err);
  177. statusBox.textContent = `Step ${i + 1}/${MODELS.length}: ${currentModel} failed. Error: ${err.message}`;
  178. outputBox.textContent = `An error occurred during the pipeline. See status for details.\n\nLast received code (if any):\n${code}\n\nError: ${err.message}`;
  179. break; // Stop the pipeline on error
  180. }
  181.  
  182. // Add a small delay between model calls to avoid hitting rate limits too quickly
  183. if (i < MODELS.length - 1) {
  184. statusBox.textContent += " Waiting before next step...";
  185. await new Promise(resolve => setTimeout(resolve, 2000)); // Wait for 2 seconds
  186. }
  187. }
  188.  
  189. // Final status update
  190. if (statusBox.textContent.includes("failed")) {
  191. statusBox.textContent = "Pipeline finished with errors.";
  192. } else {
  193. statusBox.textContent = "✅ Pipeline complete. Final code generated.";
  194. }
  195. }
  196.  
  197. /**
  198. * Copies the content of the output box to the clipboard.
  199. */
  200. function copyCode() {
  201. const output = document.getElementById("output").textContent;
  202. if (!output || output === "Your code will appear here..." || output.includes("An error occurred")) {
  203. alert("Nothing to copy yet or an error occurred.");
  204. return;
  205. }
  206. navigator.clipboard.writeText(output).then(() => {
  207. // Use a simple message box instead of alert as per instructions
  208. statusBox.textContent = "Code copied to clipboard!";
  209. setTimeout(() => {
  210. // Restore previous status after a short delay
  211. if (!statusBox.textContent.includes("Pipeline complete")) {
  212. statusBox.textContent = "✅ Pipeline complete. Final code generated.";
  213. }
  214. }, 3000); // Message disappears after 3 seconds
  215. }).catch(err => {
  216. console.error("Failed to copy code:", err);
  217. statusBox.textContent = "Failed to copy code.";
  218. });
  219. }
  220.  
  221. // Get status box element globally for easier access in copyCode
  222. const statusBox = document.getElementById("status");
  223.  
  224. </script>
  225. </body>
  226. </html>
  227.  
Advertisement
Comments
  • Josiahiscool73
    9 hours (edited)
    # text 0.59 KB | 0 0
    1. for a simple tutorial on how to use/change the ai models, from line 78 to line 86 lets you add your openrouter api key and change the model names via ai model Id names, if you actually use money for AI and your a loser, add your paid model IDs there.
    2.  
    3. for temp(temperature changes creativity of the models responses, 0.1 - 0 is recommended but its 0.7 by default) control go to line 109 also somewhere near line 109 lets you change the tokens.
    4.  
    5. this lets you stack ai models for coding, allowing you to add more and more parameters so you can multi-ai till you get for example 10 trillion parameters
Add Comment
Please, Sign In to add comment
Advertisement