
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创建,请参阅我们的开源项目。