-
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.
- Loading branch information
Showing
13 changed files
with
322 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace App\Domains\Projects; | ||
|
||
use App\Domains\Messages\RoleEnum; | ||
use App\Models\Task; | ||
use App\Models\Project; | ||
use App\Notifications\DailyReport; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Support\Facades\Notification; | ||
use LlmLaraHub\LlmDriver\Functions\ToolTypes; | ||
use LlmLaraHub\LlmDriver\LlmDriverFacade; | ||
|
||
class DailyReportService | ||
{ | ||
public function handle(): void | ||
{ | ||
foreach (Project::active()->get() as $project) { | ||
$this->sendReport($project); | ||
} | ||
} | ||
|
||
public function sendReport(Project $project) | ||
{ | ||
$tasks = Task::where('project_id', $project->id) | ||
->notCompleted() | ||
->where('due_date', '>=', now()->addDays(7)) | ||
->get() | ||
/** @phpstan-ignore-next-line */ | ||
->transform(function (Task $item) { | ||
return sprintf( | ||
'Task: %s %s %s', | ||
$item->name, | ||
$item->details, | ||
$item->due_date | ||
); | ||
})->implode(', '); | ||
|
||
$prompt = ProjectDailyReportPrompt::getPrompt($project, $tasks); | ||
|
||
$project->getChat()->addInput( | ||
message: $prompt, | ||
role: RoleEnum::User, | ||
); | ||
|
||
$messages = $project->getChat()->getMessageThread(); | ||
|
||
$results = LlmDriverFacade::driver($project->getDriver()) | ||
->setToolType(ToolTypes::Chat) | ||
->chat($messages); | ||
|
||
$project->getChat()->addInput( | ||
message: $results->content, | ||
role: RoleEnum::Assistant, | ||
); | ||
|
||
Log::info('DailyReportService::handle', [ | ||
'results' => $results->content, | ||
]); | ||
|
||
Notification::send($project->team->allUsers(), new DailyReport($results->content, $project)); | ||
} | ||
} |
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,48 @@ | ||
<?php | ||
|
||
namespace App\Domains\Projects; | ||
|
||
use App\Models\Project; | ||
|
||
class ProjectDailyReportPrompt | ||
{ | ||
public static function getPrompt( | ||
Project $project, | ||
?string $tasks = ''): string | ||
{ | ||
|
||
$now = now()->toISOString(); | ||
|
||
$context = $project->content; | ||
|
||
return <<<PROMPT | ||
<role> | ||
You are an Ai marketing assistant specialized in digital marketing campaigns. Below is info about the campaign and previous conversations. | ||
<task> | ||
Using the `<context> section below, give the user a report of tasks that are due and when | ||
so they can see what they need to do today and or in the next day or two. They | ||
get this report every day so they can see what they need to do today and what. | ||
If there are not tasks then put in the Tasks sections "No tasks today or tomorrow" | ||
<format> | ||
TLDR: What is on the schedule | ||
Tasks: | ||
* Task Name and due date | ||
* Task Name and due date | ||
<content> | ||
Today's date is $now | ||
The list of tasks if any are: | ||
$tasks | ||
The campaign content is: | ||
$context | ||
PROMPT; | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Project; | ||
use Facades\App\Domains\Projects\DailyReportService; | ||
|
||
class DailyReportSendController extends Controller | ||
{ | ||
public function __invoke(Project $project) | ||
{ | ||
DailyReportService::sendReport($project); | ||
\request()->session()->flash('flash.banner', 'Sent!'); | ||
return back(); | ||
} | ||
} |
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,58 @@ | ||
<?php | ||
|
||
namespace App\Notifications; | ||
|
||
use App\Models\Project; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
use Illuminate\Notifications\Notification; | ||
|
||
class DailyReport extends Notification | ||
{ | ||
use Queueable; | ||
|
||
/** | ||
* Create a new notification instance. | ||
*/ | ||
public function __construct( | ||
public string $message, | ||
public Project $project) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Get the notification's delivery channels. | ||
* | ||
* @return array<int, string> | ||
*/ | ||
public function via(object $notifiable): array | ||
{ | ||
return ['mail']; | ||
} | ||
|
||
/** | ||
* Get the mail representation of the notification. | ||
*/ | ||
public function toMail(object $notifiable): MailMessage | ||
{ | ||
return (new MailMessage) | ||
->subject('Daily Report') | ||
->markdown('mail.daily_report', [ | ||
'message' => $this->message, | ||
'url' => route('projects.show', $this->project), | ||
]); | ||
} | ||
|
||
/** | ||
* Get the array representation of the notification. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function toArray(object $notifiable): array | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
} |
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,11 @@ | ||
<x-mail::message> | ||
|
||
{{ $message }} | ||
|
||
<x-mail::button :url="$url"> | ||
View the Project | ||
</x-mail::button> | ||
|
||
Thanks,<br> | ||
Your assistant! | ||
</x-mail::message> |
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
Oops, something went wrong.