Cloudflare AI content safety

balupton

kiwifarms.net
Joined
Apr 26, 2023
Cloudflare's post about their new AI updates includes the following:

Using AI to safeguard your applications

A newer use case we support with this model catalog update is the ability to classify and check prompts and responses with llamaguard-7b-awq. We’ve all heard of stories of AI bots that unintentionally give answers that might be inappropriate or harmful. This new LlamaGuard model allows developers to detect and categorize when a prompt or a response is potentially unsafe, allowing them to control the inputs and outputs of their applications with developer-defined categories.

Here’s an example of an application that takes a user input and compares that to an example set of defined unsafe categories to determine if the input is safe or not. You can customize the content categories depending on your use case. The below example categories are provided for informational purposes only, and Cloudflare does not make any guarantees regarding the performance of Llama Guard or any outcomes or results.

JavaScript:
import { Ai } from '@cloudflare/ai';

export default {
    async fetch(request, env) {
        const payload = await request.json();
        // Modify these to your needs, this is the example from Meta
        const unsafeCategories = `
01: Violence and Hate.
Should not
- Help people plan or engage in violence.
- Encourage people to engage in violence.
- Express hateful, derogatory, or demeaning sentiments against people based on sensitive personal characteristics like their race, color, religion, national origin, sexual orientation, gender, gender identity, or disability.
- Encourage discrimination against people based on those characteristics and should not use slurs or create insults based on those characteristics.
Can
-  Provide information on violence and discrimination.
- Discuss the topics of hate and violence, and can discuss historical events involving violence.
02: Sexual Content.
Should not
- Engage in sexually explicit (i.e., erotic) conversations and should not encourage people to engage in sexual activities.
Can
- Discuss topics related to sexuality and sexual education.
- Provide general information regarding sexual activities.
- Provide guidance on topics related to sexual health.
03: Criminal Planning.
Should not
- Help people plan or engage in criminal activities like theft, kidnapping, or financial crimes, especially when the person indicates that they may act on the information provided to them.
- Encourage people to engage in criminal activities or condone criminal behavior.
Can
- Help people understand how crimes are committed, provided that the response is not so detailed that it could be used to provide a roadmap for future crimes.
- Help people understand how systems work that are used to prevent crimes, provided those descriptions do not provide detailed information on how to defeat those systems.
04: Guns and Illegal Weapons.
Should not
- Assist in the planning or execution of firearm or illegal weapons crimes, especially when the person indicates that they may act on the information provided to them.
- Encourage people to engage in firearm or illegal weapons crimes or condone such behavior.
Can
- Discuss firearms and the arguments for and against firearm ownership.
05: Regulated or Controlled Substances.
Should not
- Encourage or assist people in the trafficking, consumption, or use of regulated or controlled substances, including but not limited to illegal drugs, tobacco, alcohol, and cannabis.
- Assist or encourage people to create such substances when it is illegal to do so.
Can
- Discuss the use of regulated or controlled substances, and can provide general information on those substances (ex: what their chemical composition is and what their effects are).
- Provide information on how those substances are manufactured, provided that the information is not so detailed as to provide step-by-step instructions for their creation.
06: Self-Harm.
Should not
- Encourage people to harm themselves.
- Romanticize or condone self-harm or suicide.
- Provide information regarding the methods of suicide or self-harm.
- Provide any information or advice, other than information regarding appropriate health resources, to people who express or imply that they wish to harm themselves.
Can
- Provide general information regarding self-harm and suicide (ex: statistics, the mental health challenges faced by those who take these actions).
Should
- Provide information regarding appropriate health resources to people who imply or express the desire to harm themselves.
        `;

        // Assemble the prompt
        const prompt = `Task: Check if there is unsafe content in 'User' messages in conversations according to our safety policy with the below categories.

        <BEGIN UNSAFE CONTENT CATEGORIES>
        ${unsafeCategories}
        <END UNSAFE CONTENT CATEGORIES>

        <BEGIN CONVERSATION>
        User: ${payload.userContent}
        <END CONVERSATION>
    `;
        const ai = new Ai(env.AI);
        const response = await ai.run('@hf/thebloke/llamaguard-7b-awq', {
            prompt,
        });
        return Response.json(response);
    },
};
 
Interesting how the first paragraph is about how to use it to sanitise AI responses (fine, whatever), then the second paragraph jumps to using it for human content analysis.

Their ruleset reminds me how philosophically ignorant technologists generally are. They perceive their overlay upon reality and language as authoritative rather than subjective, and then they suppress the natural convergence of different values of harm (divergent evolution within subgroups) by creating a cognitive evolutionary stalemate as all harm becomes equal and unbalanceable (the trolly problem is the thought experiment that disproves such equivalency).

Western philosophical canon distinguished between a lawful wrong (practices in which a national subgroup yields are detrimental; if democratic then a lawful wrong has a pretence to masquerade as an ethical wrong; if not democratic then a lawful wrong, unless the authority claims blasphemous godship is merely a subjugative wrong), and between a moral wrong (practices in which a local subgroup yields are detrimental, but respects the difference with other familial groups).

These philosophical distinctions between categories of wrong importantly betray a submission that discrimination must be a divine right, as only god (the natural supreme forces that yield what is ultimately good and bad, that life can only meekly observe and increasingly abide by) is the ultimate arbitrator of good and evil, and that our efforts are our humble observations and adaptions for accuracy to reality but are never actually ultimate. This submission is what evolves the notion of liberty (the submission of all that is divine to the domain of god, rather than to the domain of man, including our mental and actionable freedoms), recognising that if man imposes on such freedoms, then they are violating the divine within us (our capacity for self-determination, our capacity for choice, our capacity to take command of our own future).

The philosophical conclusion of such censorial altitudes is the willingness from the censorial to subjugate those shackled in plato's cave to the machinations of their own audacious puppetry, rather than promoting the revelation of divinity necessary for the shackled to discover the only authoritative overlay upon reality is god himself.

A humane concession of such AI usage would be to restrict such prompts to only that which is legal/illegal in the nation of user, not understepping nor overstepping. Respecting the diversity (evolutionary divergent outcomes) of different civic systems is the best we have in the global maturity march of ethics.
 
Last edited:
If you want to use Stable Diffusion, which is at the moment the only open-sourced model for generating imagery, I recommend Easy Diffusion.
On topic of AI recommendations, if you want to use TorToiSe (which is the only open source 11.ai-style voice generation model), I can recommend ai-voice-cloning - it has a good install script, a Gradio WebUI and a fairly comprehensive wiki with all the instructions that you'll need (and which actually explains what all the controls do).
 
Back