Available Tools
List Files: Lists all files and subdirectories in a specified path.
Read File: Reads content from an existing file at the specified path.
Update File: Updates the content of an existing file at the specified path.
Write To File: Writes content to an existing file.
Execute Command: Executes a terminal command and returns the output. Use this when you need to execute a terminal command like git and other framework commands.
Custom Tools
To add a custom tool, follow these steps:
- Create a new PHP file for the custom tool in the Tools directory.
- Implement the functionality of the custom tool in the PHP file.
- Use the tool as needed in the project.
Sample PHP Code:
php
<?php
namespace App
tools;
use App
ttributes
description;
use function Termwind
ender;
#[Description('List all files and sub directories in the specified path. Use this when you need to list all files and directories.')]
final class ListFiles
{
public function handle(
#[Description('directory name to list files from. Default is the base path.')]
string $path,
): string {
// Your custom logic here
}
}
?>
Register the Custom Tool
To use the custom tool in ChatAssistant, follow these steps:
- Import the custom tool file inside the
ChatAssistant
file. - Pass the custom tool through
RegisterTool
code in the constructor ofChatAssistant
.
php
// Import the custom tool file inside ChatAssistant
use App
tools
deiles;
class ChatAssistant {
// Other code
public function __construct()
{
$this->client = OpenAI::client(config('dexor.api_key'));
// register the tools
$this->register([
CreateFile::class,
UpdateFile::class,
ListFiles::class,
ReadFile::class,
// Add your custom tool here
CustomTool::class,
]);
}
}