V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
Wichna
V2EX  ›  分享创造

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

  •  
  •   Wichna ·
    folyd · 1 天前 · 1176 次点击

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

    7 条回复    2025-03-11 18:29:41 +08:00
    feelinglucky
        1
    feelinglucky  
       1 天前
    沙发留给我了~
    travelcc
        2
    travelcc  
       1 天前
    感觉有点强
    Dreamerwwr
        3
    Dreamerwwr  
       1 天前
    wuhaoworld
        4
    wuhaoworld  
       1 天前
    牛逼,虽然可能短时间没啥实际应用价值,但还是很有意思,有那种 just for fun 的极客范儿
    ZoeLee0904
        5
    ZoeLee0904  
       1 天前
    你就是 MVP
    Wichna
        6
    Wichna  
    OP
       1 天前
    @wuhaoworld 哈哈哈谢谢,当它足够成熟了就慢慢有价值了,朝未来看
    god
        7
    god  
       18 小时 15 分钟前
    可以扩展成新的 langchain alternative 概念了。来自 Elixir 群友的祝福。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3503 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 20ms · UTC 04:45 · PVG 12:45 · LAX 21:45 · JFK 00:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.