vormkracht10 / laravel-embeddings
为您的Eloquent模型创建嵌入,以便与OpenAI一起使用
v0.0.3
2024-06-05 15:33 UTC
Requires
- php: ^8.1
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.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
This package is auto-updated.
Last update: 2024-09-08 16:05:42 UTC
README
OpenAI的文本嵌入测量文本字符串的相关性。使用此包,您可以自动保存Eloquent模型在PostgreSQL矢量数据库中的嵌入。要使用嵌入在您的AI请求中对OpenAI API端点进行操作。
安装
您可以通过composer安装此包
composer require vormkracht10/laravel-embeddings
您可以使用以下命令发布和运行迁移
php artisan vendor:publish --tag="laravel-embeddings-migrations"
php artisan migrate
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="laravel-embeddings-config"
这是已发布配置文件的内容
return [ 'enabled' => env('EMBEDDINGS_ENABLED', true), 'driver' => env('EMBEDDINGS_DRIVER', 'null'), // 'null' / 'openai' 'queue' => true, 'database' => [ 'connection' => env('EMBEDDINGS_DATABASE_CONNECTION', 'pgsql'), 'table' => env('EMBEDDINGS_DB_TABLE', 'embeddings'), ], 'openai' => [ 'key' => env('OPENAI_API_KEY'), 'model' => env('OPENAI_EMBEDDING_MODEL', 'text-embedding-ada-002') ], /* |-------------------------------------------------------------------------- | Chunk Sizes |-------------------------------------------------------------------------- | | These options allow you to control the maximum chunk size when you are | mass importing data into the embed engine. This allows you to fine | tune each of these chunk sizes based on the power of the servers. | */ 'chunk' => [ 'embeddable' => 500, 'unembeddable' => 500, ], ];
填写以下环境变量
EMBEDDINGS_DRIVER=openai OPENAI_API_KEY=
使用方法
// Add the Embeddable trait to your Model(s). class MyModel { use Embeddable { \Laravel\Scout\Searchable::usesSoftDelete insteadof \Vormkracht10\Embedding\Embeddable; } } // You can override the embeddable content class MyModel { // ... public function toEmbeddableString() { return strip_tags(implode(', ', $this->toArray())); } }
测试
composer test
更新日志
请参阅更新日志以获取有关最近更改的更多信息。
贡献
请参阅贡献指南以获取详细信息。
安全漏洞
请参阅我们的安全策略了解如何报告安全漏洞。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。