493 - 《Umi AI》

发布于 2024年12月7日

1、之前写了 488 - 《前端 x AI》,准备给 tnf 加上 AI 的能力,但一直没着手做。直到上周看到 cali ,仿照着写了 @umijs/ai

2、@umiji/ai 是一个通用解,通过 prompt + function call + tools 的公式来解问题,tools 提供针对性问题的准确解,比如 install packages、fs 等。

3、实现方式是基于 ai npm 包的 generateText,while true 循环调,直到任务结束后退出。参考 https://github.com/umijs/ai/blob/master/src/cli.ts#L52

const openai = createOpenAI({
  apiKey: OPENAI_API_KEY,
});

const messages = [];
while (true) {
  const response = await generateText({
    model, system, tools, messages,
  });
}

4、和 cali 的区别就是提供的 prompt 和 tools 不同。@umijs/ai 提供前端相关的最佳实践。比如最佳实践部分如下。所以 @umijs/ai 可以理解为一个解前端问题的 Agent。

BEST PRACTICES:
- Use TypeScript.
- Use Prettier for formatting. Perferred config: printWidth: 80, singleQuote: true, trailingComma: all, proseWrap: never, importOrderSortSpecifiers: true, use @trivago/prettier-plugin-sort-imports to sort imports.
- Perferred style: indent_style: space, indent_width: 2.
- How to add father as component bunder.
  1. add father as dev depe

内容预览已结束

此内容需要会员权限。请先登录以查看完整内容。