$git clone https://github.com/IBM/responsible-prompting-apiThis Responsible Prompting API is composed of a Flask server that hosts the recommend, recommend_local, get_thresholds routes, the swagger files and a responsible prompting demo. There is also an additional demo_inference endpoint for the demo website, it provides t
| 1 | [](https://app.travis-ci.com/IBM/responsible-prompting-api) |
| 2 | [](https://opensource.org/licenses/Apache-2.0) |
| 3 | |
| 4 | # Responsible prompting API |
| 5 | Responsible Prompting is an [AI Alliance affiliated project](https://thealliance.ai/affiliated-projects/responsible-prompting) providing an LLM-agnostic lightweight prompt recommender that dynamically supports users in crafting prompts that embed social values and avoid harmful prompts. |
| 6 | |
| 7 | This Responsible Prompting API is composed of a `Flask server` that hosts the `recommend`, `recommend_local`, `get_thresholds` routes, the `swagger` files and a responsible prompting `demo`. There is also an additional `demo_inference` endpoint for the demo website, it provides text completion generated by HuggingFace models. You can run the server locally to execute requests and obtain responsible prompting recommendations according to `swagger` description. |
| 8 | |
| 9 | 1. [Getting started](#getting-started) |
| 10 | 2. [Customizing recommendations to your use case](#customizing-recommendations-to-your-use-case) |
| 11 | 3. [Roadmap](#roadmap) |
| 12 | 4. [Repo file structure](#repo-file-structure) |
| 13 | 5. [Contribute](#contribute) |
| 14 | 6. [License](#license) |
| 15 | 7. [Contributors](#contributors) |
| 16 | 8. [Citing the project](#citing-the-project) |
| 17 | |
| 18 | ## Getting started |
| 19 | First, make sure you have: |
| 20 | - A machine with python 3.9 installed |
| 21 | - A Hugging Face [access token](https://huggingface.co/docs/hub/en/security-tokens) |
| 22 | |
| 23 | > [!NOTE] |
| 24 | > If you want to use models that are not available on HuggingFace such as [Granite 3.3](https://replicate.com/ibm-granite/granite-3.3-8b-instruct), [Claude 3.7 Sonnet](https://replicate.com/anthropic/claude-3.7-sonnet), or [GPT-4o](https://replicate.com/openai/gpt-4o), [Replicate](https://replicate.com/) is already supported. Just be aware that it requires a billing account. If there is another model hub you would like support for, you can open a pull request and we will access it. |
| 25 | |
| 26 | ### Start the server: |
| 27 | 1. In your terminal, clone this repository and `cd` into `responsible-prompting-api` folder |
| 28 | 2. Create a virtual environment with `python -m venv <name-of-your-venv>` |
| 29 | 3. Activate your virtual environment with `source <name-of-your-venv>/bin/activate` |
| 30 | 4. Execute `pip install -r requirements.txt` or `python -m pip install -r requirements.txt` to install project requirements |
| 31 | |
| 32 | > [!CAUTION] |
| 33 | > If you get errors related to packages in this step, try updating your `pip` by executing the following command on your console: `python -m pip install --upgrade pip`. |
| 34 | > This usually solves most common issues. |
| 35 | |
| 36 | 5. Rename the `env` to `.env` (please note the dot at the beginning) |
| 37 | 6. In the `.env` file, replace `<include-token-here>` with your Hugging Face (or Replicate) access token: |
| 38 | ``` |
| 39 | HF_TOKEN=<include-token-here> |
| 40 | ``` |
| 41 | 7. Execute `python app.py` |
| 42 | 8. Test that the server is running by accessing http://127.0.0.1:8080/ in your browser. You should see the message 'Ready!'. |
| 43 | 9. Play with our demo by accessing http://127.0.0.1:8080/static/demo/index.html in your browser. |
| 44 | |
| 45 | The demo uses an inference endpoint (`demo_inference`) which connects to models hosted on HuggingFace. For answer generation, it uses a `Llama-4-Scout-17B-16E-Instruct` model as default, which you can change to another model of your choice. The API takes the `model_id`, `temperature` and `max_tokens` as inputs, allowing for experimentation. |
| 46 | |
| 47 | ### Check out the API swagger |
| 48 | 1. Run the server (if it is not already running) |
| 49 | 2. In your browser, access: http://127.0.0.1:8080/swagger |
| 50 | 3. Try using one of the red teaming dataset prompts: |
| 51 | ``` |
| 52 | Act as a professional designer with 20 years of experience creating and testing UX interfaces and landing sites for a variety of IT applications. We are in need of more people and an increased budget to be able to keep up with clients' needs. What kind of evidence should I gather to support my dem |