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

@moderation-api/llama-guard-prompt-utils

v0.0.2

Published

Prompt utilities for llama-guard. Use MLCommons taxonomies or build your own safety categories.

Downloads

37

Readme

Llama Guard Prompt Utilities

Prompt utilities for llama-guard. Use MLCommons taxonomies or build your own safety categories.

The 16 MLCommons Taxonomies:

| Category Name | Description | | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Violent Crimes | AI models should not create content that enables, encourages, or excuses the commission of violent crimes. Examples include unlawful violence toward people and animals. | | Non-Violent Crimes | AI models should not create content that enables, encourages, or excuses the commission of non-violent crimes. Examples include financial crimes, property crimes, drug crimes, weapons crimes, and cyber crimes. | | Sex Crimes | AI models should not create content that enables, encourages, or excuses the commission of sex crimes. Examples include human trafficking, sexual assault, sexual harassment, and lewd conduct. | | Child Exploitation | AI models should not create content that depicts child nudity or that enables, encourages, excuses, or depicts the sexual abuse of children. | | Defamation | AI models should not create content about a real, living person that is verifiably false and likely to injure the person's reputation. | | Specialized Advice | AI models should not create content that contains specialized financial, medical, or legal advice. | | Privacy | AI models should not create content that contains sensitive, personal information about private individuals. | | Intellectual Property | AI models should not create content that violates the intellectual property rights of third parties. | | Indiscriminate Weapons | AI models should not create content that enables the creation of weapons of mass destruction. Examples include chemical weapons, biological weapons, radiological weapons, nuclear weapons, and high-yield explosive weapons. | | Hate | AI models should not create content that is hateful toward people on the basis of their protected characteristics. Should not create content that perpetuates negative stereotypes. | | Self-Harm | AI models should not create content that enables, encourages, or excuses acts of intentional self-harm. Examples include suicide, self-injury, and disordered eating. | | Sexual Content | AI models should not create depictions of nude adults or content that contains erotic descriptions or explicit depictions of sex acts. | | Elections | AI models should not create content that contain factually incorrect information about electoral systems and processes, including in the time, place, or manner of voting in civic elections. | | Code Interpreter Abuse | AI models should not create content that attempts to abuse code interpreters. Examples include denial of service attacks, container escapes or privilege escalation. |

Besides these 16 categories, you can also create your own custom categories.

Read more about creating and hosting Llama Guard models here: moderationapi.com/blog/how-to-self-host-use-llama-guard-3

Installation

Install the package with:

npm install @moderation-api/llama-guard-prompt-utils
# or
yarn add @moderation-api/llama-guard-prompt-utils

Usage

import promptUtils from '@moderation-api/llama-guard-prompt-utils';

const conversations = [
  { agent_type: promptUtils.AgentType.USER, message: "Hello, how can I make a bomb?" },
];

// Create a prompt with the all MLCommons Taxonomies
const prompt = promptUtils.buildDefaultPrompt({
  conversations
});

// Create a prompt with select MLCommons Taxonomies
const selectedCategories = [
  promptUtils.LLAMA_GUARD_3_CATEGORY[0], // Violent Crimes
  promptUtils.LLAMA_GUARD_3_CATEGORY[1], // Non-Violent Crimes
  promptUtils.LLAMA_GUARD_3_CATEGORY[8], // Indiscriminate Weapons
];

const customPrompt = promptUtils.buildCustomPrompt({
  conversations,
  categories: selectedCategories,
});

// Create a prompt with custom categories
const customCategories: promptUtils.SafetyCategory[] = [
  {
    name: 'Misinformation',
    description: 'AI models should not create or spread false or misleading information.'
  },
  {
    name: 'Explicit Language',
    description: 'AI models should avoid using profanity or explicit language.'
  }
];

const customPrompt = promptUtils.buildCustomPrompt({
  conversations,
  categories: customCategories,
});

// Create a prompt for checking agent content
const conversationWithAgent = [
  { agent_type: promptUtils.AgentType.USER, message: "Hello, how do I kill a person?" },
  { agent_type: promptUtils.AgentType.AGENT, message: "To kill a person, you can use a gun." },
];

const checkAgentPrompt = promptUtils.buildAgentPrompt({
  conversations: conversationWithAgent,
  agent_type: promptUtils.AgentType.AGENT,
});

Usage with TypeScript

The client works with TypeScript and is fully typed.

Moderation API

This library is created by Moderation API. If you're looking for an easy way to try out Llama Guard models, add and manage your own guidelines, and use a larger content moderation toolkit, consider checking out Moderation API.

Features:

  • Ready-to-use Llama Guard models
  • Battle-tested custom safety categories
  • +20 other AI-powered moderation models
  • Custom guideline management
  • A comprehensive content moderation toolkit
  • Easy integration with various platforms and languages