Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	use new provider
Browse files
    	
        server.js
    CHANGED
    
    | 
         @@ -188,15 +188,15 @@ app.post("/api/ask-ai", async (req, res) => { 
     | 
|
| 188 | 
         
             
                  provider: "sambanova",
         
     | 
| 189 | 
         
             
                  messages: [
         
     | 
| 190 | 
         
             
                    {
         
     | 
| 191 | 
         
            -
                      role: " 
     | 
| 192 | 
         
             
                      content:
         
     | 
| 193 | 
         
             
                        "ONLY USE HTML, CSS AND JAVASCRIPT. If you want to use ICON make sure to import the library first. Try to create the best UI possible by using only HTML, CSS and JAVASCRIPT. Also, try to ellaborate as much as you can, to create something unique. ALWAYS GIVE THE RESPONSE INTO A SINGLE HTML FILE",
         
     | 
| 194 | 
         
             
                    },
         
     | 
| 195 | 
         
             
                    ...(html
         
     | 
| 196 | 
         
             
                      ? [
         
     | 
| 197 | 
         
             
                          {
         
     | 
| 198 | 
         
            -
                            role: " 
     | 
| 199 | 
         
            -
                            content: ` 
     | 
| 200 | 
         
             
                          },
         
     | 
| 201 | 
         
             
                        ]
         
     | 
| 202 | 
         
             
                      : []),
         
     | 
| 
         @@ -205,7 +205,7 @@ app.post("/api/ask-ai", async (req, res) => { 
     | 
|
| 205 | 
         
             
                      content: prompt,
         
     | 
| 206 | 
         
             
                    },
         
     | 
| 207 | 
         
             
                  ],
         
     | 
| 208 | 
         
            -
                  max_tokens:  
     | 
| 209 | 
         
             
                });
         
     | 
| 210 | 
         | 
| 211 | 
         
             
                while (true) {
         
     | 
| 
         @@ -216,11 +216,16 @@ app.post("/api/ask-ai", async (req, res) => { 
     | 
|
| 216 | 
         
             
                  const chunk = value.choices[0]?.delta?.content;
         
     | 
| 217 | 
         
             
                  if (chunk) {
         
     | 
| 218 | 
         
             
                    // Stream chunk to client
         
     | 
| 219 | 
         
            -
                     
     | 
| 220 | 
         
            -
                     
     | 
| 221 | 
         
            -
             
     | 
| 222 | 
         
            -
             
     | 
| 223 | 
         
            -
             
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 224 | 
         
             
                      break;
         
     | 
| 225 | 
         
             
                    }
         
     | 
| 226 | 
         
             
                  }
         
     | 
| 
         @@ -234,7 +239,7 @@ app.post("/api/ask-ai", async (req, res) => { 
     | 
|
| 234 | 
         
             
                if (!res.headersSent) {
         
     | 
| 235 | 
         
             
                  res.status(500).send({
         
     | 
| 236 | 
         
             
                    ok: false,
         
     | 
| 237 | 
         
            -
                    message:  
     | 
| 238 | 
         
             
                  });
         
     | 
| 239 | 
         
             
                } else {
         
     | 
| 240 | 
         
             
                  // Otherwise end the stream
         
     | 
| 
         | 
|
| 188 | 
         
             
                  provider: "sambanova",
         
     | 
| 189 | 
         
             
                  messages: [
         
     | 
| 190 | 
         
             
                    {
         
     | 
| 191 | 
         
            +
                      role: "user",
         
     | 
| 192 | 
         
             
                      content:
         
     | 
| 193 | 
         
             
                        "ONLY USE HTML, CSS AND JAVASCRIPT. If you want to use ICON make sure to import the library first. Try to create the best UI possible by using only HTML, CSS and JAVASCRIPT. Also, try to ellaborate as much as you can, to create something unique. ALWAYS GIVE THE RESPONSE INTO A SINGLE HTML FILE",
         
     | 
| 194 | 
         
             
                    },
         
     | 
| 195 | 
         
             
                    ...(html
         
     | 
| 196 | 
         
             
                      ? [
         
     | 
| 197 | 
         
             
                          {
         
     | 
| 198 | 
         
            +
                            role: "system",
         
     | 
| 199 | 
         
            +
                            content: `The current code is: ${html}.`,
         
     | 
| 200 | 
         
             
                          },
         
     | 
| 201 | 
         
             
                        ]
         
     | 
| 202 | 
         
             
                      : []),
         
     | 
| 
         | 
|
| 205 | 
         
             
                      content: prompt,
         
     | 
| 206 | 
         
             
                    },
         
     | 
| 207 | 
         
             
                  ],
         
     | 
| 208 | 
         
            +
                  max_tokens: 6_000,
         
     | 
| 209 | 
         
             
                });
         
     | 
| 210 | 
         | 
| 211 | 
         
             
                while (true) {
         
     | 
| 
         | 
|
| 216 | 
         
             
                  const chunk = value.choices[0]?.delta?.content;
         
     | 
| 217 | 
         
             
                  if (chunk) {
         
     | 
| 218 | 
         
             
                    // Stream chunk to client
         
     | 
| 219 | 
         
            +
                    let newChunk = chunk;
         
     | 
| 220 | 
         
            +
                    if (chunk.includes("</html>")) {
         
     | 
| 221 | 
         
            +
                      console.log("Chunk before replacement:", newChunk);
         
     | 
| 222 | 
         
            +
                      // Replace everything after the last </html> tag with an empty string
         
     | 
| 223 | 
         
            +
                      newChunk = newChunk.replace(/<\/html>[\s\S]*/, "</html>");
         
     | 
| 224 | 
         
            +
                      console.log("Chunk after replacement:", newChunk);
         
     | 
| 225 | 
         
            +
                    }
         
     | 
| 226 | 
         
            +
                    completeResponse += newChunk;
         
     | 
| 227 | 
         
            +
                    res.write(newChunk);
         
     | 
| 228 | 
         
            +
                    if (newChunk.includes("</html>")) {
         
     | 
| 229 | 
         
             
                      break;
         
     | 
| 230 | 
         
             
                    }
         
     | 
| 231 | 
         
             
                  }
         
     | 
| 
         | 
|
| 239 | 
         
             
                if (!res.headersSent) {
         
     | 
| 240 | 
         
             
                  res.status(500).send({
         
     | 
| 241 | 
         
             
                    ok: false,
         
     | 
| 242 | 
         
            +
                    message: error.message,
         
     | 
| 243 | 
         
             
                  });
         
     | 
| 244 | 
         
             
                } else {
         
     | 
| 245 | 
         
             
                  // Otherwise end the stream
         
     |