Agentica框架让TypeScript开发者无需学习新概念,直接将类转化为AI聊天机器人,大幅降低Agent开发门槛。
创建 TypeScript 类,并将它们转换为 AI 聊天机器人。
从现在开始,每个 TypeScript 开发者都可以成为 AI 开发者。
TypeScript 开发者们,让我们通过 @agentica 成为 AI 开发者吧。
Github Repository: https://github.com/wrtnlabs/agentica
Guide Documents: https://wrtnlabs.io/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 agent 可以通过分析学术论文和新闻文章来编写 Notion 文档。当你要求 agent 分析最近的韩国经济趋势、对其进行评论、整理相关论文并在 Notion 中编写时,AI agent 将执行这些任务。
只需定义你的 TypeScript 类,你就可以创建任何你想要的 AI agent。
https://wrtnlabs.io/agentica/tutorial/coding/file-system/
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。
https://wrtnlabs.io/agentica/tutorial/enterprise/shopping/
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");
如果你不熟悉 AI,你可能想知道 @agentica 如何能通过函数完成所有事情。
或者,如果你是 AI agent 开发的专家,你可能有不同的问题。传统 agent 开发围绕 agent 工作流图进行,那么 @agentica 如何利用 LLM 函数调用来实现类似的能力?
访问我们的框架主页或阅读之前的文章,以了解 @agentica 的关键原理。在这些资源中,你将学到新的 AI 开发范式:"编译器驱动开发"和"文档驱动开发"。
Github Repository: https://github.com/wrtnlabs/agentica
Guide Documents: https://wrtnlabs.io/agentica
https://dev.to/samchon/every-backend-developer-is-a-great-ai-developer-338m
考虑到后端开发者所做工作的性质,他们实际上比传统 AI/ML 工程师更适合 AI agent 开发。
让我们将 swagger.json 文件交给 @agentica,这样就能创建一个在对话过程中执行 API 函数的 AI 聊天机器人。