md/phpspec-intelligence-extension
Composer 安装命令:
composer require md/phpspec-intelligence-extension
包简介
A PhpSpec extension to get a AI suggestion about what to spec next
README 文档
README
The PhpSpec Intelligence Extension introduces a next command to PhpSpec, leveraging OpenAI's GPT models to suggest the
next specification to implement in your test-driven development workflow.
Table of Contents
Introduction
Test-driven development (TDD) encourages writing tests before implementing code. However, deciding what to test next can sometimes be challenging. This extension integrates with OpenAI's API to analyze your existing specs and provide intelligent suggestions for the next spec to write, streamlining your TDD process.
Features
- Automated Spec Suggestions: Get suggestions for your next spec based on existing specifications.
- Seamless Integration: Adds a
nextcommand to PhpSpec without disrupting your workflow. - Configurable Parameters: Customize API settings like model, max tokens, and temperature.
Installation
Install the extension via Composer:
composer require --dev md/phpspec-intelligence-extension
Configuration
To use the extension, you need to:
- Enable the Extension: Add it to your
phpspec.ymlconfiguration file. - Set the OpenAI API Key: Provide your OpenAI API key securely.
1. Enable the Extension
Update your phpspec.yml file:
extensions: Md\PhpSpecIntelligenceExtension\Extension: openai_api_key: ~ openai_api_model: "gpt-3.5-turbo" openai_api_temperature: 0.7 openai_api_max_tokens: 256
2. Set the OpenAI API Key
For security, it's recommended to use environment variables to store your API key.
Using Environment Variables
Set the OPENAI_API_KEY environment variable in your shell or server configuration.
export OPENAI_API_KEY='your-openai-api-key'
Alternative: Configuration File (Less Secure)
You can also set the API key in the phpspec.yml file (not recommended for shared repositories):
extensions: Md\PhpSpecIntelligenceExtension\Extension: openai_api_key: 'your-openai-api-key'
Warning: Avoid committing API keys to version control.
Usage
After installation and configuration, you can use the next command:
vendor/bin/phpspec next
The command will analyze your existing specs and suggest the next one to implement.
Command Options
--config: Specify a custom configuration file.--verbose: Increase the verbosity of messages.
Example:
vendor/bin/phpspec next --config=phpspec.yml --verbose
Examples
Basic Usage
vendor/bin/phpspec next
Output:
Suggested example for: spec/Acme/MarkdownSpec.php:
function it_registers_the_next_command(ServiceContainer $container)
{
$container->define('console.commands.next',
Argument::type('Closure'),
Argument::type('array')
)->shouldBeCalled();
$this->load($container, []);
}
Would you like me to generate this spec? [Y/n]
Using a Custom Configuration File
vendor/bin/phpspec next --config=custom-phpspec.yml
Handling API Limits
If you encounter rate limits or quota issues, the command will display an appropriate error message. Ensure your OpenAI account has sufficient quota and consider implementing retry logic if needed.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Write specs for your changes.
- Submit a pull request with a detailed description.
Running Tests
vendor/bin/phpspec run
License
This project is licensed under the MIT License. See the LICENSE file for details.
Note: This extension uses the OpenAI API, which may incur costs. Monitor your usage to avoid unexpected charges. Always handle API keys securely and follow best practices to protect sensitive information.
md/phpspec-intelligence-extension 适用场景与选型建议
md/phpspec-intelligence-extension 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 4, 最近一次更新时间为 2024 年 09 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 md/phpspec-intelligence-extension 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 md/phpspec-intelligence-extension 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-23