Mercurial Hosting > lang
annotate src/chat.html.luan @ 46:cc20eebaa74a
use openai tts
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 14 Aug 2025 11:27:34 +0900 |
parents | 1d9d9786d76f |
children | 97b0d206cacd |
rev | line source |
---|---|
0 | 1 local Luan = require "luan:Luan.luan" |
2 local error = Luan.error | |
31 | 3 local ipairs = Luan.ipairs or error() |
29 | 4 local Parsers = require "luan:Parsers.luan" |
5 local json_string = Parsers.json_string or error() | |
35
3117876debca
ai_first_message in textarea
Franklin Schmidt <fschmidt@gmail.com>
parents:
34
diff
changeset
|
6 local Html = require "luan:Html.luan" |
3117876debca
ai_first_message in textarea
Franklin Schmidt <fschmidt@gmail.com>
parents:
34
diff
changeset
|
7 local html_encode = Html.encode or error() |
0 | 8 local Io = require "luan:Io.luan" |
9 local Http = require "luan:http/Http.luan" | |
10 local Shared = require "site:/lib/Shared.luan" | |
11 local head = Shared.head or error() | |
12 local header = Shared.header or error() | |
4 | 13 local started = Shared.started or error() |
31 | 14 local voices = Shared.voices or error() |
4 | 15 local User = require "site:/lib/User.luan" |
41 | 16 local current_user = User.current or error() |
4 | 17 local Chat = require "site:/lib/Chat.luan" |
18 local get_chat_by_id = Chat.get_by_id or error() | |
46 | 19 local Utils = require "site:/lib/Utils.luan" |
20 local capitalize = Utils.capitalize or error() | |
0 | 21 |
22 | |
23 return function() | |
18 | 24 local chat_id = Http.request.parameters.chat or error() |
25 local chat = get_chat_by_id(chat_id) or error() | |
41 | 26 local user = current_user() |
27 local is_owner = user ~= nil and user.id == chat.user_id | |
28 is_owner or not chat.is_private or error "private" | |
35
3117876debca
ai_first_message in textarea
Franklin Schmidt <fschmidt@gmail.com>
parents:
34
diff
changeset
|
29 local init_text = chat.init_text() |
0 | 30 Io.stdout = Http.response.text_writer() |
31 %> | |
32 <!doctype html> | |
33 <html lang="en"> | |
34 <head> | |
35 <% head() %> | |
4 | 36 <style> |
37 @import "/chat.css?s=<%=started%>"; | |
38 </style> | |
39 <script src="/chat.js?s=<%=started%>"></script> | |
0 | 40 </head> |
41 <body> | |
42 <% header() %> | |
4 | 43 <div content ai_container> |
44 <div top> | |
29 | 45 <h3 name></h3> |
4 | 46 <span pulldown> |
47 <img onclick="clickMenu(this)" src="/images/menu.svg"> | |
48 <div> | |
41 | 49 <% if is_owner then %> |
29 | 50 <span onclick="editChat()">Edit Chat</span> |
4 | 51 <span onclick="deleteChat()">Delete Chat</span> |
41 | 52 <% end %> |
9 | 53 <span onclick="systemPrompt()">System Prompt</span> |
1 | 54 </div> |
4 | 55 </span> |
56 </div> | |
7 | 57 <div messages> |
58 <% chat.output_messages_html() %> | |
4 | 59 </div> |
41 | 60 <% if is_owner then %> |
4 | 61 <div ask> |
42 | 62 <textarea autofocus oninput="fixChatTextarea(event.target)" onkeydown="textareaKey(event)"><%= html_encode(init_text) %></textarea> |
14 | 63 <div buttons> |
28 | 64 <audio controls preload=none></audio> |
14 | 65 <button record onclick="toggleRecording()">Record</button> |
66 <button onclick="askAi()" title="Send"><img src="/images/send.svg"></button> | |
67 </div> | |
1 | 68 </div> |
41 | 69 <% end %> |
0 | 70 </div> |
6 | 71 <img waiting-ai-icon src="/images/spinner_green.gif"> |
29 | 72 <dialog edit> |
73 <h2>Edit Chat</h2> | |
74 <form onsubmit="saveChat(this)" action="javascript:"> | |
75 <input type=hidden name=chat value="<%=chat.id%>"> | |
4 | 76 <p> |
77 <label>Chat name</label><br> | |
34 | 78 <input type=text name=name required><br> |
4 | 79 <span error></span> |
80 </p> | |
32 | 81 <p><%= chat.language_name() %></p> |
82 <p> | |
31 | 83 <label>Voice</label><br> |
84 <select name=voice> | |
85 <% for _, voice in ipairs(voices) do %> | |
46 | 86 <option value="<%=voice%>"><%=capitalize(voice)%></option> |
31 | 87 <% end %> |
88 <select> | |
89 </p> | |
34 | 90 <p> |
36 | 91 <label clickable><input type=checkbox name=autoplay>Autoplay</label> |
92 </p> | |
93 <p> | |
34 | 94 <label clickable><input type=checkbox name=show_text>Show text</label> |
95 </p> | |
41 | 96 <p> |
97 <label clickable><input type=checkbox name=is_private>Private chat</label> | |
98 </p> | |
4 | 99 <div buttons> |
100 <button type=button onclick="closeModal(this)">Cancel</button> | |
29 | 101 <button type=submit>Save</button> |
4 | 102 </div> |
103 </form> | |
104 </dialog> | |
105 <dialog delete> | |
106 <h2>Delete Chat</h2> | |
107 <p>Are you sure that you want to delete this chat?</p> | |
108 <div buttons> | |
109 <button onclick="closeModal(this)">Cancel</button> | |
110 <button onclick="doDeleteChat(this)">Delete</button> | |
111 </div> | |
112 </dialog> | |
9 | 113 <dialog system_prompt> |
114 <h2>System Prompt</h2> | |
27 | 115 <pre> |
9 | 116 <% chat.output_system_prompt() %> |
27 | 117 </pre> |
118 <p><a href="view_course.html?course=<%=chat.course_id%>">View course</a></p> | |
9 | 119 <div buttons> |
120 <button onclick="closeModal(this)">Close</button> | |
121 </div> | |
122 </dialog> | |
27 | 123 <input name=initialized style="display:none"> |
6 | 124 <script> |
41 | 125 'use strict'; |
126 //let test = 'a'; | |
127 //alert(test); | |
128 //test = 'b'; | |
29 | 129 setChat(<%= json_string(chat.info()) %>); |
130 handleChatMarkdown(); | |
41 | 131 scrollToEnd(); |
132 /* | |
27 | 133 setTimeout(function(){ |
134 let initialized = document.querySelector('[name=initialized]'); | |
135 if( !initialized.value ) { | |
136 initialized.value = 'yes'; | |
137 //alert('init'); | |
138 scrollToEnd(); | |
139 } | |
140 },10); | |
41 | 141 */ |
6 | 142 </script> |
0 | 143 </body> |
144 </html> | |
145 <% | |
146 end |