GitXplorerGitXplorer
A

payload-plugin-ai

public
15 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
d87f698d461a8c75a092c0a360b3c002f0449ba9

update readme

AAlessioGr committed 2 years ago
Unverified
48730b9a6869e4329a15a2e8cec509dcffd88a32

update readme

AAlessioGr committed 2 years ago
Unverified
960cd7ee1d241d6cc0335bea9401882f34705d80

.env.example

AAlessioGr committed 2 years ago
Unverified
165c15230f085afb2a039d7d07857255af2aa142

v1.1.0

AAlessioGr committed 2 years ago
Unverified
3745ec4a056f7229c09ece165f6807133f083751

update readme

AAlessioGr committed 2 years ago
Unverified
3d91068e36bf196b93fb8ee0aaa146797f7134a3

fix: typings

AAlessioGr committed 2 years ago

README

The README file for this repository.

Payload AI plugin

npm version

ATTENTION: This plugin currently requires a custom fork of payload to work (replace payload with yarn add alessiogr/payload#production-with-custom). This is because this plugins depends on two PRs which haven't been merged into payload yet:

In this repository I will add a bunch of AI stuff! Currently, it can just generate embeddings for fields using the OpenAI API. Expect things to break with updates without notice.

Installation

yarn add payload-plugin-ai

Add this to your payload.config.ts:

import { ai } from 'payload-plugin-ai';

...

plugins: [
    ai({
      OPENAI_SECRET: process.env.OPENAI_SECRET,
      NLPCLOUD_API_KEY: process.env.NLP_CLOUD_API_KEY,
      embeddings: {
        provider: "nlpcloud", // Nlpcloud is recommended
      },
    }),
]

Embeddings

Embeddings generated in the Admin UI

To enable embeddings on a field, simply add this property to the field:

import { genEmbeddings } from 'payload-plugin-ai';

...

yourField: {
  ...
  custom: {
        ...genEmbeddings({ visible: true }),
  },
}

Now, every time you save the collection, embeddings for that field will be generated.

Search through embeddings

You can use MongoDB atlas search to search through embeddings. In MongoDB Atlas, create a search index which looks like this:

{
  "mappings": {
    "fields": {
      "textArea_embeddings": [
        {
          "dimensions": 768,
          "similarity": "euclidean",
          "type": "knnVector"
        }
      ]
    }
  }
}

Replace textArea_embeddings with the name of the embeddings field generated by this plugins.

Once the index is created, you can search through your documents using something like mongoose. There's an example in the payload.config.ts in the demo folder (make sure you adjust the index name and the path).

Other

Project structure inspired by payload-plugin-cloud-storage and pcms-backpop