iazaran / ai-insights
利用AI分析数据并获取洞察,以改善您的业务特定领域
v1.2.0
2024-09-20 18:32 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- laravel/framework: ^11.0
README
使用AI LLMs分析数据并获取洞察和图表,以改善您的业务特定领域。默认LLM是OpenAI,但您也可以使用其他LLM。
要求
- PHP >=8.1
- Laravel >= 10
开始使用
通过Composer包管理器安装 iazaran/ai-insights
composer require iazaran/ai-insights
可选,发布配置文件
php artisan vendor:publish --provider="AIInsights\Providers\AIInsightsServiceProvider"
设置.env配置。您可以从这里获取您的OpenAI API密钥。其他配置为可选。
AI_BASE_URL="" AI_CHAT_PATH="" AI_IMAGE_PATH="" AI_API_KEY="" AI_ORGANIZATION="" AI_PROJECT="" AI_MODEL="" AI_IMAGE_MODEL="" AI_MAX_TOKENS="" AI_TEMPERATURE="" AI_INSIGHTS_DEFAULT_GOAL="" AI_IMAGE_SIZE=""
使用AIInsightsProcessor类分析您的数据。默认情况下,它将使用您的数据库中的最后几行
$businessType = 'Retail'; $goal = 'Increase sales'; $tables = ['orders', 'products']; $limit = 5; $insights = AIInsightsProcessor::analyze($businessType, $goal, $tables, $limit);
如果使用OpenAI,样本响应可能如下所示
[
'insights' => [
[
'index' => 0,
'message' => [
'role' => 'assistant',
'content' => "Based on the provided data from the 'orders' and 'products' tables, here are some insights to improve your Retail business and increase sales:\n\n1. Focus on promoting high-margin products: The data shows that Product A has a higher profit margin compared to other products. Consider running targeted marketing campaigns for this item.\n2. Implement a loyalty program: Analyzing customer purchase history reveals repeat buyers. Introduce a loyalty program to incentivize these customers and encourage more frequent purchases.\n3. Optimize inventory management: The product data indicates some items have low stock levels. Ensure popular products are always available to avoid missing sales opportunities.\n4. Personalize marketing efforts: Use customer order history to create personalized product recommendations, potentially increasing cross-selling and upselling."
],
'finish_reason' => 'stop',
],
],
'charts' => [
[
'url' => 'https://oaidalleapiprodscus.blob.core.windows.net/private/org-123456/user-123456/img-abcdef.png'
],
]
]