laravelailabs/file-assistant

Chat with files using AI

0.0.12 2024-01-30 15:24 UTC

This package is auto-updated.

Last update: 2024-03-30 07:17:49 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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

  • PDF
  • 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.