Skip to content

tacticalsoftware/laravel-open-ai-tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Open AI Tools

This is a small collection of tools we've used to build complex Open AI based applications. It may expand as we find more things the excellent underlying libraries don;t make easy enough out the box.

composer require tactical/laravel-open-ai-tools

At its core, the heavy lifting is done with invocable actions:

  • Tactical\OpenAiTools\Actions\Assistants\EnsureAssistantAction
  • Tactical\OpenAiTools\Actions\Assistants\StreamAssistantResponseAction
  • Tactical\OpenAiTools\Actions\Assistants\UpdateAssistantAction
  • Tactical\OpenAiTools\Actions\KnowledgeBase\DeleteUnlinkedFilesAction
  • Tactical\OpenAiTools\Actions\KnowledgeBase\DeleteVectorStoreAction
  • Tactical\OpenAiTools\Actions\KnowledgeBase\EmptyVectorStoreAction
  • Tactical\OpenAiTools\Actions\KnowledgeBase\EnsureVectorStoreAction
  • Tactical\OpenAiTools\Actions\KnowledgeBase\RenameVectorStoreAction
  • Tactical\OpenAiTools\Actions\KnowledgeBase\UploadFilesAction

These operate on a polymorphic relationship, which you can attach to any of your models:

class Project extends Model implements HasAssistant
{
    use HasAssistantConcern;
    
    // ...other nonsense
}

If a model has HasAssistant and HasAssistantConcern, then you can access a couple useful fields:

$project->assistant()->create();
$project->assistant->open_ai_assistant_id; // → null|string
$project->assistant->open_ai_vector_store_id; // → null|string

The actions use this relationship to store Open AI identifiers without polluting your models. You don't actually need to create the assistant yourself. Each action calls EnsureVectorStoreAction under the hood, which creates any missing assistant models.

You can reference these actions directly:

/** @var RenameVectorStoreAction $action */
$action = app(RenameVectorStoreAction::class);
$action($project, 'new project name');

Many assistant operations happen at the same time. For example, your application might require a complex knowledge base change:

  1. creating a vector store if it's missing
  2. saving the vector store ID to the database if just created
  3. emptying the existing vector store of uploaded files
  4. uploading a completely new set of files

This can lead to a mountain of boilerplate, and you might miss edge cases. We've made it easy to chain actions:

/** @var OpenAiToolsService $service */
$service = app(OpenAiToolsService::class);

$service
    ->with($project)
    ->action(ActionsEnum::EmptyVectorStore)
    ->action(ActionsEnum::UploadFiles, $files);

About

A collection of tools to make developing OpenAI applications easier.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages