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