Skip to content

Commit cc86fa2

Browse files
[website] add tutorial on generating websites
1 parent ffa2908 commit cc86fa2

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

website/learn/code/websites.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
sidebar_position: 6
3+
---
4+
5+
# Generating Websites
6+
7+
To generate websites and other multi-file applications, we will first prompt the LLM to split the code into multiple files and then make use of `h9.save()` to store multiple files.
8+
9+
## LLMs with Files
10+
11+
Most LLM generate code blocks by default, not files. We can change this behavior using a system prompt to request the LLM to generate code files, defined as code blocks with an additional file name.
12+
13+
````
14+
Your replies can include markdown code blocks but they must include a
15+
filename parameter after the language. For example,
16+
17+
```javascript filename=code.js
18+
```
19+
20+
The main html file must ne named index.html. You can generate other web files
21+
like javascript, css, svg that are referenced from index.html
22+
````
23+
24+
## Storing Files
25+
26+
YOu can make use of `h9.extract()` to extract the file blocks generated by the LLM, followed by `h9.save()` with the dictionary of text file names to content to store.
27+
28+
````py
29+
import hal9 as h9
30+
import openai
31+
import os
32+
33+
files = h9.extract("""
34+
```javascript filename=code.js
35+
function go() {
36+
document.getElementById('msg').innerText = Math.random();
37+
}
38+
```
39+
40+
```html filename=index.html
41+
<html>
42+
<head>
43+
<script src="code.js"></script>
44+
</head>
45+
<body>
46+
<button onclick="go()">Go!</button><div id="msg"></div>
47+
</body>
48+
</html>
49+
```
50+
""", default={})
51+
52+
h9.save("index.html", files=files)
53+
````

0 commit comments

Comments
 (0)