Mercurial Hosting > lang
comparison src/lib/claude/Ai_chat.luan @ 77:e8219cec281f
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 01 Sep 2025 09:26:58 -0600 |
parents | 3c60bc17403e |
children | 2be9ea450de3 |
comparison
equal
deleted
inserted
replaced
76:3c60bc17403e | 77:e8219cec281f |
---|---|
21 | 21 |
22 local Ai_chat = {} | 22 local Ai_chat = {} |
23 | 23 |
24 function Ai_chat.output_system_prompt(thread) | 24 function Ai_chat.output_system_prompt(thread) |
25 thread = json_parse(thread) | 25 thread = json_parse(thread) |
26 local system_prompt = thread.system or error | 26 local system_prompt = thread.system or error() |
27 system_prompt = html_encode(system_prompt) | 27 system_prompt = html_encode(system_prompt) |
28 %><%=system_prompt%><% | 28 %><%=system_prompt%><% |
29 end | 29 end |
30 | 30 |
31 function Ai_chat.output_messages_html(assistant_controls,thread,old_thread) | 31 function Ai_chat.output_messages_html(assistant_controls,thread,old_thread) |
32 thread = json_parse(thread) | 32 thread = json_parse(thread) |
33 local messages = thread.messages or error | 33 local messages = thread.messages or error() |
34 local n = 0 | 34 local n = 0 |
35 if old_thread ~= nil then | 35 if old_thread ~= nil then |
36 old_thread = json_parse(old_thread) | 36 old_thread = json_parse(old_thread) |
37 local old_messages = old_thread.messages or error | 37 local old_messages = old_thread.messages or error() |
38 n = #old_messages | 38 n = #old_messages |
39 end | 39 end |
40 for i, message in ipairs(messages) do | 40 for i, message in ipairs(messages) do |
41 if i <= n then | 41 if i <= n then |
42 continue | 42 continue |
183 content[#content].cache_control = { type = "ephemeral" } | 183 content[#content].cache_control = { type = "ephemeral" } |
184 return claude_chat(thread) | 184 return claude_chat(thread) |
185 end | 185 end |
186 | 186 |
187 local function ask(thread) | 187 local function ask(thread) |
188 local messages = thread.messages or error | 188 local messages = thread.messages or error() |
189 --[=[ | 189 --[=[ |
190 messages[#messages+1] = { | 190 messages[#messages+1] = { |
191 role = "assistant" | 191 role = "assistant" |
192 content = [[ | 192 content = [[ |
193 hello | 193 hello |
236 end | 236 end |
237 end | 237 end |
238 | 238 |
239 function Ai_chat.add(thread,input) | 239 function Ai_chat.add(thread,input) |
240 thread = json_parse(thread) | 240 thread = json_parse(thread) |
241 local messages = thread.messages or error | 241 local messages = thread.messages or error() |
242 messages[#messages+1] = { | 242 messages[#messages+1] = { |
243 role = "user" | 243 role = "user" |
244 content = input | 244 content = input |
245 } | 245 } |
246 return json_string(thread) | 246 return json_string(thread) |