laravelailabs / file-assistant
Chat with files using AI
Requires
- php: ^8.1
- adrianmtanase/laravel-vector-store: ^0.0.24
- illuminate/contracts: ^10.0
- illuminate/filesystem: *
- openai-php/client: ^0.8.2
- phpoffice/phpword: ^1.2
- smalot/pdfparser: ^2.8
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- larastan/larastan: ^2.0.1
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- orchestra/testbench: ^8.8
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^10.5.3
- vlucas/phpdotenv: ^5.6@dev
README
Analyzes files based on AI and offers the possibility to query them.
Support us
If this helped you, consider supporting my development over on Patreon or on Github.
Demo
Repository: LaravelAILabs/file-assistant-demo
URL: https://file-assistant.laravelailabs.com
Installation
You can install the package via composer:
composer require laravelailabs/file-assistant
You can publish the config file with:
php artisan vendor:publish --tag="file-assistant-config"
Setup
Currently using Pinecone.io as the vector database and OpenAI as the LLM. Planning to make it so any LLM can be used, as well as any Vector Database implemented in Laravel Vector Store.
Add the following secrets to your .env
:
VECTOR_STORE_PINECONE_API_KEY=YOUR_PINECONE_API_KEY VECTOR_STORE_PINECONE_ENVIRONMENT=YOUR_PINECONE_ENVIRONMENT FILE_ASSISTANT_OPENAI_API_KEY=YOUR_OPENAPI_KEY FILE_ASSISTANT_PINECONE_DATASET=YOUR_PINECONE_INDEX_NAME
You can find your OpenAI API Key here.
Usage
1. Start a new conversation
$dialog = FileAssistant::addFile('PATH_TO_YOUR_FILE') ->addFile('PATH_TO_YOUR_SECOND_FILE') ->initialize(); echo $dialog->prompt('What is this document about?')
2. Resume a conversation
$dialog = FileAssistant::setConversation(Conversation::find(1)) ->setUser(Auth::user()) ->initialize(); // grab the conversation and display the messages /** * @var \LaravelAILabs\FileAssistant\Models\Conversation $conversation */ $conversation = $dialog->getConversation(); foreach ($conversation->messages as $message) { echo sprintf('%s: %s <br>', $message->role, $message->content); } echo $dialog->prompt('Where did we leave off?')
3. Grab messages and display
The package creates 3 tables: conversations
, messages
, files
, conversation_files
. Feel free to modify their names using the file-assistant config environment variables. Use the models to interact with the database and display the messages of a conversation.
Works with
- Word
- TXT
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.