分享一下我过去几个月和 Claude 一起合作用 Rust 开发的新一代编程语言 AIScript!

176 天前
 Wichna

我过去几个月在和 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 };
}

官网: https://aiscript.dev

GitHub: https://github.com/aiscriptdev/aiscript

2828 次点击
所在节点    分享创造
7 条回复
feelinglucky
176 天前
沙发留给我了~
travelcc
176 天前
感觉有点强
Dreamerwwr
176 天前
wuhaoworld
176 天前
牛逼,虽然可能短时间没啥实际应用价值,但还是很有意思,有那种 just for fun 的极客范儿
ZoeLee0904
176 天前
你就是 MVP
Wichna
176 天前
@wuhaoworld 哈哈哈谢谢,当它足够成熟了就慢慢有价值了,朝未来看
god
175 天前
可以扩展成新的 langchain alternative 概念了。来自 Elixir 群友的祝福。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1117270

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX