تحذير
كان وكيل JS مكتبة مبكرة لاختبار الأفكار ولم يتم تطويرها بنشاط بعد الآن. تحقق من modelfusion - مكتبة منظمة العفو الدولية أكثر عمومية لـ TypeScript التي تتضمن تعلماتي من وكيل JS.
JS Agent هو إطار عمل قابل للتكنولوجيا وقابل للتمديد لإنشاء وكلاء الذكاء الاصطناعى مع JavaScript و TypeScript.
في حين أن إنشاء نموذج أولي للوكيل أمر سهل ، إلا أن زيادة موثوقيتها والمتانة معقدة وتتطلب تجربة كبيرة. يوفر JS Agent لبنات بناء قوية وأدوات لمساعدتك على تطوير وكلاء الصخور الصلبة بشكل أسرع.
درس تعليمي
وكيل لديه إمكانية الوصول إلى محرك بحث ويكيبيديا ويمكنه قراءة مقالات ويكيبيديا. يمكنك استخدامه للإجابة على أسئلة حول محتوى ويكيبيديا.
الميزات المستعملة: gpt-3.5-turbo
، أدوات مخصصة (البحث عن ويكيبيديا ، قراءة مقالة ويكيبيديا) ، قم بإنشاء حلقة الخطوة التالية ، Max Steps Run Controller
وكيل مطور آلي يعمل في حاوية Docker. يمكنه قراءة الملفات وكتابة الملفات وتنفيذ الأوامر. يمكنك ضبطه لمشروعك واستخدامه لتوثيق رمز ، وكتابة الاختبارات ، واختبارات التحديث والميزات ، إلخ.
الميزات المستعملة: gpt-4
، تنفيذ الأدوات في حاوية Docker ، وكيل مع خطوات إعداد ثابت ، وخصائص تشغيل الوكيل المتعددة ، وإنشاء حلقة الخطوة التالية ، والأدوات (قراءة الملف ، والتشغيل ، والتشغيل ، والسيطرة ، واسأل المستخدم) ، وحساب التكلفة بعد تشغيل الوكيل
JS Agent تنفيذ Babyagi.
الميزات المستخدمة: خادم وكيل HTTP ، نموذج إكمال النص ( text-davinci-003
) ، إخراج وحدة التحكم المخصصة ، حلقة تخطيط المهام التحديث
يأخذ PDF وموضوع وإنشاء مؤشر ترابط Twitter مع جميع المحتوى من PDF وذات صلة بالموضوع.
الميزات المستخدمة: تكوين الوظائف (بدون عامل) ، تحميل 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" } ) ,
} ) ;
}