diff src/lib/ai/claude/Ai_chat.luan @ 74:64e35a92d163

add translation
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 28 Aug 2025 13:31:46 -0600
parents 44bec62c49e2
children
line wrap: on
line diff
--- a/src/lib/ai/claude/Ai_chat.luan	Thu Aug 28 05:16:32 2025 -0600
+++ b/src/lib/ai/claude/Ai_chat.luan	Thu Aug 28 13:31:46 2025 -0600
@@ -13,6 +13,8 @@
 local Thread = require "luan:Thread.luan"
 local Claude = require "site:/lib/ai/claude/Claude.luan"
 local claude_chat = Claude.chat or error()
+local Utils = require "site:/lib/Utils.luan"
+local deep_copy = Utils.deep_copy or error()
 local Logging = require "luan:logging/Logging.luan"
 local logger = Logging.logger "claude/Ai_chat"
 
@@ -51,8 +53,8 @@
 		local function output(text)
 			text = html_encode(text)
 %>
-			<h3><%=who%></h3>
-			<div role="<%=role%>">
+			<div role="<%=role%>" msg="<%=i%>">
+				<h3><%=who%></h3>
 				<div message markdown><%=text%></div>
 <%			if role=="assistant" then %>
 <%=				assistant_controls %>
@@ -164,6 +166,24 @@
 	return #thread.messages > 0
 end
 
+local function chit_chat(thread)
+	thread = deep_copy(thread)
+	local messages = thread.messages or error()
+	for _, message in ipairs(messages) do
+		local content = message.content or error()
+		if type(content) == "string" then
+			content = {{
+				type = "text"
+				text = content
+			}}
+			message.content = content
+		end
+	end
+	local content = messages[#messages].content or error()
+	content[#content].cache_control = { type = "ephemeral" }
+	return claude_chat(thread)
+end
+
 local function ask(thread)
 	local messages = thread.messages or error
 --[=[
@@ -179,7 +199,7 @@
 	end
 --]=]
 	-- logger.info(json_string(thread))
-	local resultJson = claude_chat(thread)
+	local resultJson = chit_chat(thread)
 	local result = json_parse(resultJson)
 	-- logger.info(json_string(result))
 	result.type == "message" or error()