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()
|
0
|
6 local Io = require "luan:Io.luan"
|
|
7 local Http = require "luan:http/Http.luan"
|
|
8 local Shared = require "site:/lib/Shared.luan"
|
|
9 local head = Shared.head or error()
|
|
10 local header = Shared.header or error()
|
4
|
11 local started = Shared.started or error()
|
31
|
12 local voices = Shared.voices or error()
|
4
|
13 local User = require "site:/lib/User.luan"
|
24
|
14 local current_user = User.current_required or error()
|
4
|
15 local Chat = require "site:/lib/Chat.luan"
|
|
16 local get_chat_by_id = Chat.get_by_id or error()
|
0
|
17
|
|
18
|
|
19 return function()
|
4
|
20 local user = current_user()
|
24
|
21 if user == nil then return end
|
18
|
22 local chat_id = Http.request.parameters.chat or error()
|
|
23 local chat = get_chat_by_id(chat_id) or error()
|
25
|
24 local added_message = chat.init_ai()
|
0
|
25 Io.stdout = Http.response.text_writer()
|
|
26 %>
|
|
27 <!doctype html>
|
|
28 <html lang="en">
|
|
29 <head>
|
|
30 <% head() %>
|
4
|
31 <style>
|
|
32 @import "/chat.css?s=<%=started%>";
|
|
33 </style>
|
|
34 <script src="/chat.js?s=<%=started%>"></script>
|
0
|
35 </head>
|
|
36 <body>
|
|
37 <% header() %>
|
4
|
38 <div content ai_container>
|
|
39 <div top>
|
29
|
40 <h3 name></h3>
|
4
|
41 <span pulldown>
|
|
42 <img onclick="clickMenu(this)" src="/images/menu.svg">
|
|
43 <div>
|
29
|
44 <span onclick="editChat()">Edit Chat</span>
|
4
|
45 <span onclick="deleteChat()">Delete Chat</span>
|
9
|
46 <span onclick="systemPrompt()">System Prompt</span>
|
1
|
47 </div>
|
4
|
48 </span>
|
|
49 </div>
|
7
|
50 <div messages>
|
|
51 <% chat.output_messages_html() %>
|
4
|
52 </div>
|
|
53 <div ask>
|
11
|
54 <textarea autofocus oninput="fixTextarea(event.target)" onkeydown="textareaKey(event)"></textarea>
|
14
|
55 <div buttons>
|
28
|
56 <audio controls preload=none></audio>
|
14
|
57 <button record onclick="toggleRecording()">Record</button>
|
|
58 <button onclick="askAi()" title="Send"><img src="/images/send.svg"></button>
|
|
59 </div>
|
1
|
60 </div>
|
0
|
61 </div>
|
6
|
62 <img waiting-ai-icon src="/images/spinner_green.gif">
|
29
|
63 <dialog edit>
|
|
64 <h2>Edit Chat</h2>
|
|
65 <form onsubmit="saveChat(this)" action="javascript:">
|
|
66 <input type=hidden name=chat value="<%=chat.id%>">
|
4
|
67 <p>
|
|
68 <label>Chat name</label><br>
|
|
69 <input name=name required><br>
|
|
70 <span error></span>
|
|
71 </p>
|
31
|
72 <p>
|
|
73 <label>Voice</label><br>
|
|
74 <select name=voice>
|
|
75 <% for _, voice in ipairs(voices) do %>
|
|
76 <option value="<%=voice.code%>"><%=voice.name%></option>
|
|
77 <% end %>
|
|
78 <select>
|
|
79 </p>
|
4
|
80 <div buttons>
|
|
81 <button type=button onclick="closeModal(this)">Cancel</button>
|
29
|
82 <button type=submit>Save</button>
|
4
|
83 </div>
|
|
84 </form>
|
|
85 </dialog>
|
|
86 <dialog delete>
|
|
87 <h2>Delete Chat</h2>
|
|
88 <p>Are you sure that you want to delete this chat?</p>
|
|
89 <div buttons>
|
|
90 <button onclick="closeModal(this)">Cancel</button>
|
|
91 <button onclick="doDeleteChat(this)">Delete</button>
|
|
92 </div>
|
|
93 </dialog>
|
9
|
94 <dialog system_prompt>
|
|
95 <h2>System Prompt</h2>
|
27
|
96 <pre>
|
9
|
97 <% chat.output_system_prompt() %>
|
27
|
98 </pre>
|
|
99 <p><a href="view_course.html?course=<%=chat.course_id%>">View course</a></p>
|
9
|
100 <div buttons>
|
|
101 <button onclick="closeModal(this)">Close</button>
|
|
102 </div>
|
|
103 </dialog>
|
27
|
104 <input name=initialized style="display:none">
|
6
|
105 <script>
|
29
|
106 setChat(<%= json_string(chat.info()) %>);
|
|
107 handleChatMarkdown();
|
27
|
108 setTimeout(function(){
|
|
109 let initialized = document.querySelector('[name=initialized]');
|
|
110 if( !initialized.value ) {
|
|
111 initialized.value = 'yes';
|
|
112 //alert('init');
|
|
113 scrollToEnd();
|
25
|
114 <% if added_message then %>
|
27
|
115 playLastMessage();
|
25
|
116 <% end %>
|
27
|
117 }
|
|
118 },10);
|
6
|
119 </script>
|
0
|
120 </body>
|
|
121 </html>
|
|
122 <%
|
|
123 end
|