@@ -106,7 +106,7 @@ <h1 class="text-lg font-semibold"> <i class="fa-solid fa-comments"></i> Chat wit
106106 < div class ="flex flex-col flex-1 ">
107107 < span class ="text-xs font-semibold text-gray-600 " x-text ="message.role === 'user' ? 'User' : 'Assistant ({{.Model}})' "> </ span >
108108 < template x-if ="message.role === 'user' ">
109- < div class ="p-2 flex-1 rounded " :class ="message.role " x-text ="message.content "> </ div >
109+ < div class ="p-2 flex-1 rounded " :class ="message.role " x-html ="message.html "> </ div >
110110 </ template >
111111 < template x-if ="message.role === 'assistant' ">
112112 < div class ="p-2 flex-1 rounded " :class ="message.role " x-html ="message.html "> </ div >
@@ -117,22 +117,27 @@ <h1 class="text-lg font-semibold"> <i class="fa-solid fa-comments"></i> Chat wit
117117 </ div >
118118 </ div >
119119
120- < div class ="p-4 border-t border-gray-700 ">
121- < div id ="loader " class ="my-2 loader " style ="display: none; " > </ div >
120+ < div class ="p-4 border-t border-gray-700 " x-data =" { inputValue: '', shiftPressed: false } " >
121+ < div id ="loader " class ="my-2 loader " style ="display: none; "> </ div >
122122 < input id ="chat-model " type ="hidden " value ="{{.Model}} ">
123- < form id ="prompt " action ="/chat/{{.Model}} " method ="get ">
124- < input
125- type ="text "
126- id ="input "
127- name ="input "
128- placeholder ="Prompt… "
129- autocomplete ="off "
130- class ="p-2 border rounded w-full bg-gray-600 text-white placeholder-gray-300 "
131- required
132- />
123+ < form id ="prompt " action ="/chat/{{.Model}} " method ="get " @submit.prevent ="submitPrompt ">
124+ < div class ="relative w-full ">
125+ < textarea
126+ id ="input "
127+ name ="input "
128+ x-model ="inputValue "
129+ placeholder ="Send a message... "
130+ class ="p-2 pl-2 border rounded w-full bg-gray-600 text-white placeholder-gray-300 "
131+ required
132+ @keydown.shift ="shiftPressed = true "
133+ @keyup.shift ="shiftPressed = false "
134+ @keydown.enter ="if (!shiftPressed) { submitPrompt($event); } "
135+ style ="padding-right: 4rem; "
136+ > </ textarea >
137+ < button type =submit > < i class ="fa-solid fa-circle-up text-gray-300 absolute right-2 top-3 text-lg p-2 ml-2 "> </ i > </ button >
138+ </ div >
133139 </ form >
134- </ div >
135-
140+ </ div >
136141 < script >
137142 document . addEventListener ( "alpine:init" , ( ) => {
138143 Alpine . store ( "chat" , {
@@ -150,10 +155,18 @@ <h1 class="text-lg font-semibold"> <i class="fa-solid fa-comments"></i> Chat wit
150155 marked . parse ( this . history [ N ] . content ) ,
151156 ) ;
152157 } else {
158+ c = ""
159+ // split content newlines in content
160+ const lines = content . split ( "\n" ) ;
161+ // for each line, do DOMPurify.sanitize(marked.parse(line)) and add it to c
162+ lines . forEach ( ( line ) => {
163+ c += DOMPurify . sanitize ( marked . parse ( line ) ) ;
164+ } ) ;
165+
153166 this . history . push ( {
154167 role : role ,
155168 content : content ,
156- html : DOMPurify . sanitize ( marked . parse ( content ) ) ,
169+ html : c ,
157170 } ) ;
158171 }
159172
0 commit comments