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" } ) ,
} ) ;
}