我过去几个月在和 Claude 合作使用 Rust 开发了一门新语言 AIScript,现在正式开源。这门语言最大的特点是内置 AI 特性以及把语言和 Web 框架合二为一。
在 AIScript 里 prompt/ai/agent 都是关键字,使用 prompt "text"
就可以跟 AI 交互,任何使用了 prompt
的函数都需要显示声明是 ai
函数。定义一个 agent
跟定义一个 class
一样简单,支持类似 OpenAI Swarm 那种多 agent 编排。
只需要使用简单明了的 DSL 就可以写 web 接口,并且自动生成 OpenAPI docs ,JWT 或者 Google 社交账号登录用一个 @auth
或 @sso
指令即可。
$ export OPENAI_API_KEY=<your-openai-api-key>
$ cat web.ai
get / {
"""An api to ask LLM"""
query {
"""the question to ask"""
@string(min_len=3, max_len=100) // validate params with builtin directive @string
question: str
}
// `ai` and `prompt` are keywords
ai fn ask(question: str) -> str {
let answer = prompt question;
return answer;
}
// use query.name or query["name"] to access query parameter
let answer = ask(query.question);
return { answer };
}
$ aiscript serve web.ai
Listening on http://localhost:8080
$ curl http://localhost:8080
{
"error": "Missing required field: question"
}
$ curl http://localhost:8080?question=Hi
{
"error": "Field validation failed: question: String length is less than the minimum length of 3"
}
$ curl http://localhost:8080?question=What is the capital of France?
{
"answer": "The capital of France is Paris."
}
agent Researcher {
instructions: "You are a research assistant...",
fn search_web(query: str) -> str {
"""
Search the web for information about a topic.
"""
// Implementation
return "search results";
}
fn save_notes(content: str) -> bool {
"""
Save notes about a topic.
"""
// Implementation
return true;
}
}
@sso(provider="google")
get /auth/google {
let url = sso.authority_url();
print(url);
return temporary_redirect(target=url);
}
@sso(provider="google")
get /auth/google/callback {
query {
code: str,
state: str,
}
print("code", query.code);
print("state", query.state);
let user_info = sso.verify(code=query.code);
print(user_info);
return { user_info };
}
![]() |
1
feelinglucky 1 天前
沙发留给我了~
|
2
travelcc 1 天前
感觉有点强
|
![]() |
3
Dreamerwwr 1 天前
强
|
![]() |
4
wuhaoworld 1 天前
牛逼,虽然可能短时间没啥实际应用价值,但还是很有意思,有那种 just for fun 的极客范儿
|
5
ZoeLee0904 1 天前
你就是 MVP
|
![]() |
6
Wichna OP @wuhaoworld 哈哈哈谢谢,当它足够成熟了就慢慢有价值了,朝未来看
|
![]() |
7
god 18 小时 15 分钟前
可以扩展成新的 langchain alternative 概念了。来自 Elixir 群友的祝福。
|