You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/blog/announcing-aiscript.md
+46-3
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,55 @@
1
1
# Announcing AIScript and How I Built It
2
2
3
+

4
+
3
5
I'm excited to share **AIScript**, a new programming language I've been developing over the past few months. AIScript is designed specifically for web development in the AI era, with AI capabilities as first-class language features, and an intuitive route DSL and directive design. In my [Why AIScript](/blog/why-aiscript) post, I shared why I developed this new language; this post focuses on what AIScript is and how I developed it.
4
6
5
7
## What is AIScript?
6
8
7
-
AIScript is a unique combination of an interpreted programming language and web framework, both written in Rust, designed to help developers build AI applications effortlessly. The language syntax draws inspiration from Python, JavaScript, and Rust, combining their strengths to create something that's intuitive, powerful, and easy to use. The [Introduction](/guide/getting-started/introduction) page provides more details about AIScript.
9
+
AIScript is a unique combination of an interpreted programming language and web framework, both written in Rust, designed to help developers build AI applications effortlessly. The language syntax draws inspiration from Python, JavaScript, and Rust, combining their strengths to create something that's intuitive, powerful, and easy to use.
10
+
11
+
```js
12
+
$ exportOPENAI_API_KEY=<your-openai-api-key>
13
+
$ cat web.ai
14
+
get / {
15
+
"""An api to ask LLM"""
16
+
17
+
query {
18
+
"""the question to ask"""
19
+
@string(min_len=3, max_len=100) // validate params with builtin directive @string
20
+
question: str
21
+
}
22
+
23
+
// `ai` and `prompt` are keywords
24
+
ai fn ask(question: str) -> str {
25
+
let answer = prompt question;
26
+
return answer;
27
+
}
28
+
// use query.name or query["name"] to access query parameter
29
+
let answer =ask(query.question);
30
+
return { answer };
31
+
}
32
+
33
+
$ aiscript serve web.ai
34
+
Listening on http://localhost:8080
35
+
36
+
$ curl http://localhost:8080
37
+
{
38
+
"error":"Missing required field: question"
39
+
}
40
+
41
+
$ curl http://localhost:8080?question=Hi
42
+
{
43
+
"error":"Field validation failed: question: String length is less than the minimum length of 3"
44
+
}
45
+
46
+
$ curl http://localhost:8080?question=What is the capital of France?
47
+
{
48
+
"answer":"The capital of France is Paris."
49
+
}
50
+
```
51
+
52
+
The [Introduction](/guide/getting-started/introduction) page provides more details about AIScript.
8
53
9
54
## How I Built AIScript
10
55
@@ -18,8 +63,6 @@ Since many concepts in Crafting Interpreters are derived from the Lua interprete
18
63
19
64
I then began writing AIScript from scratch, basing some code on my Lox implementation and using gc-arena for garbage collection. However, I soon realized that Crafting Interpreters' single-pass architecture, while offering good performance for parsing and compilation, made static type checking and advanced optimization difficult. To address this, I collaborated with Claude to help me [migrate from a single-pass to a two-pass architecture](https://github.com/aiscriptdev/aiscript/pull/1). Through this process, I discovered that Claude excels at writing interpreters, which led me to instruct Claude to help implement the remaining components of the AIScript interpreter.
20
65
21
-

22
-
23
66
I've had a fantastic collaboration with Claude in implementing the AIScript interpreter. Not only did Claude help me write boilerplate code, but it also served as an exceptional interpreter teacher. When I was uncertain about the best implementation method, I would ask how CPython, Ruby, or other languages implement similar features, and Claude would provide detailed explanations that helped me make informed decisions. Without Claude's assistance, I definitely would have struggled to complete the first version of AIScript in just four months!
0 commit comments