postare / filament-model-ai
将人工智能集成到FilamentPHP中,利用您的Eloquent模型数据作为知识。
v1.1.0
2024-03-14 09:27 UTC
Requires
- php: ^8.1
- filament/filament: ^3.0
- illuminate/contracts: ^11.0
- openai-php/laravel: ^0.8
- spatie/laravel-package-tools: ^1.15.0
Requires (Dev)
- larastan/larastan: ^2.0.1
- laravel/pint: ^1.0
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^9.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-08-29 12:16:33 UTC
README
ModelAI是为FilamentPHP设计的插件,它可以与OpenAI API进行交互。其主要功能是使用现有的模型数据作为上下文来向OpenAI API发送请求。在实际应用中,它允许用户从数据模型中选择特定的记录,例如房地产或电子商务产品列表,并使用这些信息作为通过OpenAI的AI能力生成智能内容或响应的基础。
使用示例
示例 1:房地产门户网站
在房地产门户网站中,ModelAI可以利用“属性”模型的数据来创建定制营销内容。例如,通过选择特定的属性,插件可以生成优化的社交媒体帖子或识别关键属性相关点,所有这些均基于特定属性的数据。
示例 2:葡萄酒电子商务平台
在葡萄酒电子商务平台中,插件可以配置为与包含品种、年份和品鉴笔记等详细信息的“葡萄酒”模型一起工作。使用这些数据,“ModelAI”可以生成引人入胜的产品描述、美食搭配推荐,甚至关于葡萄酒文化的教育内容,同时利用OpenAI的人工智能确保内容的高质量和相关性。
安装
您可以通过Composer轻松安装此包
composer require postare/filament-model-ai
安装包后,您需要将您的OpenAI API密钥添加到您的.env
文件中
OPENAI_API_KEY=sk-...
要发布配置文件,请使用以下命令
php artisan vendor:publish --tag="filament-model-ai-config"
可选地,您还可以发布视图
php artisan vendor:publish --tag="filament-model-ai-views"
发布的配置文件包含以下设置
// Configuration for Postare/ModelAi return [ // OpenAI API Key 'openai_api_key' => env('OPENAI_API_KEY', ''), // Default OpenAI Model (refer to https://platform.openai.com/docs/models) 'default_openai_model' => 'gpt-3.5-turbo-1106', // Disable selecting OpenAI Model 'disable_openai_model_selection' => false, // Slug for the Model AI page 'slug' => 'model-ai', // Filament Navigation Group (refer to translation file for label or disable it) 'use_navigation_group' => true, // Model Settings 'eloquent_model' => \App\Models\User::class, // Laravel model to use 'selected_columns' => [ // Selected columns from the model 'name', 'email', ], 'field_label' => 'name', // Field to use as a label 'field_id' => 'id', // Field to use as an ID // System Prompt 'system_prompt' => 'You are a helpful assistant. Consider the data at the end of this message as context and answer the questions I will ask you later.', // Predefined Prompts (feel free to add, remove, or modify them) 'predefined_prompts' => [ [ 'name' => 'SEO', // Prompt name 'prompt' => 'Generate a title and an SEO-oriented meta description based on the provided data.', // Prompt instruction ], [ 'name' => 'Facebook Post', // Prompt name 'prompt' => 'Create a Facebook post, avoiding lists.', // Prompt instruction ], ], ];
请随意自定义这些设置以适应您的特定用例。享受使用ModelAI与FilamentPHP一起!
使用方法
除了在面板中有一个可以选则所需元素、模型和提示的页面外,您还可以在项目中的其他地方使用ModelAI。
$response = ModelAi::chat() // Optional: Override the default OpenAI model specified in the configuration file ->openai_model('gpt-4-1106-preview') // Optional ->system('your name is GeePeeTee, and you speak in a very 16th-century, very polished way.') // Optional, model to use: // params: model, id, selected_columns ->model(\App\Models\User::class, 1, ['name', 'email', 'email_verified_at']) // Mandatory, prompt to use: ->prompt("tell me about this user") // Mandatory, send the request ->send(); // Pray tell, thou hath sought to gain insight into the individual known by the appellation "Francesco". This gentle soul didst establish an entity of digital correspondence through "inerba@******.com", yet verily, the verification of such an electronic missive remains a quest unfulfilled. $response = ModelAi::chat() ->prompt("make up your own dad joke") ->send(); // Why don't skeletons fight each other? They don't have the guts.
特性
- OpenAI API集成
- 可自定义模型
- 可自定义提示
- FilamentPHP页面