Skip to content

Commit c152f51

Browse files
committed
Add why AIScript docs
1 parent 92fee0b commit c152f51

File tree

10 files changed

+349
-15
lines changed

10 files changed

+349
-15
lines changed

docs/_meta.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"activeMatch": "/guide/"
66
},
77
{
8-
"text": "Std Library",
9-
"link": "/std/overview",
10-
"activeMatch": "/std/"
11-
},
12-
{
13-
"text": "Reference",
14-
"link": "/reference/language-syntax",
15-
"activeMatch": "/reference/"
16-
}
8+
"text": "Reference",
9+
"link": "/reference/language-syntax",
10+
"activeMatch": "/reference/"
11+
},
12+
{
13+
"text": "Std Library",
14+
"link": "/std/overview",
15+
"activeMatch": "/std/"
16+
}
1717
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["introduction", "installation"]
1+
["introduction", "installation", "why-aiscript"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Installation
2+
3+
## Install via cargo
4+
5+
```
6+
$ cargo install aiscript
7+
8+
$ aiscript --version
9+
aiscript 0.1.0
10+
```
11+
12+
13+
## Install via shell script
14+
15+
:::warning
16+
To be done
17+
:::

docs/guide/getting-started/installation.mdx

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Introduction
2+
3+
AIScript is a combination of interpreter programming language and web framework both written in Rust dedicated to help people build AI applications effortlessly. The language syntax learn from Python, JavaScript and Rust, combine its good parts and designed to be easy to learn and use.
4+
5+
:::warning
6+
`AIScript` is in early development, please do not use it in production yet.
7+
:::
8+
9+
## Programming Language
10+
11+
As a programming language, AIScript write it interpreter from scratch.
12+
13+
- Function is the first class citizen and object oriented programming paradigm
14+
- Builtin AI primitive, including prompt, ai function, and agent
15+
- Dynamic typing with limited static type checking
16+
- Buitlin data validation like Python's [Pydantic](https://docs.pydantic.dev/latest/)
17+
- Simple and elegant error handling, inspired from Rust, Golang and Zig
18+
- Rich standard library backed by Rust's standard library and ecosystems underneath
19+
- Garbage collection
20+
21+
## Web Framework
22+
23+
- Elegant and intuitive route DSL
24+
- Auto params validation
25+
- Auto generate OpenAPI schema and docs
26+
- Backed by Rust's best practices, use [axum](https://github.com/tokio-rs/axum) and [sqlx](https://github.com/launchbadge/sqlx) underneath,
27+
- Rust's axum performance but with Python's flask-like syntax
28+
- Buitlin database modules ([`std.db.pg`](/std/db/pg) and [`std.db.redis`](/std/db/redis))
29+
- Buitlin auth and social login
30+
- Battery-included features with simple configuration to enable them
31+
32+
## How AIScript works
33+
34+
```javascript
35+
$ export OPENAI_API_KEY=<your-openai-api-key>
36+
37+
$ cat web.ai
38+
get / {
39+
"""A api to ask LLM"""
40+
41+
query {
42+
"""the question to ask"""
43+
@string(min_len=3, max_len=100) // validate params with builtin directive @string
44+
question: str
45+
}
46+
47+
// `ai` and `prompt` are keywords
48+
ai fn ask(question: str) -> str {
49+
let answer = prompt question;
50+
return answer;
51+
}
52+
53+
// use query.name or query["name"] to access query parameter
54+
let answer = ask(query.question);
55+
return { answer };
56+
}
57+
58+
$ aiscript serve web.ai
59+
Listening on http://localhost:8000
60+
61+
$ curl http://localhost:8000
62+
{
63+
"error": "Missing required field: question"
64+
}
65+
66+
$ curl http://localhost:8000?question=Hi
67+
{
68+
"error": "Field validation failed: question: String length is less than the minimum length of 3"
69+
}
70+
71+
$ curl http://localhost:8000?question=What is the capital of France?
72+
{
73+
"answer": "The capital of France is Paris."
74+
}
75+
```
76+
77+
You can open [http://localhost:8080/redoc](http://localhost:8080/redoc) to see the API docs.
78+
79+
![](/guide/open-api.png)

docs/guide/getting-started/introduction.mdx

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
import { Tab, Tabs } from "rspress/theme";
2+
3+
# Why AIScript
4+
5+
AIScript is my experimental project to explore a new way to build web application in AI era. It isn't an oh-another-language built by a guy who just want to learn how to write an interpreter. My ambient is bigger than that.
6+
7+
Not matter what language you use to build web API, you need a web framework. These web framework essentially does the same thing. They all parse HTTP requests, execute SQL queries, and response the result with JSON or render HTML templates. Some framework can do more, validating request params, generate OpenAPI spec, etc. However, different framworks from different languages have totally different develope experience to build an web app. When you switch from one to another, you can't escape to learn the syntax and docs again. That why I want to adopt an brand-new intuitive apporach combine language with web framework to bring the modern experience to build web apps.
8+
9+
## Intuitive first
10+
11+
What I want is write a code like this to run a web API with single command, no need to learn a new web framework, no need to struggle choose which framework to use, no need to install the dependencies to run. Just run `aiscript serve`.
12+
13+
<Tabs>
14+
<Tab label="route.ai">
15+
```javascript
16+
get /guess {
17+
18+
query {
19+
@number(min=0, max=100)
20+
value: int
21+
}
22+
23+
let message = "You got it!" if query.value == 42 else "Try again";
24+
return { message };
25+
}
26+
```
27+
</Tab>
28+
<Tab label="run">
29+
```bash
30+
$ aiscript serve route.ai
31+
Listening on http://localhost:8080
32+
```
33+
</Tab>
34+
<Tab label="curl">
35+
```bash
36+
$ curl -X GET http://localhost:8080/guess?n=10
37+
{"message": "Try again"}
38+
39+
$ curl -X GET http://localhost:8080/guess?n=42
40+
{"message": "You got it!"}
41+
42+
$ curl -X GET http://localhost:8080/guess?n=999
43+
{"error": "Field validation failed: value: Number is greater than the maximum value of 100."}
44+
```
45+
</Tab>
46+
</Tabs>
47+
48+
Here are just a small poart of cool ideas come to my brain. I always seek for it if someone already built it. But I cannot find one, so I decided to build one.
49+
50+
## Out-of-box first
51+
52+
When build a web app, almost the rest besides the core business logic is the same. How can I support JWT authentication? How to integrate Google or GitHub login? How to query database or validate data? For those reraly changed standard, I wish it built into the language or framework, give me an out-of-box experience.
53+
54+
<Tabs>
55+
<Tab label="jwt_auth.ai">
56+
```rust
57+
@auth // JWT auth
58+
post /chat {
59+
query {
60+
@string(min_len=5, max_len=200)
61+
message: str
62+
}
63+
64+
use std.db.pg;
65+
let message = pg.query("INSERT INTO messages (message) VALUES ($1)", query.message);
66+
return message;
67+
}
68+
```
69+
</Tab>
70+
<Tab label="google_login.ai">
71+
```javascript
72+
@sso(provider="google")
73+
get /auth/google {
74+
let url = sso.authority_url();
75+
print(url);
76+
return temporary_redirect(target=url);
77+
}
78+
79+
@sso(provider="google")
80+
get /auth/google/callback {
81+
query {
82+
code: str,
83+
state: str,
84+
}
85+
86+
print("code", query.code);
87+
print("state", query.state);
88+
let user_info = sso.verify(code=query.code);
89+
print(user_info);
90+
return { user_info };
91+
}
92+
```
93+
</Tab>
94+
<Tab label="validation.ai">
95+
```javascript
96+
class User {
97+
@string(min_len=3, max=20)
98+
name: str,
99+
@number(min=18, strict_int=true, strict_float=true)
100+
age: int,
101+
@in(["male", "female"])
102+
gender: str = "male",
103+
}
104+
let u1 = User("Le", 20, "male") |err| {
105+
print("Validate error:", err);
106+
};
107+
// Validate error: {
108+
// loc: [name], input: Le, type: validation_error,
109+
// msg: String length is less than the minimum length of 3
110+
// }
111+
let u2 = User("Lee", 17, "male") |err| {
112+
print("Validate error:", err);
113+
};
114+
// Validate error: {
115+
// loc: [age], input: 17, type: validation_error,
116+
// msg: Number is less than the minimum value of 18
117+
// }
118+
let u3 = User("Lee", 20, "boy") |err| {
119+
print("Validate error:", err);
120+
};
121+
// Validate error: {
122+
// loc: [gender], input: boy, type: validation_error,
123+
// msg: Value is not in the list of allowed values
124+
// }
125+
let u4 = User("Lee") |err| {
126+
print("Validate error:", err);
127+
};
128+
// Validate error: {
129+
// loc: [age], input: nil, type: missing,
130+
// msg: Field required
131+
// }
132+
```
133+
</Tab>
134+
<Tab label="project.toml">
135+
```toml
136+
[auth.jwt]
137+
secret = "$JWT_SECRET"
138+
expiration = 3600
139+
140+
[sso.google]
141+
client_id = "your_google_client_id"
142+
client_secret = "your_google_client_secret"
143+
redirect_url = "http://localhost:8080/auth/google/callback"
144+
scopes = ["email"]
145+
```
146+
</Tab>
147+
</Tabs>
148+
149+
## AI first
150+
151+
People we'll ask:
152+
153+
:::info
154+
"Do we really need a new programming language in the age AI can write code for us?".
155+
:::
156+
157+
In my own opionion, I think yes, at least for web application.
158+
159+
In the one hand, most of mainstream language designed two-decades ago, `prompt`, `agent` isn't a primitive features in the language, it is in AIScript. Your don't need to install a package to call LLM API or orchestrate multiple agents.
160+
161+
<Tabs>
162+
<Tab label="prompt.ai">
163+
```rust
164+
let answer = prompt "Why the sky is blue?" => {
165+
model: "claude-3.7",
166+
temperature: 0.8,
167+
};
168+
print(answer);
169+
```
170+
</Tab>
171+
<Tab label="agent.ai">
172+
```python
173+
agent WeatherAgent {
174+
instructions: "Providing a weather forecast at the locations the user provides.",
175+
model: "gpt-4o",
176+
177+
fn get_forecast(location: str, forecast_date: date) -> str {
178+
"""
179+
Call this tools to forecast weather based on `location` and `forecast_date`.
180+
"""
181+
// In real code: call weather API, DB queries, etc.
182+
return f'The forecast in {location} on {forecast_date} is 24°C and sunny.';
183+
}
184+
}
185+
186+
let user_prompt = "What will the weather be like in Paris on Tuesday?";
187+
WeatherAgent.run(input=user_prompt);
188+
```
189+
</Tab>
190+
<Tab label="project.toml">
191+
```toml
192+
[ai.embedding]
193+
model = "gpt-3.5-turbo"
194+
195+
[ai.openai]
196+
api_key = "YOUR_API_KEY"
197+
198+
[ai.anthropic]
199+
api_key = "YOUR_API_KEY"
200+
```
201+
</Tab>
202+
</Tabs>
203+
204+
In the other hands, many features is out-of-box and batter-included in the standard library. It's helpful for AI code generation.
205+
206+
:::info Thought on AI code generation era
207+
208+
#### Building web app is not that easy
209+
210+
- Solid coding experience is required, from programming languages to web frameworks and libraries. You need a lot of hands-on experience to build software with confidence.
211+
212+
- Even though AI code generation is pretty helpful, you still need expertise in coding if you're not going to build a toy project.
213+
214+
- Finishing the code is just the beginning; deploying, observability, security, there are a bunch of things waiting for you. AI is not that helpful for these right now.
215+
216+
#### Code Generation: Just the Tip of the Iceberg
217+
218+
- For any serious piece of software that makes it to production, 80% or more of the cost is in the phase after initial development. That's the phase called Day-2 operations.
219+
220+
- Day-2 operations present the biggest challenges.
221+
222+
- Can Cursor and WindSurf solve the deployment problem, make the whole Day-2 easy and effortless? No, I don't think so, neither can Devin.
223+
224+
:::
225+
226+
227+
## Best practice first
228+
229+
I hope I don't need to learn serveral methods to compare and figure out which one is the best practice. What I hope I only need one solution which is the best practice, free myself from such a choose struggeling.
230+
231+
AIScript choose Rust's best practice of web developement, and encapsulate those best practices into the language and framework.
232+

docs/public/aiscript-logo-white.svg

Lines changed: 10 additions & 0 deletions
Loading

docs/public/guide/open-api.png

143 KB
Loading

rspress.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default defineConfig({
88
icon: '/toucan.png',
99
logo: {
1010
light: '/aiscript-logo.svg',
11-
dark: '/aiscript-logo.svg',
11+
dark: '/aiscript-logo-white.svg',
1212
},
1313
route: {
1414
cleanUrls: true,

0 commit comments

Comments
 (0)