Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit 1dd0f4c

Browse files
committed
fix the double toasts
and start adding back chat over completion
1 parent da9c836 commit 1dd0f4c

File tree

7 files changed

+61
-11
lines changed

7 files changed

+61
-11
lines changed

Modules/LlmDriver/app/Functions/SearchAndSummarize.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use App\Domains\Agents\VerifyPromptOutputDto;
77
use App\Domains\Messages\RoleEnum;
88
use App\Domains\Prompts\SummarizePrompt;
9+
use App\Models\Chat;
10+
use App\Models\Message;
911
use App\Models\PromptHistory;
1012
use Facades\App\Domains\Agents\VerifyResponseAgent;
1113
use Facades\LlmLaraHub\LlmDriver\DistanceQuery;
@@ -108,10 +110,28 @@ public function handle(
108110

109111
notify_ui($model, 'Building Summary');
110112

111-
/** @var CompletionResponse $response */
112-
$response = LlmDriverFacade::driver(
113-
$model->getChatable()->getDriver()
114-
)->completion($contentFlattened);
113+
114+
if(!get_class($model) === Chat::class) {
115+
Log::info('[LaraChain] Using the Simple Completion', [
116+
'input' => $contentFlattened,
117+
'driver' => $model->getChatable()->getDriver(),
118+
]);
119+
/** @var CompletionResponse $response */
120+
$response = LlmDriverFacade::driver(
121+
$model->getChatable()->getDriver()
122+
)->completion($contentFlattened);
123+
} else {
124+
Log::info('[LaraChain] Using the Chat Completion', [
125+
'input' => $contentFlattened,
126+
'driver' => $model->getChatable()->getDriver(),
127+
]);
128+
$messages = $model->getChat()->getChatResponse();
129+
130+
/** @var CompletionResponse $response */
131+
$response = LlmDriverFacade::driver(
132+
$model->getChatable()->getDriver()
133+
)->chat($messages);
134+
}
115135

116136
$this->response = $response->content;
117137

app/Domains/Messages/SearchAndSummarizeChatRepo.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ public function search(Chat $chat,
2828
string $input,
2929
?Filter $filter = null): string
3030
{
31-
Log::info('[LaraChain] Search and Summarize Default Function');
31+
Log::info('[LaraChain] Search and Summarize Default Function', [
32+
'note' => "Showing input since some system grab the last on the array",
33+
'input' => $input
34+
]);
3235

3336
$originalPrompt = $input;
3437

@@ -84,14 +87,15 @@ public function search(Chat $chat,
8487
Log::info('[LaraChain] Getting the Summary', [
8588
'input' => $contentFlattened,
8689
'driver' => $chat->chatable->getDriver(),
90+
'messages' => count($latestMessagesArray),
8791
]);
8892

8993
notify_ui($chat, 'Building Summary');
9094

9195
/** @var CompletionResponse $response */
9296
$response = LlmDriverFacade::driver(
9397
$chat->chatable->getDriver()
94-
)->completion($contentFlattened);
98+
)->chat($latestMessagesArray);
9599

96100
$this->response = $response->content;
97101

app/Models/Chat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function getAiResponse($input)
134134
public function getChatResponse(int $limit = 5): array
135135
{
136136
$latestMessages = $this->messages()
137-
->latest()
137+
->orderBy('id', 'desc')
138138
->limit(5)
139139
->get();
140140

resources/js/Pages/Chat/ChatInputThreaded.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ onMounted(() => {
5454
});
5555
});
5656
57+
onUnmounted(() => {
58+
Echo.leave(`collection.chat.${props.chat.chatable_id}.${props.chat.id}`);
59+
});
5760
5861
5962
const save = () => {

resources/js/Pages/Collection/Chat.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import AppLayout from '@/Layouts/AppLayout.vue';
33
import Welcome from '@/Components/Welcome.vue';
44
import PrimaryButton from '@/Components/PrimaryButton.vue';
55
import SecondaryLink from '@/Components/SecondaryLink.vue';
6-
import { computed, onMounted, provide, ref } from 'vue';
6+
import {computed, onMounted, onUnmounted, provide, ref} from 'vue';
77
import Nav from '@/Pages/Collection/Components/Nav.vue';
88
import CollectionTags from './Components/CollectionTags.vue';
99
import { useDropzone } from "vue3-dropzone";
@@ -57,6 +57,11 @@ onMounted(() => {
5757
});
5858
});
5959
});
60+
61+
onUnmounted(() => {
62+
Echo.leave(`collection.chat.${props.collection.data.id}.${props.chat.data.id}`);
63+
});
64+
6065
</script>
6166

6267
<template>

resources/js/Pages/Collection/Components/Documents.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup>
2-
import {computed, onMounted, ref} from 'vue';
2+
import {computed, onMounted, onUnmounted, ref} from 'vue';
33
import Tags from '@/Components/Tags.vue';
44
import ShowDocument from '@/Pages/Collection/Components/ShowDocument.vue';
55
import DocumentReset from '@/Pages/Collection/Components/DocumentReset.vue';
@@ -71,7 +71,9 @@ onMounted(() => {
7171
});
7272
});
7373
74-
74+
onUnmounted(() => {
75+
Echo.leave(`collection.${props.collection.id}`);
76+
});
7577
7678
</script>
7779
<template>

tests/Feature/SearchAndSummarizeTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
namespace Tests\Feature;
44

55
use App\Domains\Agents\VerifyPromptOutputDto;
6+
use App\Domains\Messages\RoleEnum;
67
use App\Models\Chat;
78
use App\Models\Collection;
89
use App\Models\Document;
910
use App\Models\DocumentChunk;
11+
use App\Models\Message;
1012
use Facades\App\Domains\Agents\VerifyResponseAgent;
1113
use Facades\LlmLaraHub\LlmDriver\DistanceQuery;
1214
use LlmLaraHub\LlmDriver\Functions\ParametersDto;
@@ -54,7 +56,7 @@ public function test_gets_user_input()
5456
]),
5557
]);
5658

57-
LlmDriverFacade::shouldReceive('driver->completion')
59+
LlmDriverFacade::shouldReceive('driver->chat')
5860
->once()
5961
->andReturn($dto);
6062

@@ -75,6 +77,20 @@ public function test_gets_user_input()
7577
'chatable_id' => $collection->id,
7678
]);
7779

80+
$messageUser = Message::factory()->create([
81+
'body' => 'Results Before this one',
82+
'role' => RoleEnum::User,
83+
'is_chat_ignored' => false,
84+
'chat_id'=> $chat->id
85+
]);
86+
87+
$messageAssistant = Message::factory()->create([
88+
'body' => 'Results Before this one',
89+
'role' => RoleEnum::Assistant,
90+
'is_chat_ignored' => false,
91+
'chat_id'=> $chat->id
92+
]);
93+
7894
$document = Document::factory()->create([
7995
'collection_id' => $collection->id,
8096
]);

0 commit comments

Comments
 (0)