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