tactical/laravel-open-ai-tools 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tactical/laravel-open-ai-tools

Composer 安装命令:

composer require tactical/laravel-open-ai-tools

包简介

README 文档

README

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);

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-04-13