V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
hlhr202
V2EX  ›  Node.js

LLama for nodejs

  •  
  •   hlhr202 · 2023-03-23 10:03:46 +08:00 · 1564 次点击
    这是一个创建于 401 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 条回复    2023-03-23 10:14:01 +08:00
    tool2d
        1
    tool2d  
       2023-03-23 10:14:01 +08:00
    IT 行业有头部通吃原则。

    习惯了 OpenGPT 后,别的 Ai 回答都像刚毕业的小学生,用了几次后,实在没有兴趣继续使用了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2736 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:45 · PVG 19:45 · LAX 04:45 · JFK 07:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.