hudhaifas/silverstripe-gpt-actions
Composer 安装命令:
composer require hudhaifas/silverstripe-gpt-actions
包简介
Expose secure server-side actions to ChatGPT via OpenAPI and expirable API keys.
README 文档
README
Expose your custom server-side logic to GPTs and AI clients via secure, structured endpoints.
The silverstripe-gpt-actions module allows you to define and expose server-side actions through a secure HTTP interface for integration with custom GPTs (ChatGPT plugins) or other AI tools.
It supports:
- Custom GET endpoints per action
- OpenAPI schema generation (
/gpt/openapi) for easy GPT integration - Secure access using expirable API keys
- CMS management of API keys
- Google Analytics 4 (GA4) usage tracking (optional)
- Developer-friendly action registration and manifest system
✅ Requires SilverStripe 4.10+ or 5.x
📦 Installation
composer require hudhaifas/silverstripe-gpt-actions
Enable the module in your SilverStripe project, then run:
vendor/bin/sake dev/build flush=1
🧠 Use Cases
This module is ideal for:
- Enabling GPTs to access domain-specific actions directly
- Exposing structured data and tools to AI models
- Creating secure and discoverable AI endpoints
- Tracking GPT usage analytics via GA4
🧩 Defining Actions
Create a PHP class implementing a run() static function and a describe() static method:
namespace MyApp\GPTActions; use Exception; class GetEntityByIDAction { public static function run(array $parameters) { if (!isset($parameters['EntityID'])) { throw new Exception("Missing parameter: EntityID"); } $entity = MyEntity::get_by_id($parameters['EntityID']); return [ 'ID' => $entity->ID, 'Name' => $entity->Name, 'Details' => $entity->Details ]; } public static function describe(): array { return [ 'name' => 'GetEntityByID', 'description' => 'Retrieve an entity by its unique ID.', 'parameters' => [ 'EntityID' => [ 'type' => 'integer', 'required' => true, 'description' => 'The numeric ID of the entity' ], ], ]; } }
The
describe()method is used to auto-generate OpenAPI documentation.
⚙️ Registering Actions
Register actions in your YAML config (e.g., app/_config/gpt-actions.yml):
GptActions\Util\GPTActionRegistry: available_actions: GetEntityByID: MyApp\GPTActions\GetEntityByIDAction SearchEntities: MyApp\GPTActions\SearchEntitiesAction
🌐 Available Endpoints
GET /gpt/action/{ActionName}?param1=value1&...
Invokes a specific action. Example:
GET /gpt/action/GetEntityByID?EntityID=123
Authorization: Bearer YOUR_API_KEY
GET /gpt/openapi
Returns a dynamic OpenAPI 3.1 JSON schema for all registered actions.
🔐 API Key Authentication
Manage API keys from the CMS under the GPT Keys section.
Each key:
- Is a 64-character token
- Can be linked to a
Member - Can expire and/or be deactivated
- Inherits the same permissions and access scope as the linked
Member
Authentication Methods:
- ✅ Recommended:
Authorization: Bearer YOUR_KEY - 🧪 Testing only:
?key=YOUR_KEY
🛡️ Request Authentication
The module uses the GPTAuthenticator class to validate incoming requests.
Internally, each request to /gpt/* is authenticated via the controller’s init() method:
if (!GPTAuthenticator::authenticate($this->getRequest())) { return $this->httpError(401, 'Unauthorized GPT access'); }
You may reuse the GPTAuthenticator::authenticate() method anywhere in your project.
⚙️ SiteConfig Integration
To customize OpenAPI schema metadata and enable analytics, the module extends SiteConfig with:
| Field | Purpose |
|---|---|
GPTActionTitle |
Appears in OpenAPI info.title |
GPTActionDescription |
Appears in OpenAPI info.description |
GPTAnalyticsMeasurementID |
GA4 Measurement ID |
GPTAnalyticsAPISecret |
GA4 API Secret |
All can be set from the CMS Settings UI.
📈 GPT Usage Analytics (Optional)
If configured via SiteConfig, the module will send usage events to Google Analytics 4 (GA4) using the [Measurement Protocol].
Tracked event: gpt_action_called
Event parameters:
| Param | Example | Description |
|---|---|---|
action_name |
GetEntityByID | Name of the called action |
success |
true/false |
Whether the action succeeded |
📋 Example OpenAPI Output
{
"openapi": "3.1.0",
"info": {
"title": "My Custom GPT",
"description": "Custom actions exposed for GPT integration.",
"version": "1.0.0"
},
"paths": {
"/gpt/action/GetEntityByID": {
"get": {
"summary": "Retrieve an entity by ID.",
"parameters": [
{
"name": "EntityID",
"in": "query",
"required": true,
"schema": { "type": "integer" }
}
]
}
}
}
}
🧪 Testing Endpoints
fetch('https://yourdomain.com/gpt/action/GetEntityByID?EntityID=123', { headers: { Authorization: 'Bearer YOUR_KEY' } }) .then(res => res.json()) .then(console.log);
🤖 Creating a Custom GPT
You can easily create a ChatGPT plugin (Custom GPT) that consumes the OpenAPI spec exposed at /gpt/openapi.
👉 See docs/CustomGPT.md for a walkthrough on publishing your GPT on ChatGPT.com.
📜 License
MIT
✍️ Maintainer
Hudhaifa – amlineage.com
hudhaifas/silverstripe-gpt-actions 适用场景与选型建议
hudhaifas/silverstripe-gpt-actions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 353 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bot」 「silverstripe」 「openai」 「ChatGpt」 「gpt」 「genai」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hudhaifas/silverstripe-gpt-actions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hudhaifas/silverstripe-gpt-actions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hudhaifas/silverstripe-gpt-actions 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dialogflow php sdk
PHP 8.0+ OpenAI API client with fully typed/documented requests+responses models, guzzle and symfony/http-client support and async/parallel requests.
Laravel 5.6 Monolog custom telegram channel
Analytics chooser extensions for site settings.
Estimate AI API costs before making expensive calls
统计信息
- 总下载量: 353
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-27