Mercurial Hosting > lang
comparison src/lib/Chat.luan @ 52:27758f3b2d69
add hide_ruby
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 16 Aug 2025 09:56:10 +0900 |
parents | cc20eebaa74a |
children | ecb851fabd75 |
comparison
equal
deleted
inserted
replaced
51:4581a20b8124 | 52:27758f3b2d69 |
---|---|
29 name = doc.name | 29 name = doc.name |
30 ai_thread = doc.ai_thread | 30 ai_thread = doc.ai_thread |
31 language = doc.language | 31 language = doc.language |
32 tts_instructions = doc.tts_instructions | 32 tts_instructions = doc.tts_instructions |
33 voice = doc.voice | 33 voice = doc.voice |
34 show_text = doc.show_text == "true" | 34 show_text = doc.show_text |
35 autoplay = doc.autoplay == "true" | 35 autoplay = doc.autoplay == "true" |
36 is_private = doc.is_private == "true" | 36 is_private = doc.is_private == "true" |
37 has_ruby = doc.has_ruby == "true" | |
37 } | 38 } |
38 end | 39 end |
39 | 40 |
40 local function to_doc(chat) | 41 local function to_doc(chat) |
41 return { | 42 return { |
47 name = chat.name or error() | 48 name = chat.name or error() |
48 ai_thread = chat.ai_thread or error() | 49 ai_thread = chat.ai_thread or error() |
49 language = chat.language or error() | 50 language = chat.language or error() |
50 tts_instructions = chat.tts_instructions -- or error() | 51 tts_instructions = chat.tts_instructions -- or error() |
51 voice = chat.voice or error() | 52 voice = chat.voice or error() |
52 show_text = chat.show_text and "true" or "false" | 53 show_text = chat.show_text |
53 autoplay = chat.autoplay and "true" or "false" | 54 autoplay = chat.autoplay and "true" or "false" |
54 is_private = chat.is_private and "true" or nil | 55 is_private = chat.is_private and "true" or nil |
56 has_ruby = chat.has_ruby and "true" or nil | |
55 } | 57 } |
56 end | 58 end |
57 | 59 |
58 function Chat.new(chat) | 60 function Chat.new(chat) |
59 chat.updated = chat.updated or time_now() | 61 chat.updated = chat.updated or time_now() |
60 chat.voice = chat.voice or voices[1] | 62 chat.voice = chat.voice or voices[1] |
61 if chat.show_text==nil then chat.show_text = true end | |
62 if chat.autoplay==nil then chat.autoplay = true end | 63 if chat.autoplay==nil then chat.autoplay = true end |
63 | 64 |
64 function chat.save() | 65 function chat.save() |
65 local doc = to_doc(chat) | 66 local doc = to_doc(chat) |
66 Db.save(doc) | 67 Db.save(doc) |
101 | 102 |
102 function chat.output_system_prompt() | 103 function chat.output_system_prompt() |
103 Ai_chat.output_system_prompt(chat.ai_thread) | 104 Ai_chat.output_system_prompt(chat.ai_thread) |
104 end | 105 end |
105 | 106 |
107 local function option(name,text) | |
108 local selected = name==chat.show_text and " selected" or "" | |
109 %> | |
110 <option <%=name%><%=selected%>><%=text%></option> | |
111 <% | |
112 end | |
113 | |
114 local function assistant_controls() | |
115 return `%> | |
116 <div controls> | |
117 <audio controls preload=none></audio> | |
118 <select> | |
119 <% | |
120 option("show_text","Show text") | |
121 if chat.has_ruby then | |
122 option("hide_ruby","Hide pronunciation") | |
123 end | |
124 option("hide_text","Hide text") | |
125 %> | |
126 </select> | |
127 </div> | |
128 <% ` | |
129 end | |
130 | |
106 function chat.output_messages_html() | 131 function chat.output_messages_html() |
107 Ai_chat.output_messages_html(chat.show_text,chat.ai_thread) | 132 Ai_chat.output_messages_html(assistant_controls(),chat.ai_thread) |
108 end | 133 end |
109 | 134 |
110 function chat.ask(input) | 135 function chat.ask(input) |
111 local old_thread = chat.ai_thread | 136 local old_thread = chat.ai_thread |
112 local ai_thread = Ai_chat.ask(old_thread,input) | 137 local ai_thread = Ai_chat.ask(old_thread,input) |
113 run_in_transaction( function() | 138 run_in_transaction( function() |
114 chat = chat.reload() | 139 chat = chat.reload() |
115 chat.ai_thread = ai_thread | 140 chat.ai_thread = ai_thread |
116 chat.save() | 141 chat.save() |
117 end ) | 142 end ) |
118 return `Ai_chat.output_messages_html(chat.show_text,ai_thread,old_thread)` | 143 return `Ai_chat.output_messages_html(assistant_controls(),ai_thread,old_thread)` |
119 end | 144 end |
120 | 145 |
121 function chat.language_name() | 146 function chat.language_name() |
122 return languages[chat.language] | 147 return languages[chat.language] |
123 end | 148 end |