borah / knowledge-base-laravel
Laravel wrapper for the Knowledge-Base API
Fund package maintenance!
BorahLabs
Requires
- php: ^8.1
- illuminate/contracts: ^10.0|^11.0
- spatie/laravel-package-tools: ^1.16.4
Requires (Dev)
- larastan/larastan: ^2.0.1
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- orchestra/testbench: ^8.8
- pestphp/pest: ^2.20
- 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-11-04 12:39:10 UTC
README
This package is a Laravel wrapper for the Knowledge Base API. It will create and maintain a Knowledge Base for all the configured Eloquent models.
Installation
You can install the package via composer:
composer require borah/knowledge-base-laravel
You must publish the migrations:
php artisan vendor:publish --tag="knowledge-base-laravel-migrations"
After the migration has been published you can run them using php artisan migrate
.
Also, if you want, you can publish the config file with:
php artisan vendor:publish --tag="knowledge-base-laravel-config"
This is the contents of the published config file:
return [ 'connection' => [ 'host' => env('KNOWLEDGE_BASE_HOST', 'http://localhost:8100'), ], 'models' => [ 'knowledge_base_id' => \Borah\KnowledgeBase\Models\KnowledgeBaseId::class, ], ];
Requirements
This package is a wrapper for Knowledge Base API, so you need to have it running in order to use this package.
Usage
To use it, you need to add the Borah\KnowledgeBase\Traits\HasKnowledgeBase
trait to the models you want to add to the Knowledge Base. Also, these models should implement the Borah\KnowledgeBase\Contracts\Embeddable
interface.
For example:
<?php namespace App\Models; use Borah\KnowledgeBase\Contracts\Embeddable; use Borah\KnowledgeBase\DTO\KnowledgeEmbeddingText; use Borah\KnowledgeBase\Traits\BelongsToKnowledgeBase; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; class Post extends Model implements Embeddable { use HasFactory; use BelongsToKnowledgeBase; public function getEmbeddingsTexts(): KnowledgeEmbeddingText|array { return [ new KnowledgeEmbeddingText( text: $this->content, entity: class_basename($this), ), ]; } }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.