作为JavaScript开发人员,拥有有效的工具和框架是至关重要的,尤其是在创建需要实验和适应性的AI代理时。这就是为什么我想介绍 GPTAgent.js ,这是一个可组合且可扩展的框架,旨在使用Typescript和JavaScript构建AI代理。
请注意,gptagent.js当前处于早期阶段(v0.0.4),并且会随着时间的推移添加更多功能和改进。
以下是我用gptagent.js实现的示例:
JavaScript/TypeScript Developer Agent
此代理在Docker容器中运行,可以读取文件,写文件和执行命令,从而可以执行各种开发任务。例如,它可以编写,运行和修复单元测试。
请查看此推文,演示GPTAGENT.JS如何编写框架本身的第一个单元测试:
¾gptagent.js写了第一个用于gptagent.js
ð§µ的单位测试。
Wikipedia Question-Answering Agent
这个AI代理可以搜索Wikipedia并阅读文章,并根据发现的信息提供答案。下面的代码片段演示了Wikipedia问答代理的配置:
import $, { ActionRegistry, Agent, runCLIAgent } from "@gptagent/agent";
const textGenerator = new $.ai.openai.Gpt4ChatTextGenerator({
apiKey: process.env.OPENAI_API_KEY,
});
const searchWikipediaAction =
new $.action.tool.ProgrammableGoogleSearchEngineAction({
type: "tool.search-wikipedia",
description:
"Search wikipedia using a search term. Returns a list of pages.",
executor: new $.action.tool.ProgrammableGoogleSearchEngineExecutor({
key: process.env.WIKIPEDIA_SEARCH_KEY,
cx: process.env.WIKIPEDIA_SEARCH_CX,
}),
});
const summarizeWebpageAction = new $.action.tool.SummarizeWebpageAction({
type: "tool.read-wikipedia-article",
description:
"Read a wikipedia article and summarize it considering the query.",
inputExample: {
url: "https://en.wikipedia.org/wiki/Artificial_intelligence",
topic: "{query that you are answering}",
},
executor: new $.action.tool.SummarizeWebpageExecutor({
webpageTextExtractor:
new $.component.webpageTextExtractor.BasicWebpageTextExtractor(),
summarizer: new $.component.textSummarizer.SingleLevelSplitSummarizer({
splitter: new $.component.splitter.RecursiveCharacterSplitter({
maxCharactersByChunk: 4096 * 4,
}),
summarizer: new $.component.textSummarizer.ChatTextSummarizer({
chatTextGenerator: textGenerator,
}),
}),
}),
});
runCLIAgent({
agent: new Agent({
name: "Wikipedia QA",
rootStep: new $.step.DynamicCompositeStep({
nextStepGenerator: new $.step.BasicNextStepGenerator({
role: `You are an knowledge worker that answers questions using Wikipedia content.`,
constraints: `Make sure all facts for your answer are from Wikipedia articles that you have read.`,
actionRegistry: new ActionRegistry({
actions: [searchWikipediaAction, summarizeWebpageAction],
format: new $.action.format.JsonActionFormat(),
}),
textGenerator,
}),
}),
}),
});
给予 GPTAgent.js 尝试与开发人员社区分享您的经验。您的反馈对于持续改进框架至关重要。不要忘记遵循gptagent.js项目以获取更新和新闻。愉快的编码!