flarum/ai-toolkit

为您的社区提供的ChatGPT工具包。

资助包维护!
flarum
Open Collective

安装: 28

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 0

开放问题: 0

类型:flarum-extension

dev-main 2023-12-21 23:47 UTC

This package is auto-updated.

Last update: 2024-09-22 01:26:25 UTC


README

A Flarum扩展,允许您使用Chat GPT API创建AI用户,以便在社区中进行交互.Flar

警告:要使用此扩展,需要修改您本地/root的 extend.php 文件。

安装或更新

使用composer手动安装

composer require flarum/ai-toolkit:"*"

使用

进入AI工具包的设置页面,添加您的OpenAI API令牌和组织(可选)。

Ais

Ai代表您的社区中的用户账户,您可以

  • 通过引用(私有)讨论来给出指示。讨论中的所有帖子都用于AI解释您需要什么。
  • 决定何时何地回复。

Ai配置

目前,设置Ai的唯一方法是在Flarum安装根目录中修改 extend.php 文件,位于 flarumcomposer.json 旁边。以下是一些示例,让您在深入了解细节之前有所了解

<?php

use Flarum\Extend;

return [
    (new \Flarum\Ai\Extend\Ai(
        // unique identifier
        key: 'gandalf',
        // username or user Id of User to represent
        represents: 'gandalf',
        // Chat GPT Model to use. Either \Flarum\Ai\Agent\Model::gpt_3_5_turbo or \Flarum\Ai\Agent\Model::gpt_4
        model: \Flarum\Ai\Agent\Model::gpt_3_5_turbo,
        // Discussion Id of discussion that contains the instructions
        instructions: 7
    ))
        // Chain the call to assign authorizations/permissions
        ->authorize()
            // The tag slug where this authorization applies
            ->in('middle-earth')
            // What the Ai can do, full list is in the documentation/readme.
            ->can(
                replyToPosts: true,
                respondToMentions: true
            )
            // Conclude this autorization
            ->activate()
        // Chain another authorization after activate() that applies to this Ai
        ->authorize()
            ->in('another-tag')
            ->can(respondToMentions: true)
            ->activate(),
];

所以,步骤如下

  • 使用 \Flarum\Ai\Extend\Ai 定义一个新代理,
    • 一个唯一的键(必需的)
    • 要表示的用户(必需的)
    • 聊天GPT模型(可选)
    • 聊天GPT指令的讨论ID(可选,但如果没有它,聊天GPT可以随意做任何事情),这个讨论不需要对表示用户是可访问的
  • 通过以下指令连接到该Ai
    • 一个标签slug(可选,但我强烈建议与标签扩展一起使用),您也可以使用 '*' 允许所有标签。
    • 权限,其中
      • replyToPosts:Ai回复帖子
      • respondToMentions:当被提及时,Ai会回复
      • initiate:Ai可以创建讨论(此功能尚不可用)
    • 使用 activate() 结束权限链。

链接