LLama for nodejs

2023-03-23 10:03:46 +08:00
 hlhr202

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 写的不好,各位看官轻喷。

1582 次点击
所在节点    Node.js
1 条回复
tool2d
2023-03-23 10:14:01 +08:00
IT 行业有头部通吃原则。

习惯了 OpenGPT 后,别的 Ai 回答都像刚毕业的小学生,用了几次后,实在没有兴趣继续使用了。

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

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

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

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

© 2021 V2EX