-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from LlmLaraHub/assistant
Assistant
- Loading branch information
Showing
69 changed files
with
3,136 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
namespace LlmLaraHub\LlmDriver\Functions; | ||
|
||
use App\Models\Message; | ||
use App\Models\Task; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\Log; | ||
use LlmLaraHub\LlmDriver\Responses\FunctionResponse; | ||
|
||
class CreateTasksTool extends FunctionContract | ||
{ | ||
protected string $name = 'create_tasks_tool'; | ||
|
||
protected string $description = 'If the Campaign needs to have tasks created or the users prompt requires it you can use this tool to make multiple tasks'; | ||
|
||
public bool $showInUi = true; | ||
|
||
public array $toolTypes = [ | ||
ToolTypes::Source, | ||
ToolTypes::Output, | ||
ToolTypes::Chat, | ||
ToolTypes::ChatCompletion, | ||
]; | ||
|
||
public function handle( | ||
Message $message): FunctionResponse | ||
{ | ||
Log::info('TaskTool called'); | ||
|
||
$args = $message->args; | ||
foreach (data_get($args, 'tasks', []) as $taskArg) { | ||
$name = data_get($taskArg, 'name', null); | ||
$details = data_get($taskArg, 'details', null); | ||
$due_date = data_get($taskArg, 'due_date', null); | ||
$assistant = data_get($taskArg, 'assistant', false); | ||
$user_id = data_get($taskArg, 'user_id', null); | ||
|
||
$project = $message->chat->getChatable(); | ||
|
||
Task::updateOrCreate([ | ||
'name' => $name, | ||
'project_id' => $project->id, | ||
], | ||
[ | ||
'details' => $details, | ||
'due_date' => $due_date, | ||
'assistant' => $assistant, | ||
'user_id' => ($user_id !== '' && User::whereId($user_id)->exists()) ? $user_id : null, | ||
]); | ||
} | ||
|
||
return FunctionResponse::from([ | ||
'content' => json_encode($args), | ||
]); | ||
} | ||
|
||
/** | ||
* @return PropertyDto[] | ||
*/ | ||
protected function getProperties(): array | ||
{ | ||
return [ | ||
new PropertyDto( | ||
name: 'tasks', | ||
description: 'Array of task objects', | ||
type: 'array', | ||
required: true, | ||
properties: [ | ||
new PropertyDto( | ||
name: 'items', | ||
description: 'Task object', | ||
type: 'object', | ||
required: true, | ||
properties: [ | ||
new PropertyDto( | ||
name: 'name', | ||
description: 'Name of the task', | ||
type: 'string', | ||
required: true | ||
), | ||
new PropertyDto( | ||
name: 'details', | ||
description: 'Detailed info of the task', | ||
type: 'string', | ||
required: true | ||
), | ||
new PropertyDto( | ||
name: 'due_date', | ||
description: 'Due date if any format "Y-m-d"', | ||
type: 'string', | ||
required: true | ||
), | ||
new PropertyDto( | ||
name: 'assistant', | ||
description: 'Should the assistant be assigned this true or false', | ||
type: 'string', | ||
), | ||
new PropertyDto( | ||
name: 'user_id', | ||
description: 'User id if assigned to a user', | ||
type: 'string', | ||
), | ||
] | ||
), | ||
] | ||
), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace LlmLaraHub\LlmDriver\Tests\Feature; | ||
|
||
use App\Models\Chat; | ||
use App\Models\Message; | ||
use App\Models\Project; | ||
use LlmLaraHub\LlmDriver\Functions\CreateTasksTool; | ||
use Tests\TestCase; | ||
|
||
class CreateTasksToolTest extends TestCase | ||
{ | ||
/** | ||
* A basic feature test example. | ||
*/ | ||
public function test_generates_tasks(): void | ||
{ | ||
$project = Project::factory()->create(); | ||
$chat = Chat::factory()->create([ | ||
'chatable_id' => $project->id, | ||
'chatable_type' => Project::class, | ||
]); | ||
|
||
$data = get_fixture('claude_chat_response.json'); | ||
|
||
$data = data_get($data, 'tool_calls.1.arguments.tasks'); | ||
|
||
$message = Message::factory()->create([ | ||
'chat_id' => $chat->id, | ||
'args' => [ | ||
'tasks' => $data, | ||
], | ||
]); | ||
|
||
$this->assertDatabaseCount('tasks', 0); | ||
|
||
(new CreateTasksTool())->handle($message); | ||
|
||
$this->assertDatabaseCount('tasks', 5); | ||
|
||
$this->assertCount(5, $project->refresh()->tasks); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Domains\Projects; | ||
|
||
use App\Domains\Chat\UiStatusEnum; | ||
use App\Models\Project; | ||
use Facades\App\Domains\Projects\Orchestrate; | ||
|
||
class KickOffProject | ||
{ | ||
public function handle(Project $project) | ||
{ | ||
$chat = $project->chats()->first(); | ||
|
||
$chat->updateQuietly([ | ||
'chat_status' => UiStatusEnum::InProgress, | ||
]); | ||
|
||
$chat->messages()->delete(); | ||
|
||
$project->tasks()->delete(); | ||
|
||
Orchestrate::handle($chat, $project->content, $project->system_prompt); | ||
|
||
$chat->updateQuietly([ | ||
'chat_status' => UiStatusEnum::Complete, | ||
]); | ||
} | ||
} |
Oops, something went wrong.