Commit
·
9d13a4e
1
Parent(s):
3bcd657
various improvements
Browse files- src/alpine.mts +1 -1
- src/index.mts +24 -8
src/alpine.mts
CHANGED
|
@@ -217,4 +217,4 @@ notify(message) {
|
|
| 217 |
|
| 218 |
export const methodsPrompt = getPromptFromFeatures(methods)
|
| 219 |
|
| 220 |
-
export const alpine =
|
|
|
|
| 217 |
|
| 218 |
export const methodsPrompt = getPromptFromFeatures(methods)
|
| 219 |
|
| 220 |
+
export const alpine = "# Alpine.js docs\n"+ attributesPrompt // + propertiesPrompt + methodsPrompt
|
src/index.mts
CHANGED
|
@@ -14,7 +14,7 @@ const css = [
|
|
| 14 |
.join("")
|
| 15 |
|
| 16 |
const script = [
|
| 17 |
-
|
| 18 |
"/js/[email protected]"
|
| 19 |
].map(item => `<script src="${item}"></script>`)
|
| 20 |
.join("")
|
|
@@ -29,8 +29,9 @@ const llm = await AutoModelForCausalLM.from_pretrained$(
|
|
| 29 |
const app = express()
|
| 30 |
const port = 7860
|
| 31 |
|
| 32 |
-
const timeoutInSec =
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
app.use(express.static("public"))
|
| 36 |
|
|
@@ -53,6 +54,17 @@ const endRequest = (id: string, reason: string) => {
|
|
| 53 |
console.log(`request ${id} ended (${reason})`)
|
| 54 |
}
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
app.get("/debug", (req, res) => {
|
| 57 |
res.write(JSON.stringify({
|
| 58 |
nbTotal: pending.total,
|
|
@@ -96,20 +108,24 @@ app.get("/", async (req, res) => {
|
|
| 96 |
Generate a webpage written in English about: ${req.query.prompt}.
|
| 97 |
# Documentation
|
| 98 |
${daisy}
|
| 99 |
-
${alpine}
|
| 100 |
# Guidelines
|
| 101 |
-
-
|
|
|
|
|
|
|
|
|
|
| 102 |
- You MUST use English, not Latin! (I repeat: do NOT write lorem ipsum!)
|
|
|
|
| 103 |
- Use a central layout by wrapping everything in a \`<div class="flex flex-col justify-center">\`
|
| 104 |
# Result output
|
| 105 |
${prefix}`
|
| 106 |
|
| 107 |
|
| 108 |
try {
|
|
|
|
| 109 |
const inputTokens = await llm.tokenize(finalPrompt)
|
| 110 |
console.log("initializing the generator (may take 30s or more)")
|
| 111 |
const generator = await llm.generate(inputTokens)
|
| 112 |
-
|
| 113 |
for await (const token of generator) {
|
| 114 |
if (!pending.queue.includes(id)) {
|
| 115 |
break
|
|
@@ -119,9 +135,9 @@ ${prefix}`
|
|
| 119 |
res.write(tmp)
|
| 120 |
}
|
| 121 |
|
| 122 |
-
endRequest(id, `normal end of the
|
| 123 |
} catch (e) {
|
| 124 |
-
endRequest(id, `premature end of the
|
| 125 |
}
|
| 126 |
|
| 127 |
try {
|
|
|
|
| 14 |
.join("")
|
| 15 |
|
| 16 |
const script = [
|
| 17 |
+
"/js/[email protected]",
|
| 18 |
"/js/[email protected]"
|
| 19 |
].map(item => `<script src="${item}"></script>`)
|
| 20 |
.join("")
|
|
|
|
| 29 |
const app = express()
|
| 30 |
const port = 7860
|
| 31 |
|
| 32 |
+
const timeoutInSec = 60 * 60
|
| 33 |
+
|
| 34 |
+
console.log("timeout set to 60 minutes")
|
| 35 |
|
| 36 |
app.use(express.static("public"))
|
| 37 |
|
|
|
|
| 54 |
console.log(`request ${id} ended (${reason})`)
|
| 55 |
}
|
| 56 |
|
| 57 |
+
// we need to exit the open Python process or else it will keep running in the background
|
| 58 |
+
process.on('SIGINT', () => {
|
| 59 |
+
try {
|
| 60 |
+
(python as any).exit()
|
| 61 |
+
} catch (err) {
|
| 62 |
+
// exiting Pythonia can get a bit messy: try/catch or not,
|
| 63 |
+
// you *will* see warnings and tracebacks in the console
|
| 64 |
+
}
|
| 65 |
+
process.exit(0)
|
| 66 |
+
})
|
| 67 |
+
|
| 68 |
app.get("/debug", (req, res) => {
|
| 69 |
res.write(JSON.stringify({
|
| 70 |
nbTotal: pending.total,
|
|
|
|
| 108 |
Generate a webpage written in English about: ${req.query.prompt}.
|
| 109 |
# Documentation
|
| 110 |
${daisy}
|
|
|
|
| 111 |
# Guidelines
|
| 112 |
+
- Do not write a tutorial or repeat the instruction, but directly write the final code within a script tag
|
| 113 |
+
- Use a color scheme consistent with the brief and theme
|
| 114 |
+
- You need to use Tailwind CSS and DaisyUI for the UI, pure vanilla JS and AlpineJS for the JS.
|
| 115 |
+
- You vanilla JS code will be written directly inside the page, using <script type="text/javascript">...</script>
|
| 116 |
- You MUST use English, not Latin! (I repeat: do NOT write lorem ipsum!)
|
| 117 |
+
- No need to write code comments, and try to make the code compact (short function names etc)
|
| 118 |
- Use a central layout by wrapping everything in a \`<div class="flex flex-col justify-center">\`
|
| 119 |
# Result output
|
| 120 |
${prefix}`
|
| 121 |
|
| 122 |
|
| 123 |
try {
|
| 124 |
+
// be careful: if you input a prompt which is too large, you may experience a timeout
|
| 125 |
const inputTokens = await llm.tokenize(finalPrompt)
|
| 126 |
console.log("initializing the generator (may take 30s or more)")
|
| 127 |
const generator = await llm.generate(inputTokens)
|
| 128 |
+
console.log("generator initialized, beginning token streaming..")
|
| 129 |
for await (const token of generator) {
|
| 130 |
if (!pending.queue.includes(id)) {
|
| 131 |
break
|
|
|
|
| 135 |
res.write(tmp)
|
| 136 |
}
|
| 137 |
|
| 138 |
+
endRequest(id, `normal end of the LLM stream for request ${id}`)
|
| 139 |
} catch (e) {
|
| 140 |
+
endRequest(id, `premature end of the LLM stream for request ${id} (${e})`)
|
| 141 |
}
|
| 142 |
|
| 143 |
try {
|