From 4b100bd8716009e4f6bc4d26ba2e49c09008bc0e Mon Sep 17 00:00:00 2001 From: Ashley Johnson <61059402+PapaRascal2020@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:52:45 +0100 Subject: [PATCH] More refactoring of Playground code - Extracted User and Bot Messages --- .../Components/sidekick-bot-message.blade.php | 17 +++++++ .../sidekick-user-message.blade.php | 10 ++++ .../resources/views/Pages/chatroom.blade.php | 50 ++++++------------- 3 files changed, 42 insertions(+), 35 deletions(-) create mode 100644 stubs/default/resources/views/Components/sidekick-bot-message.blade.php create mode 100644 stubs/default/resources/views/Components/sidekick-user-message.blade.php diff --git a/stubs/default/resources/views/Components/sidekick-bot-message.blade.php b/stubs/default/resources/views/Components/sidekick-bot-message.blade.php new file mode 100644 index 0000000..4f1fc99 --- /dev/null +++ b/stubs/default/resources/views/Components/sidekick-bot-message.blade.php @@ -0,0 +1,17 @@ +
+
+

+ + + + + + + + + + Assistant

+

{{ $slot }}

+
+
diff --git a/stubs/default/resources/views/Components/sidekick-user-message.blade.php b/stubs/default/resources/views/Components/sidekick-user-message.blade.php new file mode 100644 index 0000000..10dc6cd --- /dev/null +++ b/stubs/default/resources/views/Components/sidekick-user-message.blade.php @@ -0,0 +1,10 @@ +
+
+

+ + + User

+

{{ $slot }}

+
+
diff --git a/stubs/default/resources/views/Pages/chatroom.blade.php b/stubs/default/resources/views/Pages/chatroom.blade.php index db1e047..dd7fabb 100644 --- a/stubs/default/resources/views/Pages/chatroom.blade.php +++ b/stubs/default/resources/views/Pages/chatroom.blade.php @@ -24,21 +24,13 @@ @if(isset($messages)) @foreach($messages as $message) @if(strtolower($message['role']) === 'user') -
-
-

- @include('Components.user') User

-

{!! $message['content'] !!}

-
-
+ + {!! $message['content'] !!} + @else -
-
-

- @include('Components.bot') Assistant

-

{!! nl2br($message['content']) !!}

-
-
+ + {!! nl2br($message['content']) !!} + @endif @endforeach @endif @@ -85,13 +77,9 @@ let isStreamed = stream.checked; responseContainer.innerHTML += ` -
-
-

- @include('Components.user') User

-

${message}

-
-
+ + ${message} + `; responseContainer.innerHTML += ` @@ -120,13 +108,7 @@ // Create response container responseContainer.innerHTML += ` -
-
-

- @include('Components.bot') Assistant

-

-
-
+ `; // Make fetch request to server @@ -173,6 +155,8 @@ } function handleCallback() { + let r = (Math.random() + 1).toString(36).substring(7); + fetch('/sidekick/playground/chat/update', { method: 'POST', headers: { @@ -190,13 +174,9 @@ function handleCallback() { loader.remove(); responseContainer.innerHTML += ` -
-
-

- @include('Components.bot') Assistant

-

${response}

-
-
+ + ${response} + `; container.scrollTop = container.scrollHeight;