The NoFilterGPT API for Python allows developers to easily integrate the power of the NoFilterGPT AI model into their Python applications. With a simple POST request, you can generate dynamic responses from the AI, fine-tuning parameters such as temperature, token limit, and more.
To start using the NoFilterGPT API, you will need an API key. Simply log into your account at nofiltergpt.com, navigate to the "Settings" page, click on the "Developers" tab, and generate your API key. It's simple and fast!
Once you have your API key, you're ready to make requests to the NoFilterGPT API and build engaging applications.
The NoFilterGPT API's primary endpoint for generating AI-based chat completions is:
https://api.nofiltergpt.com/v1/chat/completions
This endpoint expects a POST request with the following required and optional parameters in the body, in JSON format.
-
messages: An array of message objects that represent the conversation. Each message object must have the following structure:
- role: Either
"system","user", or"assistant". - content: The message content. This is the text that the model will process or generate.
Example:
"messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello! Can you help me with something?"} ]
- role: Either
- temperature: Controls the creativity of the output. Lower values make the output more deterministic, while higher values increase randomness. Default:
0.7. - max_tokens: The maximum number of tokens (words/subwords) to generate. Default depends on the model.
- top_p: For nucleus sampling. This controls diversity by cutting off the less likely responses. Default:
1.
To authenticate, you need to append your API key in the query string of the request URL like this:
https://api.nofiltergpt.com/v1/chat/completions?api_key=YOUR_API_KEY
Replace YOUR_API_KEY with the actual API key obtained from your NoFilterGPT account.
The file example.py in the root of this project provides a working example of how to interact with the /v1/chat/completions endpoint using Python.
You will need to install the requests library if you haven't already:
pip install requests-
Replace the API Key: Open the
example.pyfile and replace'YOUR_API_KEY'with your actual API key obtained from nofiltergpt.com.api_key = 'YOUR_API_KEY'
-
Modify the Parameters (optional): You can modify the request parameters, such as
messages,temperature,max_tokens, andtop_p, in the file to fit your specific needs. For example, you can change the user input like this:data = { "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "How do I integrate this API?"} ], "temperature": 0.7, "max_tokens": 150, "top_p": 1 }
-
Run the Script: To execute the script and make a request to the
/v1/chat/completionsendpoint, simply run the Python file on your server or local environment:python example.py
This will output the response generated by the API based on the provided input.
Here is the content of example.py for your reference:
import requests
import json
# CHANGE THIS VALUE HERE
api_key = 'YOUR_API_KEY'
url = f'https://api.nofiltergpt.com/v1/chat/completions?api_key={api_key}'
data = {
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello! Can you help me with something?"}
],
"temperature": 0.7,
"max_tokens": 150,
"top_p": 1
}
headers = {
'Content-Type': 'application/json'
}
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code != 200:
print(f"Error: {response.status_code}")
else:
print(response.json())The API response will include a generated completion (i.e., a response from the assistant) and any additional data. Handle error responses with appropriate HTTP status codes.
- 400 Bad Request: One or more required parameters are missing.
- 401 Unauthorized: Invalid or missing API key.
If you would like to contribute or have suggestions for improvements, feel free to create an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.