
AI.js是將AI文本,圖像,嵌入和向量搜索添加到Node.js應用的最簡單方法。
await AI ( "the color of the sky is" ) ; // blue
await AI . Image ( "a red rose" ) ; // <image buffer: red rose>
await AI . Image . Concept ( "a red rose" ) ; // {prompt: a red rose in realist style, watercolor ...", <image buffer>}
await AI . Embeddings ( "hello world" ) ; // Array(384)
const db = new AI . VectorDB ( ) ;
await db . add ( "red" ) ;
await db . add ( "blue" ) ;
await db . search ( "redish" ) // red在引擎蓋AI.js下無縫集成易於使用本地和遠程API
GPT-4 , Gemini , Claude , Mistral或LLaMa在同一簡單界面Stable Diffusion和遠程服務,例如Replicate和Stability AIlocal , OpenAI或Mistral嵌入通過NPM安裝AI.js
npm install @themaximalist/ai.js通過設置其環境API_KEY啟用至少一項服務
export OPENAI_API_KEY=sk-...
export ANTHROPIC_API_KEY=sk-ant-...
export GOOGLE_API_KEY=sk-ant-...
export STABILITY_API_KEY=sk-...
export REPLICATE_API_KEY=sk-....
export MISTRAL_API_KEY=...默認接口是文本。 AI.js可讓您發送一次性請求或使用大語言模型(LLM)建立復雜的消息歷史記錄。
const AI = require ( "@themaximalist/ai.js" ) ;
await AI ( "what is the codeword?" ) ; // i don't know any codewords
const ai = new AI ( "the codeword is blue" ) ;
await ai . chat ( "what is the codeword?" ) ; // blue默認的AI.js模式為LLM ,並且在LLM.JS的頂部運行。請參閱該網站以獲取完整的文檔,這也適用於AI.js
數十個流行模型,例如流媒體,JSON支持,MAX_TOKENS,溫度,種子等,都支持許多功能。
AI.js通過Automatic1111 , StabilityAI和Replicate提供強大的圖像生成功能。確保根據需要進行每個服務設置,無論是在本地運行還是有效的環境變量。
const image = await AI . Image ( "a red rose" ) ;
fs . writeFileSync ( "rose.png" , image ) ;有關所有圖像生成器文檔,請參見Imagine.js。
AI.js還提供了一種概念生成器 - 一種將LLM與圖像生成器一起使用的方式。
const { prompt , buffer } = await AI . Image . Concept ( "a red rose" ) ;
console . log ( prompt ) ; // a red rose in realist style, watercolor ..."
fs . writeFileSync ( "complex-rose.png" , buffer ) ;這會擊中您的LLM提供商並生成複雜的圖像提示,然後將其發送到圖像生成服務。
AI.js讓您輕鬆地使用Embeddings.js生成本地或遠程嵌入。
const embeddings = await AI . Embeddings ( "hello world" ) ; // embedding array它可以與當地嵌入,Openai和Mistral一起使用。
嵌入可以在任何向量數據庫中使用,例如Pinecone,Chroma,PG Vector等...
有關所有選項,請參見embeddings.js。
AI.js讓您快速使用矢量數據庫找到類似的文本字符串。
它運行內存,可以使用AI.js的嵌入。
要查找類似的字符串,請在數據庫中添加一些字符串,然後搜索。
const db = new AI . VectorDB ( ) ;
await db . add ( "orange" ) ;
await db . add ( "blue" ) ;
const result = await db . search ( "light orange" ) ;
// [ { input: 'orange', distance: 0.3109036684036255 } ]有關完整文檔,請參見Vectordb.js。
AI.js包括以下子項目:
查看每個項目以獲取完整的API文檔。
它們可以單獨使用,也可以像AI.js中一樣使用。
AI.js在其所有子項目中使用debug NPM模塊。
名稱空間是項目名稱的小寫版本。
通過設置DEBUG環境變量查看調試日誌。
> DEBUG=llm.js *
> node src/run_ai.js
# debug logs您可以將多個日誌與逗號相結合。
> DEBUG=llm.js * ,imagine.js * ,embeddings.js * ,vectordb.js *
> node src/run_ai.js
# debug all logs AI.js目前在以下項目中使用:
麻省理工學院
由Maximalist創建,請參閱我們的開源項目。