คำเตือน
JS Agent เป็นห้องสมุดแรก ๆ เพื่อทดสอบความคิดและไม่ได้พัฒนาอย่างแข็งขันอีกต่อไป ตรวจสอบ Modelfusion - ไลบรารี AI ทั่วไปสำหรับ TypeScript ที่รวมการเรียนรู้ของฉันจาก JS Agent
JS Agent เป็นเฟรมเวิร์กแบบคอมโพสิตและขยายได้สำหรับการสร้างตัวแทน AI ด้วย JavaScript และ TypeScript
ในขณะที่การสร้างต้นแบบของเอเจนต์นั้นง่ายการเพิ่มความน่าเชื่อถือและความทนทานนั้นซับซ้อนและต้องมีการทดลองอย่างมาก JS Agent ให้การสร้างบล็อกและเครื่องมือที่มีประสิทธิภาพเพื่อช่วยให้คุณพัฒนาตัวแทนที่เป็นของแข็งได้เร็วขึ้น
การสอน
ตัวแทนที่สามารถเข้าถึงเครื่องมือค้นหา Wikipedia และสามารถอ่านบทความ Wikipedia คุณสามารถใช้เพื่อตอบคำถามเกี่ยวกับเนื้อหา Wikipedia
คุณสมบัติที่ใช้: gpt-3.5-turbo
, เครื่องมือที่กำหนดเอง (ค้นหา Wikipedia, อ่านบทความ Wikipedia), สร้างลูปขั้นตอนต่อไป, ขั้นตอนสูงสุด Run Controller
ตัวแทนนักพัฒนาซอฟต์แวร์อัตโนมัติที่ทำงานในคอนเทนเนอร์ Docker สามารถอ่านไฟล์เขียนไฟล์และเรียกใช้คำสั่ง คุณสามารถปรับสำหรับโครงการของคุณและใช้เป็นเอกสารเอกสารการทดสอบเขียนการทดสอบอัพเดตและคุณสมบัติ ฯลฯ
คุณสมบัติที่ใช้: gpt-4
, การดำเนินการเครื่องมือในคอนเทนเนอร์ Docker, ตัวแทนที่มีขั้นตอนการตั้งค่าคงที่, คุณสมบัติการเรียกใช้เอเจนต์หลายตัว, สร้างลูปขั้นตอนต่อไป, เครื่องมือ (ไฟล์อ่าน, ไฟล์เขียน, รัน, คำสั่ง, ถามผู้ใช้), การคำนวณต้นทุนหลังจากเอเจนต์รัน
การใช้งานตัวแทน JS ของ Babyagi
คุณสมบัติที่ใช้: HTTP Agent Server, โมเดลการทำข้อความเสร็จสมบูรณ์ ( text-davinci-003
), เอาต์พุตคอนโซลที่กำหนดเอง, การอัปเดตงานลูปการวางแผน
ใช้ PDF และหัวข้อและสร้างเธรด Twitter พร้อมเนื้อหาทั้งหมดจาก PDF ที่เกี่ยวข้องกับหัวข้อ
คุณสมบัติที่ใช้: องค์ประกอบของฟังก์ชั่น (ไม่มีเอเจนต์), การโหลด PDF
แยกข้อความออกเป็นชิ้นและสร้างการฝังตัว
คุณสมบัติที่ใช้: การเรียกฟังก์ชันโดยตรง (ไม่มีเอเจนต์), ข้อความแยก (GPT3-tokenizer), สร้าง EMBEDDING
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" } ) ,
} ) ;
}