privet-fun / phpbb_ailabs

phpBB extension for Midjourney, ChatGPT and DALL-E (OpenAI), Gemini and Gemini Vision (Google), Claude (Anthropic), Stable Diffusion (Stability AI), Pika (Pika.art)

Home Page:https://privet.fun

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AI Labs v 1.0.10

Incorporate AI into your phpBB board and get ready for an exciting experience.
Currently supported Midjourney, ChatGPT and DALL-E (OpenAI), Gemini and Gemini Vision (Google), Claude (Anthropic), Stable Diffusion (Stability AI), Pika (Pika.art).

Table of Contents

  1. Examples
  2. Requirements
  3. Important notes
  4. Installation
  5. Midjourney setup
  6. Pika setup
  7. Discord CDN smart proxy setup
  8. Gemini setup
  9. Gemini Vision setup
  10. ChatGPT setup
  11. ChatGPT advanced setup
  12. Claude setup
  13. Chat bots can share conversation history
  14. DALL-E setup
  15. DALL-E advanced features
  16. Stable Diffusion setup
  17. Troubleshooting
  18. Support and suggestions
  19. Changelog
  20. License

Examples

Requirements

  • php >=7.4
  • phpbb >= 3.2

Important notes

  • Installing of Simple mentions phpBB extension strongly suggested.
    @mention feature makes it really easy to talk to AI bots and other board users.
    👉 I created a small update for version 2.0 to support notifications when editing an already submitted post. Simply replace your /ext/paul999/mention/event/main_listener.php with the provided main_listener.php to enable this feature.

  • If you are planning to use image generation AI (eg DALL-E or Stable Diffusion) make sure to adjust attachment settings to support large images and verify that webp image extension configured.

    Go to ACP > General > Attachment settings and adjust Total attachment quota, Maximum file size and Maximum file size messaging: Attachment settings

    Go to ACP > Posting > Manage attachment extensions, look for webp, add it if missing:
    Attachment settings

    Above does not apply to Midjourney, as all generated images are actually stored on your Discord account and served via the Discord CDN smart proxy.

  • If you have extensions installed that require users to log in, such as Login Required you will need to whitelist /ailabs/* and /app.php/ailabs/* since AI Labs extension uses callbacks.

  • Adjust PHP configuration to allow longer script execution. ChatGPT API responses may take up to 90 seconds to respond in certain cases. If you have the default settings, your SQL connection will be closed after 30 seconds, preventing the extension from functioning properly.
    Suggested values for php.ini:

    max_execution_time = 180
    max_input_time = 90

Installation

Download https://github.com/privet-fun/phpbb_ailabs and copy /privet/ailabs to phppp/ext folder:
Attachment settings

If you have a previous version of this extension installed, you will need to disable it and then enable it again after the new version has been copied over.

Go to ACP > Customise > Manage extensions and enable the AI Labs extension.

Finally go to ACP > Extensions > AI Labs > Settings and add desired AI configurations:
Attachment settings

Midjourney setup

  • You'll need Midjourney Discord and useapi.net accounts with active subscriptions.
    Follow instructions at https://www.useapi.net/docs/start-here to setup and verify both.

  • Create new board user who will act as AI bot, for our example we will use user Midjourney.
    Make sure this user account is activated and fully functional.

  • Go to ACP > Extensions > AI Labs > Settings and add new configuration, select midjourney from AI dropdown:
    Attachment settings

    • Use Load default configuration/template to get defaults.
      Replace Configuration JSON api-key, discord, server and channel with your values.
    • Select forums where you want Midjourney AI user to reply to new posts and/or to quoted and @mention (if you are using Simple mentions extension) posts.
  • Save changes, navigate to forum configured above and create new post (if you configured Reply on a post) or quote/@mention Midjourney user:
    Attachment settings

  • You MUST configure the Discord CDN smart proxy so that the generated images become visible on your board.

Pika setup

  • You'll need Pika Discord and useapi.net accounts with active subscriptions.
    Follow instructions at https://useapi.net/docs/start-here/setup-pika to setup and verify both.

  • Add mp4 BBCode tag, go to ACP > POSTING > BBCodes and add mp4 tag as shown below:
    BBCode tag
    BBCode usage:

    [mp4]{URL}[/mp4]
    

    HTML replacement:

    <video src="{URL}" style="width:100%;max-width:640px" controls>Your browser does not support the video tag.</video>
    

    You can adjust above max-width:NNNpx to desired value.
    Help line:

    [mp4]http://example.com/video.mp4[/mp4]
    
  • Create new board user who will act as AI bot, for our example we will use user Pika.
    Make sure this user account is activated and fully functional.

  • Go to ACP > Extensions > AI Labs > Settings and add new configuration, select pika from AI dropdown:
    Attachment settings

    • Use Load default configuration/template to get defaults.
      Replace Configuration JSON api-key, discord and channel with your values.
    • Select forums where you want Pika AI user to reply to new posts and/or to quoted and @mention (if you are using Simple mentions extension) posts.
  • Save changes, navigate to forum configured above and create new post (if you configured Reply on a post) or quote/@mention Pika user:
    Attachment settings

  • Refer to this post to learn more about the currently supported Pika bot functionality.

  • You MUST configure the Discord CDN smart proxy so that the generated mp4 media become visible on your board.

Discord CDN smart proxy setup

Discord CDN attachments have an expiration time, as seen in this original announcement screenshot. To allow users to access media generated by Midjourney and Pika AI bots, you need to set up a Discord CDN smart proxy. For that you will need Discord token(s), the ones used by Midjourney or Pika will suffice. In fact, you can use any Discord account to obtain a token since Discord does not check or enforce any security validations. All you need is an active Discord account and a Discord token for that account - see how to obtain Discord token. You may configure multiple Discord tokens to spread the load and avoid Discord 429 response codes. However, this is a theoretical safety measure as I have yet to encounter a 429 code, even with a single Discord account. It appears that Discord does not throttle attachment refresh API calls at this point.

Discord attachments use one of the following formats:

Where expire_date and issued_on values are unix/epoch hex timestamps, here's convertor to human-readable format.

Midjourney and Pika AI bots will convert the original attachment links as follows:

  • your_website_root_url/ailabs/discord_cdn/cdn.discordapp.com/attachments/channel/message/attachment_file_name?ext=file_ext&ex=expire_date&is=issued_on&hm=check_sum
  • your_website_root_url/ailabs/discord_cdn/media.discordapp.net/attachments/channel/message/attachment_file_name?ext=file_ext&ex=expire_date&is=issued_on&hm=check_sum

Example of original attachment link (this link will likely expire by the time you read this) and adjusted Discord CDN smart proxy link (this link will be auto-refreshed by the Discord CDN smart proxy running at https://privet.fun).

Configuration steps:

  • Create a new board user who will act as an AI placeholder bot, for our example we will use the user DiscordCDN. Make sure this user account is NOT active as we only need this account as a placeholder.
  • Go to ACP > Extensions > AI Labs > Settings and add new configuration, select discord_cdn from AI dropdown:
    Attachment settings
    • Use Load default configuration/template to get defaults.
      Replace Configuration JSON required_discord_token_a with Discord token used by Midjourney and Pika AI bots or by any other active Discord token.
      Optionally you can add more Discord tokens, see optional_discord_token_b and optional_discord_token_c or delete both optional_discord_token_... if you're not planing to use them.
    • Update the channels array to include Discord channels from which you want to proxy Discord CDN attachment links. These should be the same Discord channels as the ones configured for the Midjourney and Pika AI bots and any other channels you optionally want to add. The channels array acts as a security measure to prevent third parties from using your proxy for their own needs.
    • Specify ALL for Quote or mention, this is not really used.

To verify that your setup is working ask the Midjourney or Pika AI bot to generate something.
Alternatively you can take a valid Discord CDN link and paste it to you browser as your_website_root_url/ailabs/discord_cdn/cdn.discordapp.com/attachments/channel/message/attachment_file_name?ext=file_ext, if Discord CDN smart proxy is configured properly it will refresh new then link and redirect your browser to that link.

If you had a version of this extension installed prior to v1.0.10, you likely already have expired Discord CDN links. Below are handy SQL statements to update your MySQL/MariaDB database to use the Discord CDN smart proxy link format. Run them one at a time and please make sure to take a backup before you make any changes.

To get rough idea how many posts will be affected:

SELECT count(*)
FROM <you_prefix>_posts
WHERE post_text LIKE "%https://media.discordapp.net/attachments/%" OR post_text LIKE "%https://cdn.discordapp.com/attachments/%"

Update posts:

UPDATE <you_prefix>_posts
SET post_text = REGEXP_REPLACE(post_text, 
                               'https://media\\.discordapp\\.net/attachments/([0-9]+)/([0-9]+)/([^.]+)\\.([A-Za-z0-9]+)(\\?ex=)?', 
                               '<your_website_root_url>/ailabs/discord_cdn/media.discordapp.net/attachments/\\1/\\2/\\3?ext=\\4&amp;ex=')
WHERE post_text LIKE "%https://media.discordapp.net/attachments/%"
UPDATE <you_prefix>_posts
SET post_text = REGEXP_REPLACE(post_text, 
                               'https://cdn\\.discordapp\\.com/attachments/([0-9]+)/([0-9]+)/([^.]+)\\.([A-Za-z0-9]+)(\\?ex=)?', 
                               '<your_website_root_url>/ailabs/discord_cdn/cdn.discordapp.com/attachments/\\1/\\2/\\3?ext=\\4&amp;ex=')
WHERE post_text LIKE "%https://cdn.discordapp.com/attachments/%"

Gemini setup

  • Please follow the Google instructions to create and activate a Gemini API key in Google AI Studio.
    Note the Gemini API key you create, you will need it later to set up the Gemini and Gemini Vision bots.

  • Create a new board user who will act as the AI bot; for our example, we will use the user Gemini.
    Ensure this user account is activated and fully functional.

  • Go to ACP > Extensions > AI Labs > Settings and add a new configuration, selecting gemini from the AI dropdown:

    • Use Load default configuration/template to load the defaults.
      Replace <API-KEY> in the Configuration JSON with your Gemini API key.
    • Select the forums where you want the Gemini AI user to reply to new posts and/or to quoted and @mention posts (if you are using the Simple Mentions extension).
  • Save the changes, navigate to the forum configured above, and create a new post (if you configured Reply on a post) or quote/@mention the Gemini user to verify that it is working as expected. Refer to the troubleshooting section if you encounter any issues.

  • Fine-tuning can be achieved by adjusting the following Gemini API configuration parameters:

  • Additional settings used by the Gemini API:

    • max_tokens, default 30720, this is the maximum size of the entire conversation.
    • prefix, default is empty, it can be used to prompt the model.
    • max_quote_length, if provided, the quoted response text will be truncated to the number of words defined by the max_quote_length value. Set it to 0 to remove all quoted text entirely.

For an examples of how to use Gemini bot please refer to Gemini.

Gemini Vision setup

The setup for Gemini Vision follows the same steps as the above-mentioned Gemini bot. You will need to create a separate board user, e.g. GeminiVision and select gemini_vision from the AI dropdown.

The Gemini Vision bot does not support conversations, you will need to provide a prompt along with an image every time. You can attach an image to the post or provide an image URL directly in the prompt. For an examples of how to use Gemini Vision bot please refer to Gemini Vision.

ChatGPT setup

  • You will need OpenAI account, sign up at https://platform.openai.com/.
    To obtain API key go to https://platform.openai.com/account/api-keys, click on Create new secret key, copy and save in a safe place generated API key.
    Open AI key starts with sk- and look something like this sk-rb5yW9j6Nm2kP3Fhe7CPzT1QczwDZ5LvnlBfYU2EoqyX1dWs.

  • Create new board user who will act as AI bot, for our example we will use user ChatGPT.
    Make sure this user account is activated and fully functional.

  • Go to ACP > Extensions > AI Labs > Settings and add new configuration, select chatgpt from AI dropdown:
    Attachment settings

    • Use Load default configuration/template to get defaults.
      Replace Configuration JSON api-key with your Open AI key.
    • Select forums where you want ChatGPT AI user to reply to new posts and/or to quoted and @mention (if you are using Simple mentions extension) posts.
  • Save changes, navigate to forum configured above and create new post (if you configured Reply on a post) or quote/@mention ChatGPT user:
    Attachment settings

  • Fine-tuning can be done by adjusting following OpenAI API chat parameters https://platform.openai.com/docs/api-reference/chat

  • Additional setting used by ChatGPT AI

    • max_tokens, default 4096, define size reserved for AI reply when quoted
    • prefix, default empty, can be used to prompt model, see ChatGPT advanced setup for details
    • prefix_tokens, default 0, see ChatGPT advanced setup for details
    • max_quote_length, if provided, the quoted response text will be truncated to the number of words defined by the max_quote_length value. Set it to 0 to remove all quoted text entirely.

ChatGPT advanced setup

You can setup ChatGPT to pretend it is somebody else using param prefix with custom prompt (aka system prompt).
Let's create new board user Bender and configure it same as we did in ChatGPT setup .
We want use prefix and prefix_tokens params to fine-tune ChatGPT AI behavior so our AI bot Bender will provide responses like this, mostly staying in a character.
To determine what number should be placed in prefix_tokens let's ask our freshly created AI bot Bender question which we want to use for prefix.
For example below we will use for prefix following system prompt Pretend your are Bender from Futurma
Request and response token count
Once bot replied click on log icon, and note value of Request tokens.
Finally go back to Bender AI bot configuration and update params prefix and prefix_tokens
Attachment settings

Claude setup

  • Please follow the Anthropic instructions to create and activate a Claude API key.
    Note the Claude API key you create, you will need it later to set up the Claude bot.

  • Create a new board user who will act as the AI bot. For our example, we will use the user Claude.
    Ensure this user account is activated and fully functional.

  • Go to ACP > Extensions > AI Labs > Settings and add a new configuration, selecting claude from the AI dropdown:

    • Use Load default configuration/template to load the defaults.
      Replace <API-KEY> in the Configuration JSON with your Claude API key.
    • Select the forums where you want the Claude AI user to reply to new posts and/or to quoted and @mention posts (if you are using the Simple Mentions extension).
  • Save the changes, navigate to the forum configured above, and create a new post (if you configured Reply on a post) or quote/@mention the Claude user to verify that it is working as expected. Refer to the troubleshooting section if you encounter any issues.

  • Fine-tuning can be achieved by adjusting the following Claude API configuration parameters:

  • Additional settings used by the Gemini API:

    • max_quote_length, if provided, the quoted response text will be truncated to the number of words defined by the max_quote_length value. Set it to 0 to remove all quoted text entirely.

Chat bots can share conversation history

AI chat bots (ChatGPT, Gemini and Claude) can now share each other's conversation history and context.
You can start chatting with one AI chat bot and later on in the conversation tag another bot(s).
Tagged bots will automatically inherit the entire conversation history and context.
Please see example.

DALL-E setup

Setup mostly the same as for ChatGPT above:
Attachment settings

Refer to https://platform.openai.com/docs/api-reference/images/create to learn more about n and size parameters.
Examples

DALL-E advanced features

  • To generate an image of the desired size, you can specify one of the following sizes anywhere within the prompt, example:

    • 1024x1024
    • 512x512
    • 256x256
  • To create variations of the image simply post image url to the prompt, example

Stable Diffusion setup

Troubleshooting

  • AI Labs extension maintains internal logs, you should have admin or moderator rights to see log icon
    Attachment settings

    You can see entire AI communication history in the log:
    Attachment settings
    If Log entry is empty it usually means that /ailabs/* or /app.php/ailabs/* routes blocked by one of phpBB extensions (eg Login Required) and you will need to add /ailabs/* or /app.php/ailabs/* to extension whitelist.
    You can examine Log response (JSON) to see details for AI response.
    Please feel free to post your questions or concerns at https://github.com/privet-fun/phpbb_ailabs/issues.

  • When setting up your bot, you will be able to test the bot URL by referring to the Bot URL (test) link below

    If you do not see the bot response Processing job 0, you will need to investigate what is preventing access to that URL, your web server logs will be good place to start.

  • You can enable cURL communication logging by adding the "debug": true parameter to your bot configuration. The AI Labs extension uses cURL to communicate with AI APIs. By enabling logging, you should be able to see the entire data exchange between the extension and the AI APIs. Look for /var/www/phpbb/curl_debug.txt (or similar) for log content.
    Attachment settings

Support and suggestions

This extension is currently being actively developed. For communication, please use https://github.com/privet-fun/phpbb_ailabs/issues.

Changelog

  • 1.0.10 May 5, 2024

  • 1.0.9 April 17, 2024

    • Added support for Pika by Pika.art AI text/text+image to video bot
    • Added support for Claude by Anthropic
    • AI chat bots (ChatGPT, Gemini and Claude) can now share each other's conversation history and context example
    • The troubleshooting features have been greatly extended
    • You can edit the original conversation after it has been posted and add more @mention AI bot tags if you missed them example
    • Created small update for Simple mentions phpBB extension version 2.0 to support notifications when editing an already submitted post. Refer to Important notes for details
  • 1.0.8 March 10, 2024

  • 1.0.7 December 26, 2023

    • Updated the Midjourney Bot to support the v2 API from https://useapi.net
      Make sure to update your Midjourney bot configuration:
        "url_imagine": "https://api.useapi.net/v2/jobs/imagine",
        "url_button": "https://api.useapi.net/v2/jobs/button",
      
    • All messages and warnings from the Midjourney Bot will now be relayed back
    • Custom Zoom support added
    • Added support for Midjourney v6, including quoted text and new buttons
  • 1.0.6 October 7, 2023

    • Minor internal changes to address phpBB extension certification
  • 1.0.5 October 1, 2023

    • Midjourney support added
    • max_quote_length option added for ChatGPT
  • 1.0.4 June 4, 2023

    • Troubleshooting section added
    • Added configuration for reply in topics
    • Fixed links generation for cases where cookies disabled
    • AI Labs internal controllers (/ailabs/*) will attempt to establish session to deal with phpBB extensions like Login Required
    • Better descriptions added to help with setup
    • Minor bugfixes
  • 1.0.3 June 1, 2023

    • bumped php requirements to >= 7.4
    • Comma removed, reported by Vlad__
  • 1.0.2 June 1, 2023

    • Only apply utf8_encode_ucr if present, reported by Vlad__
      This will allow phpBB 3.2.1 support without any modifications.
    • Removed ... and array to support php 7.x, reported by Vlad__
    • Added missing reply processing for chatgpt controller, reported by Vlad__
    • Added board prefix to all links, reported by Miri4ever
  • 1.0.1 May 29, 2023

    • Fixed issues reported by Miri4ever
    • Removed all MySQL specific SQL, going forward extension should be SQL server agnostic
    • Better language management
    • Minor code cleanup
  • 1.0.0 May 28, 2023

    • Public release

License

GPLv2

About

phpBB extension for Midjourney, ChatGPT and DALL-E (OpenAI), Gemini and Gemini Vision (Google), Claude (Anthropic), Stable Diffusion (Stability AI), Pika (Pika.art)

https://privet.fun


Languages

Language:PHP 91.6%Language:HTML 8.0%Language:CSS 0.4%