亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

每個 TypeScript 開發者都可以成為 AI 開發者

1. 序言

创建 TypeScript 类,然后将这些类转换成 AI 聊天机器人。

从现在起,每位 TypeScript 开发者都能成为 AI 开发者了。

TypeScript 同志们,让我们用 @agentica 一起成为 AI 开发者。

    import { Agentica } from "@agentica/core";
    import OpenAI from "openai";
    import typia from "typia";

    const agent = new Agentica({
      vendor: {
        model: "gpt-4o-mini",
        api: new OpenAI({ apiKey: "********" }),
      },
      controllers: [
        {
          protocol: "class",
          application: typia.llm.application<BbsArticleService, "chatgpt">(),
          execute: new BbsArticleService(),
        },
      ],
    });
    await agent.conversate("我想写一篇文章,你有什么建议吗?"); // 等待代理开始对话

进入全屏 退出全屏

2. Agentica 架构.

@agentica 是专门用于大型语言模型函数调用的框架。

你可以通过 TypeScript 类型定义来提供功能。如果你创建了如下 FileSystem 类,并将其与@agentica集成,它就会成为一个可以管理文件系统的聊天机器人。你可以通过与聊天机器人的对话来管理你的文件系统。

如果你同时提供了多个类似的 TypeScript 类,比如 GoogleScholarServiceNaverNewsServiceNotionService,你的 AI 代理可以分析学术论文和新闻文章,然后在 Notion 中撰写文档。当你让代理分析最近的韩国经济趋势,对其进行评论,整理相关论文,并将结果写入 Notion 中时,AI 代理会帮你完成这些任务。

只需定义你的 TypeScript 类即可,就可以创建你想要的任何 AI 代理程序。

参见https://wrtnlabs.io/agentica/tutorial/coding/file-system/

    import fs from "fs";

    export class 文件系统 {
      public __dirname(): string {
        return __dirname;
      }

      public 读取目录(input: {
        路径: string;
        选项?:
          | {
              编码: "utf-8";
              withFileTypes?: false | undefined;
              recursive?: boolean | undefined;
            }
          | "utf-8"
          | null;
      }): Promise<string[]> {
        return fs.promises.readdir(input.路径, input.选项);
      }

      public 读取文件(input: { 路径: string }): Promise<string> {
        return fs.promises.readFile(input.路径, "utf8");
      }

      public 写入文件同步(input: { 
        文件: string; 
        数据: string;
      }): Promise<void> {
        return fs.promises.writeFile(input.文件, input.数据);
      }
    }

全屏查看 / 退出全屏

3. 企业演示

有些人可能会疑惑:这些类只有少数几个功能,这只是一个在特定场景下运行良好的玩具项目吗?使用 @agentica 是否能够构建一个企业级聊天机器人?

答案是肯定的,确实可以创建企业级别的聊天机器人。

这里有一个为企业级购物商场打造的聊天机器人,具备289个API功能。它支持大多数标准电商功能,并且如展示,运行顺畅无误。

参考一下,@agentica 也可以从 Swagger 或 OpenAPI 规范文档中获取函数定义。下面的演示来自 @samchon/shopping-backend

    import { Agentica } from "@agentica/core";
    import { HttpLlm, OpenApi } from "@samchon/openapi";
    import typia from "typia";

    const agent = new Agentica({
      model: "chatgpt",
      vendor: {
        api: new OpenAI({ apiKey: "*****" }),
        model: "gpt-4o-mini",
      },
      controllers: [
        {
          protocol: "http",
          name: "shopping",
          // 购物协议应用
          application: HttpLlm.application({
            model: "chatgpt",
            document: await fetch(
              "https://shopping-be.wrtn.ai/editor/swagger.json",
            ).then((r) => r.json()),
          }),
          connection: {
            host: "https://shopping-be.wrtn.ai",
            headers: {
              Authorization: "Bearer *****",
            },
          },
        },
        {
          protocol: "class",
          name: "counselor",
          // 顾问协议应用
          application: typia.llm.application<ShoppingCounselor, "chatgpt">(),
          execute: new ShoppingCounselor(),
        },
        {
          protocol: "class",
          name: "policy",
          // 政策协议应用
          application: typia.llm.application<ShoppingPolicy, "chatgpt">(),
          execute: new ShoppingPolicy(),
        },
        {
          protocol: "class",
          name: "rag",
          // 搜索协议应用
          application: typia.llm.application<ShoppingSearchRag, "chatgpt">(),
          execute: new ShoppingSearchRag(),
        },
      ],
    });
    // 我想买一台MacBook Pro (mù kù bāo pú)
    await agent.对话("我想买一台MacBook Pro (mù kù bāo pú)");

切换全屏

4. 原则

如果你不太了解人工智能,你可能会好奇@agentica是如何利用各种函数来完成所有任务的。

或者,如果你是AI代理开发的专家,你可能会有不一样的疑问。传统的代理开发主要围绕代理的工作流程图,那么@agentica又是如何通过LLM函数调用实现类似功能的?

访问我们的框架主页,或阅读我之前的文章以了解其关键原则。在这些资源中,您将了解到新的 AI 开发范式:“编译驱动开发”和“文档驱动开发”。

5. 下一个主题

https://dev.to/samchon/every-backend-developer-is-a-great-ai-developer-338m 注:链接中的内容需要单独翻译成中文。

每个后端开发者也是AI开发者。

由于后端开发人员的工作性质,他们实际上比传统的AI/ML工程师更有优势进行AI代理的开发。

让我们将 swagger.json 文件传给 @agentica,这样在聊天时让AI聊天机器人助手运行API的功能。

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消