From 088b71eb821bd51fa1de3041aa5bd7c2e0d85b28 Mon Sep 17 00:00:00 2001 From: Alfred Nutile Date: Thu, 28 Mar 2024 09:51:17 -0400 Subject: [PATCH] ready to deploy --- .../Documents/Transformers/PdfTransformer.php | 4 ++ app/Events/ChatUpdatedEvent.php | 44 +++++++++++++ app/Http/Controllers/ChatController.php | 3 + app/Http/Controllers/CollectionController.php | 1 + resources/js/Pages/Chat/ChatInputThreaded.vue | 4 +- resources/js/Pages/Collection/Chat.vue | 10 ++- .../Pages/Collection/Components/LlmType.vue | 62 +++++++++++++++++++ .../Collection/Components/ResourceForm.vue | 10 ++- resources/js/Pages/Collection/Create.vue | 2 + routes/channels.php | 16 ++++- .../Controllers/CollectionControllerTest.php | 1 + 11 files changed, 151 insertions(+), 6 deletions(-) create mode 100644 app/Events/ChatUpdatedEvent.php create mode 100644 resources/js/Pages/Collection/Components/LlmType.vue diff --git a/app/Domains/Documents/Transformers/PdfTransformer.php b/app/Domains/Documents/Transformers/PdfTransformer.php index 6ef7bfc3..a6a71817 100644 --- a/app/Domains/Documents/Transformers/PdfTransformer.php +++ b/app/Domains/Documents/Transformers/PdfTransformer.php @@ -2,6 +2,8 @@ namespace App\Domains\Documents\Transformers; +use App\Domains\Collections\CollectionStatusEnum; +use App\Events\CollectionStatusEvent; use App\Jobs\SummarizeDataJob; use App\Jobs\SummarizeDocumentJob; use App\Jobs\VectorlizeDataJob; @@ -48,6 +50,8 @@ public function handle(Document $document): Document new SummarizeDataJob($DocumentChunk), //Tagging ]; + + CollectionStatusEvent::dispatch($document->collection, CollectionStatusEnum::PROCESSING); } $batch = Bus::batch($chunks) diff --git a/app/Events/ChatUpdatedEvent.php b/app/Events/ChatUpdatedEvent.php new file mode 100644 index 00000000..b4ee1910 --- /dev/null +++ b/app/Events/ChatUpdatedEvent.php @@ -0,0 +1,44 @@ + + */ + public function broadcastOn(): array + { + return [ + new PrivateChannel('collection.chat.'.$this->collection->id.'.'.$this->chat->id), + ]; + } + + /** + * The event's broadcast name. + */ + public function broadcastAs(): string + { + return 'status'; + } +} diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index 081a199e..5ea2bd99 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Events\ChatUpdatedEvent; use App\Http\Resources\ChatResource; use App\Http\Resources\CollectionResource; use App\Http\Resources\MessageResource; @@ -45,6 +46,8 @@ public function chat(Chat $chat) $response = SearchOrSummarizeChatRepo::search($chat, $validated['input']); + ChatUpdatedEvent::dispatch($chat->chatable, $chat); + return response()->json(['message' => $response]); } } diff --git a/app/Http/Controllers/CollectionController.php b/app/Http/Controllers/CollectionController.php index a3a22d0d..d79565d4 100644 --- a/app/Http/Controllers/CollectionController.php +++ b/app/Http/Controllers/CollectionController.php @@ -30,6 +30,7 @@ public function store() $validated = request()->validate([ 'name' => 'required', 'description' => 'required', + 'driver' => 'required', ]); $validated['team_id'] = auth()->user()->current_team_id; diff --git a/resources/js/Pages/Chat/ChatInputThreaded.vue b/resources/js/Pages/Chat/ChatInputThreaded.vue index a47c0bf5..5ae21572 100644 --- a/resources/js/Pages/Chat/ChatInputThreaded.vue +++ b/resources/js/Pages/Chat/ChatInputThreaded.vue @@ -28,10 +28,12 @@ const getting_results = ref(false) const save = () => { getting_results.value = true + let message = form.input + form.reset(); axios.post(route('chats.messages.create', { chat: props.chat.id }), { - input: form.input + input: message }).then(response => { getting_results.value = false console.log(response.data.message) diff --git a/resources/js/Pages/Collection/Chat.vue b/resources/js/Pages/Collection/Chat.vue index bd20e1d3..04bf8065 100644 --- a/resources/js/Pages/Collection/Chat.vue +++ b/resources/js/Pages/Collection/Chat.vue @@ -29,7 +29,15 @@ const props = defineProps({ provide('system_prompt', props.system_prompt); - +onMounted(() => { + Echo.private(`collection.chat.${props.collection.data.id}.${props.chat.data.id}`) + .listen('.status', (e) => { + console.log(e); + router.reload({ + preserveScroll: true, + }) + }); +});