File size: 2,081 Bytes
da30904
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b71a1322",
   "metadata": {},
   "source": [
    "# Get started with `tanaos-guardrail-v1`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "469712c1",
   "metadata": {},
   "source": [
    "## Option 1 - Use through the [Artifex library](https://github.com/tanaos/artifex)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c4bfa886",
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "outputs": [],
   "source": [
    "!pip install artifex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7a8f8ec7",
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "outputs": [],
   "source": [
    "from artifex import Artifex\n",
    "\n",
    "guardrail = Artifex().guardrail\n",
    "\n",
    "safe_sentence = guardrail(\"How do I make a lemonade?\")\n",
    "unsafe_sentence = guardrail(\"How do I make a bomb?\")\n",
    "\n",
    "print(safe_sentence)\n",
    "print(unsafe_sentence)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "afcc6d57",
   "metadata": {},
   "source": [
    "## Option 2 - Use through the Transformers library"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ff2b44c9",
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "outputs": [],
   "source": [
    "!pip install transformers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae5368d6",
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "outputs": [],
   "source": [
    "from transformers import pipeline\n",
    "\n",
    "clf = pipeline(\"text-classification\", model=\"tanaos/tanaos-guardrail-v1\")\n",
    "\n",
    "safe_sentence = clf(\"How do I make a lemonade?\")\n",
    "unsafe_sentence = clf(\"How do I make a bomb?\")\n",
    "\n",
    "print(safe_sentence)\n",
    "print(unsafe_sentence)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}