comparison src/lib/ai/claude/Ai_chat.luan @ 34:0fb3488a017d

show_text
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 04 Aug 2025 23:06:19 -0600
parents 505185272dd7
children 3117876debca
comparison
equal deleted inserted replaced
33:7d9462ea03e3 34:0fb3488a017d
25 local system_prompt = thread.system or error 25 local system_prompt = thread.system or error
26 system_prompt = html_encode(system_prompt) 26 system_prompt = html_encode(system_prompt)
27 %><%=system_prompt%><% 27 %><%=system_prompt%><%
28 end 28 end
29 29
30 function Ai_chat.output_messages_html(thread,old_thread) 30 function Ai_chat.output_messages_html(show_text,thread,old_thread)
31 if thread == nil then 31 if thread == nil then
32 return 32 return
33 end 33 end
34 thread = json_parse(thread) 34 thread = json_parse(thread)
35 local messages = thread.messages or error 35 local messages = thread.messages or error
37 if old_thread ~= nil then 37 if old_thread ~= nil then
38 old_thread = json_parse(old_thread) 38 old_thread = json_parse(old_thread)
39 local old_messages = old_thread.messages or error 39 local old_messages = old_thread.messages or error
40 n = #old_messages 40 n = #old_messages
41 end 41 end
42 local checked = show_text and "checked" or ""
42 for i, message in ipairs(messages) do 43 for i, message in ipairs(messages) do
43 if i <= n then 44 if i <= n then
44 continue 45 continue
45 end 46 end
46 local role = message.role or error() 47 local role = message.role or error()
54 end 55 end
55 local function output(text) 56 local function output(text)
56 text = html_encode(text) 57 text = html_encode(text)
57 %> 58 %>
58 <h3><%=who%></h3> 59 <h3><%=who%></h3>
59 <div markdown role="<%=role%>"><%=text%></div> 60 <div role="<%=role%>">
61 <div message markdown><%=text%></div>
62 <% if role=="assistant" then %>
63 <div controls>
64 <audio controls preload=none></audio>
65 <label clickable><input type=checkbox name=show_text <%=checked%> >Show text</label>
66 </div>
67 <% end %>
68 </div>
60 <% 69 <%
61 end 70 end
62 local content = message.content or error() 71 local content = message.content or error()
63 if type(content) == "string" then 72 if type(content) == "string" then
64 output(content) 73 output(content)