Mercurial Hosting > lang
comparison src/lib/Chat.luan @ 35:3117876debca
ai_first_message in textarea
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 05 Aug 2025 16:41:29 -0600 |
parents | 0fb3488a017d |
children | 2737eeedc1d5 |
comparison
equal
deleted
inserted
replaced
34:0fb3488a017d | 35:3117876debca |
---|---|
41 id = chat.id | 41 id = chat.id |
42 chat_user_id = long(chat.user_id) | 42 chat_user_id = long(chat.user_id) |
43 chat_updated = long(chat.updated) | 43 chat_updated = long(chat.updated) |
44 course_id = long(chat.course_id) | 44 course_id = long(chat.course_id) |
45 name = chat.name or error() | 45 name = chat.name or error() |
46 ai_thread = chat.ai_thread | 46 ai_thread = chat.ai_thread or error() |
47 language = chat.language or error() | 47 language = chat.language or error() |
48 language_region = chat.language_region or error() | 48 language_region = chat.language_region or error() |
49 voice = chat.voice or error() | 49 voice = chat.voice or error() |
50 show_text = chat.show_text and "true" or "false" | 50 show_text = chat.show_text and "true" or "false" |
51 } | 51 } |
87 | 87 |
88 function chat.name_html() | 88 function chat.name_html() |
89 return html_encode(chat.name) | 89 return html_encode(chat.name) |
90 end | 90 end |
91 | 91 |
92 function chat.init_ai() -- return if added message | 92 function chat.init_text() -- return text for textarea |
93 if chat.ai_thread ~= nil then | 93 if Ai_chat.has_messages(chat.ai_thread) then |
94 return false | 94 return "" |
95 end | 95 end |
96 local course = get_course_by_id(chat.course_id) or error() | 96 local course = get_course_by_id(chat.course_id) or error() |
97 local ai_first_message = course.ai_first_message | 97 return course.ai_first_message or error() |
98 local ai_thread = Ai_chat.ask_first(course.ai_system_prompt,ai_first_message) | |
99 run_in_transaction( function() | |
100 chat = chat.reload() | |
101 chat.ai_thread = ai_thread | |
102 chat.save() | |
103 end ) | |
104 return ai_first_message ~= nil | |
105 end | 98 end |
106 | 99 |
107 function chat.output_system_prompt() | 100 function chat.output_system_prompt() |
108 Ai_chat.output_system_prompt(chat.ai_thread) | 101 Ai_chat.output_system_prompt(chat.ai_thread) |
109 end | 102 end |
112 Ai_chat.output_messages_html(chat.show_text,chat.ai_thread) | 105 Ai_chat.output_messages_html(chat.show_text,chat.ai_thread) |
113 end | 106 end |
114 | 107 |
115 function chat.ask(input) | 108 function chat.ask(input) |
116 local old_thread = chat.ai_thread | 109 local old_thread = chat.ai_thread |
117 local ai_thread = Ai_chat.ask_more(old_thread,input) | 110 local ai_thread = Ai_chat.ask(old_thread,input) |
118 run_in_transaction( function() | 111 run_in_transaction( function() |
119 chat = chat.reload() | 112 chat = chat.reload() |
120 chat.ai_thread = ai_thread | 113 chat.ai_thread = ai_thread |
121 chat.save() | 114 chat.save() |
122 end ) | 115 end ) |