Giter VIP home page Giter VIP logo

ai.js's Introduction

AI.js

AI.js — AI Toolkit for Node.js

GitHub Repo stars NPM Downloads GitHub code size in bytes GitHub License

AI.js is the easiest way to add AI text, images, embeddings and vector search to your Node.js app.

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

Under the hood AI.js seamlessly integrates easy to use local and remote APIs

  • Text: LLM.js use GPT-4, Gemini, Claude, Mistral or LLaMa in same simple interface
  • Image: Imagine.js supports local Stable Diffusion and remote services like Replicate and Stability AI
  • Embeddings: Embeddings.js create local, OpenAI or Mistral embeddings
  • VectorDB: VectorDB.js searches similar embeddings in memory
  • Audio: Coming Soon
  • Video: Coming Soon

Features

  • Easy to use
  • Same simple interface for hundreds of models (OpenAI, Google, Anthropic, Mistral, LLaMa, Replicate, Stability AI, Hugging Face and more)
  • Works locally and offline by default!
  • Offers best-in-class options through remote APIs
  • Advanced LLM features like one-shot prompts, chat history, streaming and JSON schema and more
  • Image generation using the best open and paid models
  • Image concepts to easily combine LLMs with Image generators for impressive results
  • Easy to use text embeddings and in-memory vector search
  • MIT license

Installation

Install AI.js via npm

npm install @themaximalist/ai.js

Enable at least one service by setting its environment 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=...

LLM

The default interface is text. AI.js lets you send one-off requests or build up complex message histories with the Large Language Model (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

The default AI.js mode is LLM, and is running on top of LLM.js. Please see that site for full documentation, that also applies to AI.js.

There are many features supported across dozens of popular models, like streaming, JSON support, max_tokens, temperature, seed and more.

Images

AI.js provides powerful image generation functions through Automatic1111, StabilityAI and Replicate. Make sure you have each service setup as needed, either running locally or a valid environment variable.

const image = await AI.Image("a red rose");
fs.writeFileSync("rose.png", image);

See Imagine.js for all image generator documentation.

Imagine Concepts

AI.js also provides a concept generator—a way of using LLMs together with image generators.

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);

This hits your LLM provider and generates a complex image prompt before sending it off to the image generation service.

Embeddings

AI.js let's you easily generate local or remote embeddings using Embeddings.js.

const embeddings = await AI.Embeddings("hello world"); // embedding array

It works with local embeddings, OpenAI and Mistral.

Embeddings can be used in any vector database like Pinecone, Chroma, PG Vector, etc...

See Embeddings.js for all options.

Vector Search

AI.js let's you quickly find similar text strings using a vector database.

It runs in-memory and can use embeddings from AI.js.

To find similar strings, add a few to the database, and then search.

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 } ]

See VectorDB.js for full documentation.

API

AI.js includes these sub-projects:

  • LLM.js — Simple interface to dozens of Large Language Models
  • Imagine.js — Local and remote image generation library
  • Embeddings.js — Simple local or OpenAI text embeddings
  • VectorDB.js — Local text similarity search

Check out each individual project for full API documentation.

They can be used individually or together like in AI.js.

Debug

AI.js uses the debug npm module across all of it's sub-projects.

The namespace is the lowercase version of the project name.

View debug logs by setting the DEBUG environment variable.

> DEBUG=llm.js*
> node src/run_ai.js
# debug logs

You can combine multiple logs with a comma.

> DEBUG=llm.js*,imagine.js*,embeddings.js*,vectordb.js*
> node src/run_ai.js
# debug all logs

Projects

AI.js is currently used in the following projects:

License

MIT

Author

Created by The Maximalist, see our open-source projects.

ai.js's People

Contributors

themaximalist avatar

Stargazers

jeunjetta avatar Stefan Ciprian Hotoleanu avatar  avatar  avatar Ryan M. Poe avatar Kiran Kota avatar Sandalots avatar M̵̞̗̝̼̅̏̎͝Ȯ̴̝̻̊̃̋̀Õ̷̼͋N̸̩̿͜ ̶̜̠̹̼̩͒ avatar Tim Huff avatar 9kopb avatar gefei avatar Majed Itani avatar TheNotify avatar

Watchers

Andy Abgottspon avatar  avatar  avatar

Forkers

ag076810

ai.js's Issues

Claude V2

Dear Maximal1st team,

Awesome repo! Been using the component for a few weeks and its amazing. I wonder why this repo is not much much more popular?

I was wondering if there are plans to add Claude V2. I tried using it by just adjusting the model string but always receive an error. Thanks for the update. If this is not actively developed, it's OK as well, but please let me know as I'd have to look for another solution (even though I love the elegance of this one)

Andy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.