hlhr202
V2EX  ›  Node.js

LLama for nodejs

  •  
  •   hlhr202 · Mar 23, 2023 · 2534 views
    This topic created in 1171 days ago, the information mentioned may be changed or developed.

    AIGC 这么火,小前端来蹭个热度,写了个 llama-node 的库

    https://github.com/hlhr202/llama-node

    起因是为了方便自己调用,又希望降低 llama.cpp 和 llama-rs 的调用门槛,我研究了一下 meta 开源的 llama 社区项目,最终找到了 llama-rs 这个 rust 库。

    https://github.com/setzer22/llama-rs

    对 rust 确实不太熟,还是喜欢留在 typescript 的安全区,所以决定用 llama-rs 写一个 nodejs 的库。

    node addon 方面选择了 @太狼 大佬的 napi-rs 。

    用法展示:

    import path from "path";
    import { LLamaClient } from "llama-node";
    
    const model = path.resolve(process.cwd(), "./ggml-alpaca-7b-q4.bin");
    
    const client = new LLamaClient({ path: model, numCtxTokens: 4096 }, true);
    
    const prompt = `// Show an example of counter component in react.js. it has increment and decrement buttons where they change the state by 1.
    export const Counter => {`;
    
    client.createTextCompletion(
        {
            prompt,
            numPredict: BigInt(2048),
            temp: 0.2,
            topP: 0.8,
            topK: BigInt(40),
            repeatPenalty: 1,
            repeatLastN: BigInt(512),
        },
        (res) => {
            process.stdout.write(res.token);
        }
    );
    

    结论还是:写 ai 程序也是撸 typescript 更快。。。就这样先将就用着吧。rust 写的不好,各位看官轻喷。

    1 replies    2023-03-23 10:14:01 +08:00
    tool2d
        1
    tool2d  
       Mar 23, 2023
    IT 行业有头部通吃原则。

    习惯了 OpenGPT 后,别的 Ai 回答都像刚毕业的小学生,用了几次后,实在没有兴趣继续使用了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2823 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 13:13 · PVG 21:13 · LAX 06:13 · JFK 09:13
    ♥ Do have faith in what you're doing.