{% youtube pdsplQyok8k %}
建立 TypeScript 類,並將其轉換為 AI 聊天機器人。
從現在開始,每個 TypeScript 開發人員都可以成為 AI 開發人員。
TypeScript 開發人員,讓我們與@agentica
一起成為 AI 開發人員。
Github 倉庫:https://github.com/wrtnlabs/agentica
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.");
@agentica
是一個專門用於 LLM 函數呼叫的框架。
您可以透過 TypeScript 類別類型提供函數。如果您建立下面的FileSystem
類別並將其與@agentica
集成,它將成為檔案系統聊天機器人。您可以透過聊天機器人中的對話文字來管理您的檔案系統。
如果您同時提供多個 TypeScript 類別(例如GoogleScholarService
、 NaverNewsService
和NotionService
),您的 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);
}
}
有人可能會疑惑: BbsArticleService
或FileSystem
類別不是只有幾個功能嗎?這僅僅是一個在有限的場景中發揮良好作用的玩具專案嗎?是否可以使用@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");
{% youtube 4kohpDkhV5w %}
如果你不熟悉AI,你可能會想知道@agentica
如何透過函數完成一切。
或者,如果您是 AI 代理開發的專家,您可能會有不同的問題。傳統的代理開發圍繞著代理工作流程圖展開,那麼@agentica
如何利用LLM函數呼叫來實現類似的功能?
請造訪我們的框架主頁或閱讀我之前的文章以了解@agentica
的關鍵原則。在這些資源中,您將了解新的AI開發範式:「編譯器驅動開發」和「文件驅動開發」。
Github 倉庫:https://github.com/wrtnlabs/agentica
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