npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

payload-ai

v0.0.67

Published

Payload AI tools

Downloads

11

Readme

Payload AI

Translate content to different languages using OpenAI's GPT.

How to install the plugin

Install via npm:

npm install payload-ai

Or yarn:

yarn add payload-ai

To install the plugin, simply add it to your payload.config() in the Plugin array.

import payloadAi from 'payload-ai';

export const config = buildConfig({
  plugins: [
    // You can pass options to the plugin
    payloadAi({
		  enabled: true,
    }),
  ]
});

Collection translation 📦

Add the collections where you want to enable the translation and the fields. It will translate each field (also nested fields) on every update of the default language.

plugins: [
  aiTranslatorPlugin({
    enabled: true,
    collections: {
      examples: { // Name of the collection you want to add translations
        fields: [
          'stringText', // Keys of fields you want to translate (wil also translate nested fields)
          'richText',
        ],
      },
    },
  }),
],

Custom prompts by Field

Use promptFunc for each field to customize the prompt.

plugins: [
  aiTranslatorPlugin({
    enabled: true,
    collections: {
      examples: {
          settings: {
            model: 'gpt-4',
            promptFunc: ({ messages, namespace }) => {
              return [
                {
                  role: 'system',
                  content:
                    'Important: Add a smily face at the end of the message to make the AI more friendly. 😊',
                },
                ...messages,
              ]
            },
          },
        },
    }
  }
]

The function will allow you to use the following

  • req: Request

  • doc Document in languages

  • previousDoc Old document (only available on Update)

  • targetDoc The old target document

  • collectionOptions

  • language

  • translatorConfig language: string, sourceLanguage?: string,

  • targetField

  • sourceField

Use with payload-seo



import {generateTitle, generateDescription } from "payload-ai";

seo({
  collections: ['examples'],
  // uploadsCollection: 'media',
  generateTitle: generateTitle,
  generateDescription: ({ doc }) => generateDescription,
});

String translation

Use this to provide a backend for i18next string translations.

plugins: [
  aiTranslatorPlugin({
    enabled: true,
    stringTranslation: {
      enabled: true
    }
  }),
],

Change model for string translation

To update the model you can change the collection settings in the same way as with other collections.

plugins: [
  aiTranslatorPlugin({
    enabled: true,
    stringTranslation: {
      enabled: true
    }
    collections: {
      translations: {
        settings: {
          model: 'gpt-4',
        },
      }
    }
  }),
],

Access control

By default the plugin will use the update access control of the collection.

To overwrite that behaviour you can add access to the collections configuration.

plugins: [
  aiTranslatorPlugin({
    enabled: true,
    stringTranslation: {
      enabled: true
    }
    collections: {
      examples: {
        access: () => true,
      }
    }
  }),
],

Planned features 🧭

  • generate image alt text from GPT
  • generate SEO Text
  • generate structured content
  • custom access control
  • custom overrides for translation
  • generate images based on input
  • generate Open Graph based on content

Use in hooks

TODO: add documentation

myCollectionPrompt = ({source}) => {

source()

return }