阿川私房教材:
學 JavaScript 前端,帶作品集去面試!

63 個專案實戰,寫出作品集,讓面試官眼前一亮!

立即開始免費試讀!
  1. 前言

{% youtube pdsplQyok8k %}

建立 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("I want to write an article.");
  1. Agentica 框架

@agentica是一個專門用於 LLM 函數呼叫的框架。

您可以透過 TypeScript 類別類型提供函數。如果您建立下面的FileSystem類別並將其與@agentica集成,它將成為檔案系統聊天機器人。您可以透過聊天機器人中的對話文字來管理您的檔案系統。

如果您同時提供多個 TypeScript 類別(例如GoogleScholarServiceNaverNewsServiceNotionService ),您的 AI 代理程式可以透過分析學術論文和新聞文章來撰寫 Notion 文件。當你要求代理人分析近期韓國經濟趨勢、對其進行評論、整理相關論文、並將其寫在Notion中時,AI代理就會執行這些任務。

只需定義您的 TypeScript 類,您就可以建立任何您想要的 AI 代理程式。

import fs from "fs";

export class FileSystem {
  public __dirname(): string {
    return __dirname;
  }

  public readdir(input: {
    path: string;
    options?:
      | {
          encoding: "utf-8";
          withFileTypes?: false | undefined;
          recursive?: boolean | undefined;
        }
      | "utf-8"
      | null;
  }): Promise<string[]> {
    return fs.promises.readdir(input.path, input.options);
  }

  public readFile(input: { path: string }): Promise<string> {
    return fs.promises.readFile(input.path, "utf8");
  }

  public writeFileSync(input: { 
    file: string; 
    data: string;
  }): Promise<void> {
    return fs.promises.writeFile(input.file, input.data);
  }
}

3.企業示範

有人可能會疑惑: BbsArticleServiceFileSystem類別不是只有幾個功能嗎?這僅僅是一個在有限的場景中發揮良好作用的玩具專案嗎?是否可以使用@agentica建立企業級聊天機器人?

答案是肯定的,建立企業級聊天機器人確實是可能的。

這是企業級購物中心聊天機器人,包含289個API函數。它支援標準電子商務平台的大多數功能,並且正如所演示的,它執行起來沒有問題。

作為參考, @agentica也可以從 Swagger/OpenAPI 文件中取得功能。下面的演示源自@samchon/shopping-backend

{% youtube RAzYo02HTXA %}

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(),
    },
  ],
});
await agent.conversate("I want to buy a MacBook Pro");
  1. 原則

{% youtube 4kohpDkhV5w %}

如果你不熟悉AI,你可能會想知道@agentica如何透過函數完成一切。

或者,如果您是 AI 代理開發的專家,您可能會有不同的問題。傳統的代理開發圍繞著代理工作流程圖展開,那麼@agentica如何利用LLM函數呼叫來實現類似的功能?

請造訪我們的框架主頁或閱讀我之前的文章以了解@agentica的關鍵原則。在這些資源中,您將了解新的AI開發範式:「編譯器驅動開發」和「文件驅動開發」。

  1. 下一篇文章

https://dev.to/samchon/every-backend-developer-is-a-great-ai-developer-338m

每個後端開發人員也是 AI 開發人員。

考慮到後端開發人員的工作性質,他們實際上比傳統的 AI/ML 工程師更適合進行 AI 代理開發。

我們將swagger.json檔案帶到@agentica ,以便讓 AI 聊天機器人在對話期間執行 API 函數。


原文出處:https://dev.to/samchon/every-typescript-developer-is-an-ai-developer-2kan


共有 0 則留言


精選技術文章翻譯,幫助開發者持續吸收新知。

阿川私房教材:
學 JavaScript 前端,帶作品集去面試!

63 個專案實戰,寫出作品集,讓面試官眼前一亮!

立即開始免費試讀!