comparison src/lib/ai/claude/Chat.luan @ 13:65bd7e245c63

add html
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 24 Jul 2025 22:47:48 -0600
parents 2d4b3f003ec2
children f5425a3c1898
comparison
equal deleted inserted replaced
12:2d4b3f003ec2 13:65bd7e245c63
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 Chat.output_messages_html(thread) 30 function Chat.output_messages_html(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
36 for _, message in ipairs(messages) do 36 local n = 0
37 if old_thread ~= nil then
38 old_thread = json_parse(old_thread)
39 local old_messages = old_thread.messages or error
40 n = #old_messages
41 end
42 for i, message in ipairs(messages) do
43 if i <= n then
44 continue
45 end
37 local role = message.role or error() 46 local role = message.role or error()
38 local who 47 local who
39 if role=="assistant" then 48 if role=="assistant" then
40 who = "Claude" 49 who = "Claude"
41 elseif role=="user" then 50 elseif role=="user" then
94 } 103 }
95 --[=[ 104 --[=[
96 messages[#messages+1] = { 105 messages[#messages+1] = {
97 role = "assistant" 106 role = "assistant"
98 content = [[ 107 content = [[
99 uhuh 108 hello
100 ]] 109 ]]
101 } 110 }
102 if true then 111 if true then
103 return json_string(thread) 112 return json_string(thread)
104 end 113 end