Skip to content

uncensored-chatgpt/NoFilterGPT-API-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

NoFilterGPT API for Python

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.

Getting Your API Key

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.

How to Use the NoFilterGPT API

Endpoint: /v1/chat/completions

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.

Required Parameters:

  • 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?"}
    ]

Optional Parameters:

  • 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.

Authentication

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.

Example Usage with example.py

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.

Setup

You will need to install the requests library if you haven't already:

pip install requests
  1. Replace the API Key: Open the example.py file and replace 'YOUR_API_KEY' with your actual API key obtained from nofiltergpt.com.

    api_key = 'YOUR_API_KEY'
  2. Modify the Parameters (optional): You can modify the request parameters, such as messages, temperature, max_tokens, and top_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
    }
  3. Run the Script: To execute the script and make a request to the /v1/chat/completions endpoint, 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.

Full example.py Code

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())

Handling Responses

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.

Error Handling

  • 400 Bad Request: One or more required parameters are missing.
  • 401 Unauthorized: Invalid or missing API key.

Contributing

If you would like to contribute or have suggestions for improvements, feel free to create an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Example on how to use NoFilterGpt.com's chat API with Python language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages