|
| 1 | + |
| 2 | + |
| 3 | +# AI Product Introduction Generator for Laravel |
| 4 | + |
| 5 | +## 🚀 Leverage AI API to generate engaging product introductions for E-commerce applications. |
| 6 | + |
| 7 | +[](https://packagist.org/packages/sharpapi/laravel-ecommerce-product-intro) |
| 8 | +[](https://packagist.org/packages/sharpapi/laravel-ecommerce-product-intro) |
| 9 | + |
| 10 | +Check the details at SharpAPI's [E-commerce API](https://sharpapi.com/en/catalog/ai/e-commerce) page. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## Requirements |
| 15 | + |
| 16 | +- PHP >= 8.1 |
| 17 | +- Laravel >= 9.0 |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | +Follow these steps to install and set up the SharpAPI Laravel Product Introduction Generator package. |
| 24 | + |
| 25 | +1. Install the package via `composer`: |
| 26 | + |
| 27 | +```bash |
| 28 | +composer require sharpapi/laravel-ecommerce-product-intro |
| 29 | +``` |
| 30 | + |
| 31 | +2. Register at [SharpAPI.com](https://sharpapi.com/) to obtain your API key. |
| 32 | + |
| 33 | +3. Set the API key in your `.env` file: |
| 34 | + |
| 35 | +```bash |
| 36 | +SHARP_API_KEY=your_api_key_here |
| 37 | +``` |
| 38 | + |
| 39 | +4. **[OPTIONAL]** Publish the configuration file: |
| 40 | + |
| 41 | +```bash |
| 42 | +php artisan vendor:publish --tag=sharpapi-ecommerce-product-intro |
| 43 | +``` |
| 44 | + |
| 45 | +--- |
| 46 | +## Key Features |
| 47 | + |
| 48 | +- **AI-Powered Product Introduction Generation**: Efficiently create engaging product descriptions for your e-commerce platform. |
| 49 | +- **Multi-language Support**: Generate product introductions in multiple languages. |
| 50 | +- **Customizable Length**: Control the length of the generated product introduction. |
| 51 | +- **Voice Tone Control**: Set your preferred writing style for the product introduction. |
| 52 | +- **Robust Polling for Results**: Polling-based API response handling with customizable intervals. |
| 53 | +- **API Availability and Quota Check**: Check API availability and current usage quotas with SharpAPI's endpoints. |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +## Usage |
| 58 | + |
| 59 | +You can inject the `EcommerceProductIntroService` class to access product introduction generation functionality. For best results, especially with batch processing, use Laravel's queuing system to optimize job dispatch and result polling. |
| 60 | + |
| 61 | +### Basic Workflow |
| 62 | + |
| 63 | +1. **Dispatch Job**: Send product data to the API using `generateProductIntro`, which returns a status URL. |
| 64 | +2. **Poll for Results**: Use `fetchResults($statusUrl)` to poll until the job completes or fails. |
| 65 | +3. **Process Result**: After completion, retrieve the results from the `SharpApiJob` object returned. |
| 66 | + |
| 67 | +> **Note**: Each job typically takes a few seconds to complete. Once completed successfully, the status will update to `success`, and you can process the results as JSON, array, or object format. |
| 68 | +
|
| 69 | +--- |
| 70 | + |
| 71 | +### Controller Example |
| 72 | + |
| 73 | +Here is an example of how to use `EcommerceProductIntroService` within a Laravel controller: |
| 74 | + |
| 75 | +```php |
| 76 | +<?php |
| 77 | + |
| 78 | +namespace App\Http\Controllers; |
| 79 | + |
| 80 | +use GuzzleHttp\Exception\GuzzleException; |
| 81 | +use SharpAPI\EcommerceProductIntro\EcommerceProductIntroService; |
| 82 | + |
| 83 | +class ProductController extends Controller |
| 84 | +{ |
| 85 | + protected EcommerceProductIntroService $productIntroService; |
| 86 | + |
| 87 | + public function __construct(EcommerceProductIntroService $productIntroService) |
| 88 | + { |
| 89 | + $this->productIntroService = $productIntroService; |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * @throws GuzzleException |
| 94 | + */ |
| 95 | + public function generateProductIntro(string $productData) |
| 96 | + { |
| 97 | + $statusUrl = $this->productIntroService->generateProductIntro( |
| 98 | + $productData, |
| 99 | + 'English', // optional language |
| 100 | + 300, // optional maximum length |
| 101 | + 'Enthusiastic' // optional voice tone |
| 102 | + ); |
| 103 | + |
| 104 | + $result = $this->productIntroService->fetchResults($statusUrl); |
| 105 | + |
| 106 | + return response()->json($result->getResultJson()); |
| 107 | + } |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +### Handling Guzzle Exceptions |
| 112 | + |
| 113 | +All requests are managed by Guzzle, so it's helpful to be familiar with [Guzzle Exceptions](https://docs.guzzlephp.org/en/stable/quickstart.html#exceptions). |
| 114 | + |
| 115 | +Example: |
| 116 | + |
| 117 | +```php |
| 118 | +use GuzzleHttp\Exception\ClientException; |
| 119 | + |
| 120 | +try { |
| 121 | + $statusUrl = $this->productIntroService->generateProductIntro('Sony PlayStation 5 with 1TB SSD', 'English', 300); |
| 122 | +} catch (ClientException $e) { |
| 123 | + echo $e->getMessage(); |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +--- |
| 128 | + |
| 129 | +## Optional Configuration |
| 130 | + |
| 131 | +You can customize the configuration by setting the following environment variables in your `.env` file: |
| 132 | + |
| 133 | +```bash |
| 134 | +SHARP_API_KEY=your_api_key_here |
| 135 | +SHARP_API_JOB_STATUS_POLLING_WAIT=180 |
| 136 | +SHARP_API_JOB_STATUS_USE_POLLING_INTERVAL=true |
| 137 | +SHARP_API_JOB_STATUS_POLLING_INTERVAL=10 |
| 138 | +SHARP_API_BASE_URL=https://sharpapi.com/api/v1 |
| 139 | +``` |
| 140 | + |
| 141 | +--- |
| 142 | + |
| 143 | +## Product Introduction Data Format Example |
| 144 | + |
| 145 | +```json |
| 146 | +{ |
| 147 | + "data": { |
| 148 | + "type": "api_job_result", |
| 149 | + "id": "fb0a5ab0-54fe-4283-9a33-ac491962c778", |
| 150 | + "attributes": { |
| 151 | + "status": "success", |
| 152 | + "type": "ecommerce_product_intro", |
| 153 | + "result": { |
| 154 | + "product_intro": "Experience unparalleled gaming with the Razer Blade 16, featuring NVIDIA RTX 4090, 13th Gen Intel i9, dual-mode 4K/FHD display, 32GB RAM, 2TB SSD, and a compact GaN charger." |
| 155 | + } |
| 156 | + } |
| 157 | + } |
| 158 | +} |
| 159 | +``` |
| 160 | + |
| 161 | +--- |
| 162 | + |
| 163 | +## Support & Feedback |
| 164 | + |
| 165 | +For issues or suggestions, please: |
| 166 | + |
| 167 | +- [Open an issue on GitHub](https://github.com/sharpapi/laravel-ecommerce-product-intro/issues) |
| 168 | +- Join our [Telegram community](https://t.me/sharpapi_community) |
| 169 | + |
| 170 | +--- |
| 171 | + |
| 172 | +## Changelog |
| 173 | + |
| 174 | +Please see [CHANGELOG](CHANGELOG.md) for a detailed list of changes. |
| 175 | + |
| 176 | +--- |
| 177 | + |
| 178 | +## Credits |
| 179 | + |
| 180 | +- [A2Z WEB LTD](https://github.com/a2zwebltd) |
| 181 | +- [Dawid Makowski](https://github.com/makowskid) |
| 182 | +- Enhance your [Laravel AI](https://sharpapi.com/) capabilities! |
| 183 | + |
| 184 | +--- |
| 185 | + |
| 186 | +## License |
| 187 | + |
| 188 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
| 189 | + |
| 190 | +--- |
| 191 | + |
| 192 | +## Follow Us |
| 193 | + |
| 194 | +Stay updated with news, tutorials, and case studies: |
| 195 | + |
| 196 | +- [SharpAPI on X (Twitter)](https://x.com/SharpAPI) |
| 197 | +- [SharpAPI on YouTube](https://www.youtube.com/@SharpAPI) |
| 198 | +- [SharpAPI on Vimeo](https://vimeo.com/SharpAPI) |
| 199 | +- [SharpAPI on LinkedIn](https://www.linkedin.com/products/a2z-web-ltd-sharpapicom-automate-with-aipowered-api/) |
| 200 | +- [SharpAPI on Facebook](https://www.facebook.com/profile.php?id=61554115896974) |
0 commit comments