diff src/lib/ai/claude/Ai_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 238a91f224b1
line wrap: on
line diff
--- a/src/lib/ai/claude/Ai_chat.luan	Mon Aug 04 23:06:19 2025 -0600
+++ b/src/lib/ai/claude/Ai_chat.luan	Tue Aug 05 16:41:29 2025 -0600
@@ -18,9 +18,6 @@
 local Ai_chat = {}
 
 function Ai_chat.output_system_prompt(thread)
-	if thread == nil then
-		return
-	end
 	thread = json_parse(thread)
 	local system_prompt = thread.system or error
 	system_prompt = html_encode(system_prompt)
@@ -28,9 +25,6 @@
 end
 
 function Ai_chat.output_messages_html(show_text,thread,old_thread)
-	if thread == nil then
-		return
-	end
 	thread = json_parse(thread)
 	local messages = thread.messages or error
 	local n = 0
@@ -83,7 +77,21 @@
 end
 
 
-local function ask(thread,input)
+function Ai_chat.init(system_prompt)
+	local thread = {
+		system = system_prompt
+		messages = {nil}
+	}
+	return json_string(thread)
+end
+
+function Ai_chat.has_messages(thread)
+	thread = json_parse(thread)
+	return #thread.messages > 0
+end
+
+function Ai_chat.ask(thread,input)
+	thread = json_parse(thread)
 	local messages = thread.messages or error
 	messages[#messages+1] = {
 		role = "user"
@@ -112,22 +120,6 @@
 		role = "assistant"
 		content = content
 	}
-end
-
-function Ai_chat.ask_first(system_prompt,input)
-	local thread = {
-		system = system_prompt
-		messages = {nil}
-	}
-	if input ~= nil then
-		ask(thread,input)
-	end
-	return json_string(thread)
-end
-
-function Ai_chat.ask_more(thread,input)
-	thread = json_parse(thread)
-	ask(thread,input)
 	return json_string(thread)
 end