Skip to content

Commit 429c7bb

Browse files
committed
Update blog post
1 parent 41b99c1 commit 429c7bb

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

docs/blog/announcing-aiscript.md

+46-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,55 @@
11
# Announcing AIScript and How I Built It
22

3+
![](/aiscript-social-image.png)
4+
35
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.
46

57
## What is AIScript?
68

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+
$ export OPENAI_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.
853

954
## How I Built AIScript
1055

@@ -18,8 +63,6 @@ Since many concepts in Crafting Interpreters are derived from the Lua interprete
1863

1964
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.
2065

21-
![](/blog/claude-project.png)
22-
2366
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!
2467

2568
## Final Thoughts

0 commit comments

Comments
 (0)