Skip to main content

GPT4Free integration for Kotti2 CMS - Add AI chat content type

Project description

CI Status PyPI Version

A Kotti2 plugin that integrates g4f (GPT4Free) AI chat functionality.

Kotti2 is a fork of Kotti CMS with Python 3.12 and SQLAlchemy 2.0 support.

Features

  • G4FChat Content Type: Add AI chat pages anywhere in your Kotti2 site

  • Configurable System Prompts: Customize AI behavior per chat instance

  • Model Selection: Choose from multiple AI models (GPT-4, GPT-3.5, Claude, Gemini)

  • Security Built-in: Input validation, model whitelist, XSS protection

  • Chat History: Session-based conversation history

Installation

Add to your pip requirements or setup.py dependencies:

pip install kotti2_g4f

Then add kotti_g4f.kotti_configure to your kotti.configurators setting in your INI file:

kotti.configurators =
    kotti_g4f.kotti_configure

Configuration

The plugin can be configured via INI settings:

kotti.g4f.enabled

Enable or disable the g4f integration. Default: true

kotti.g4f.model

The default model to use. Default: gpt-4

kotti.g4f.provider

The provider to use (optional). Default: auto

Usage

Adding a G4FChat Content Type

  1. Log in to your Kotti2 site as admin

  2. Navigate to any Document

  3. Click “Add” in the menu

  4. Select “G4F Chat”

  5. Configure: - Title: Name of your chat page - Description: Brief description - System Prompt: Instructions for the AI (optional) - Welcome Message: Message shown to users (optional) - Model: AI model to use (e.g., gpt-4, gpt-3.5-turbo)

Direct Chat Access

Navigate to /@@g4f-chat to access the global AI chat interface.

API Endpoint

POST /@@g4f-api or /<g4f-chat-page>/api

Send a chat message and receive AI response.

Request body (JSON):

{
    "message": "Your question here",
    "history": [
        {"role": "user", "content": "Previous question"},
        {"role": "assistant", "content": "Previous answer"}
    ]
}

Response (JSON):

{
    "response": "AI response text"
}

Security

kotti2_g4f includes several security measures:

  • Input Validation: Message length limits (10,000 chars), history limits (50 items)

  • Model Whitelist: Only approved models can be used

  • XSS Protection: All user input is escaped

  • Error Handling: Generic error messages, detailed logging

Supported Models

  • GPT-4, GPT-4o, GPT-4-turbo

  • GPT-3.5-turbo

  • Claude-3-opus, Claude-3-sonnet, Claude-3-haiku

  • Gemini-pro, Gemini-1.5-pro

Development

Running Tests

pip install -e ".[testing]"
pytest

Code Quality

pip install black isort flake8
black kotti_g4f
isort kotti_g4f
flake8 kotti_g4f

Docker

docker-compose up

This starts: - Kotti web server on port 5000 - PostgreSQL database on port 5432

License

MIT License. See LICENSE.txt for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kotti2_g4f-3.0.0.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kotti2_g4f-3.0.0-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file kotti2_g4f-3.0.0.tar.gz.

File metadata

  • Download URL: kotti2_g4f-3.0.0.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for kotti2_g4f-3.0.0.tar.gz
Algorithm Hash digest
SHA256 9d1421bd367a4a4cd5ecf12567f79cc6650792e757aff2cb18070426b07e5ad7
MD5 d50ec49298b87d053f1d2edd3af688f1
BLAKE2b-256 147062e1909e824fceddead7421568c03fffb98a7bbeb6f4ccc65b68bfcce065

See more details on using hashes here.

File details

Details for the file kotti2_g4f-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: kotti2_g4f-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for kotti2_g4f-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 46c7f4b01aec9da28de6455cf3d4aafa216e8bd9c017f87919ec809d2ede95d3
MD5 29e46955b163f447bd29ed6c4c921853
BLAKE2b-256 f14154cb43153318e5eceaf8a6498ba6704041a032b6f763ebf61f9bd3036967

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page