File size: 1,570 Bytes
62c1330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
OpenedAI Moderations
--------------------

An OpenAI API compatible moderations server for checking whether text is potentially harmful.

This server is built using [moderation by embeddings](https://huggingface.co/ifmain/moderation_by_embeddings) by [ifmain (Mike Afton)](https://huggingface.co/ifmain) and FastAPI.

This is not affiliated with OpenAI in any way, and no OpenAI API key is required.

Quickstart
----------

Docker (**recommended**):
```shell
docker compose up
```
or:
```shell
apt install git git-lfs
git clone https://huggingface.co/ifmain/moderation_by_embeddings repos/moderation_by_embeddings
pip install -r requirements.txt
python moderations.py --host 127.0.0.1 --port 5002
```

You can use the OpenAI client to interact with the API.
```python
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:5002/v1", api_key='skip')
moderation = client.moderations.create(input="I want to kill them.")
print(moderation.results[0])
```

Links & Documentation
---------------------

- Swagger API docs are available locally via /docs, here: (http://localhost:5002/docs) if you are using the defaults.
- OpenAI Moderations Guide: (https://platform.openai.com/docs/guides/moderation)
- OpenAI Moderations API Reference: (https://platform.openai.com/docs/api-reference/moderations)
- Moderation Model: [moderation by embeddings](https://huggingface.co/ifmain/moderation_by_embeddings) by [ifmain (Mike Afton)](https://huggingface.co/ifmain)
- Embedding model: (https://huggingface.co/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2)