js agent
v0.0.24
警告
JS代理是一个早期的图书馆,可以测试想法,并且不再积极发展。查看Modelfusion-更一般的AI库,用于打字稿,将我从JS代理商那里纳入我的学习。
JS代理是一种可组合且可扩展的框架,用于使用JavaScript和打字稿创建AI代理。
虽然创建代理原型很容易,但提高其可靠性和鲁棒性很复杂,需要进行相当大的实验。 JS代理提供强大的构建块和工具,以帮助您更快地开发岩石固体。
教程
可以访问Wikipedia搜索引擎并可以阅读Wikipedia文章的代理商。您可以使用它来回答有关Wikipedia内容的问题。
使用的功能: gpt-3.5-turbo
,自定义工具(搜索Wikipedia,阅读Wikipedia文章),生成下一步循环,最大步骤运行控制器
在Docker容器中工作的自动开发器代理。它可以读取文件,写文件并执行命令。您可以对项目进行调整,并使用它来记录代码,编写测试,更新测试和功能等。
使用的功能: gpt-4
,Docker容器中的工具执行,具有固定设置步骤的代理,多个代理运行属性,生成下一步循环,工具(读取文件,写文件,运行,命令,命令,询问用户),代理运行后的费用计算
JS代理商实施Babyagi。
使用的功能:HTTP代理服务器,文本完成模型( text-davinci-003
),自定义控制台输出,更新任务计划循环
采用PDF和一个主题,并创建一个与主题相关的PDF所有内容的Twitter线程。
所使用的功能:功能组成(无代理),PDF加载,分裂提取 - 螺丝
将文本分成块并生成嵌入。
使用的功能:直接函数调用(无代理),拆分文本(GPT3-Tokenizer),生成嵌入
text-davinci-003
等)gpt-4
, gpt-3.5-turbo
)text-embedding-ada-002
)Step
和AgentRun
)。npm install js-agent
请参阅示例和文档,以了解如何创建代理。
import * as $ from "js-agent" ;
const openai = $ . provider . openai ;
export async function runWikipediaAgent ( {
wikipediaSearchKey ,
wikipediaSearchCx ,
openAiApiKey ,
task ,
} : {
openAiApiKey : string ;
wikipediaSearchKey : string ;
wikipediaSearchCx : string ;
task : string ;
} ) {
const searchWikipediaAction = $ . tool . programmableGoogleSearchEngineAction ( {
id : "search-wikipedia" ,
description :
"Search wikipedia using a search term. Returns a list of pages." ,
execute : $ . tool . executeProgrammableGoogleSearchEngineAction ( {
key : wikipediaSearchKey ,
cx : wikipediaSearchCx ,
} ) ,
} ) ;
const readWikipediaArticleAction = $ . tool . extractInformationFromWebpage ( {
id : "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}" ,
} ,
execute : $ . tool . executeExtractInformationFromWebpage ( {
extract : $ . text . extractRecursively . asExtractFunction ( {
split : $ . text . splitRecursivelyAtToken . asSplitFunction ( {
tokenizer : openai . tokenizer . forModel ( {
model : "gpt-3.5-turbo" ,
} ) ,
maxChunkSize : 2048 , // needs to fit into a gpt-3.5-turbo prompt and leave room for the answer
} ) ,
extract : $ . text . generateText . asFunction ( {
prompt : $ . prompt . extractChatPrompt ( ) ,
model : openai . chatModel ( {
apiKey : openAiApiKey ,
model : "gpt-3.5-turbo" ,
} ) ,
} ) ,
} ) ,
} ) ,
} ) ;
return $ . runAgent < { task : string } > ( {
properties : { task } ,
agent : $ . step . generateNextStepLoop ( {
actions : [ searchWikipediaAction , readWikipediaArticleAction ] ,
actionFormat : $ . action . format . flexibleJson ( ) ,
prompt : $ . prompt . concatChatPrompts (
async ( { runState : { task } } ) => [
{
role : "system" ,
content : `## ROLE
You are an knowledge worker that answers questions using Wikipedia content. You speak perfect JSON.
## CONSTRAINTS
All facts for your answer must be from Wikipedia articles that you have read.
## TASK
${ task } ` ,
} ,
] ,
$ . prompt . availableActionsChatPrompt ( ) ,
$ . prompt . recentStepsChatPrompt ( { maxSteps : 6 } )
) ,
model : openai . chatModel ( {
apiKey : openAiApiKey ,
model : "gpt-3.5-turbo" ,
} ) ,
} ) ,
controller : $ . agent . controller . maxSteps ( 20 ) ,
observer : $ . agent . observer . showRunInConsole ( { name : "Wikipedia Agent" } ) ,
} ) ;
}