| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace App\Jobs;
- use App\Models\Chat;
- use Illuminate\Bus\Batchable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Queue\Queueable;
- use Illuminate\Support\Facades\Http;
- class SetChatTitleJob implements ShouldQueue
- {
- use Batchable;
- use Queueable;
- public int $tries = 5;
- /**
- * Create a new job instance.
- */
- public function __construct(private readonly Chat $chat)
- {
- $this->onQueue('secondary');
- $this->afterCommit();
- }
- /**
- * Execute the job.
- */
- public function handle(): void
- {
- if ($this->batch()?->cancelled() || $this->chat->title) {
- return;
- }
- $response = Http::inference()->throw()->post('/generate', [
- 'message' => 'Кратко выдели суть обсуждения (2-4 слова) из сообщения пользователя для именования чата. ' . ' ' .
- 'Это необходимо, чтобы пользователь выдел список своих чатов и мог быстро понять что обсуждалось в данном чате.' . ' ' .
- 'Название должно быть ёмким, отражать суть сообщения, без лишних слов.' . ' ' .
- 'Ответ дай только в виде текста названия, без пояснений и кавычек.' . ' ' .
- 'Сообщение пользователя: ' . $this->chat->messages()->first()->content,
- ]);
- $result = $response->json();
- $this->chat->update(['title' => $result['content']]);
- }
- }
|