Skip to content

Commit e513dd0

Browse files
authored
Merge pull request drewbaumann#26 from boypt/fix_anotherqx
fix: ask another question buttons knows nothing about user reading texts
2 parents 74ea9fa + 5b6d727 commit e513dd0

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

dialogs.lua

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ local function getBookContext(ui)
5050
}
5151
end
5252

53+
local function formatUserPrompt(user_prompt, highlightedText, ui)
54+
local book = getBookContext(ui)
55+
local formatted_user_prompt = (user_prompt or "Please analyze: ")
56+
:gsub("{title}", book.title)
57+
:gsub("{author}", book.author)
58+
:gsub("{highlight}", highlightedText)
59+
60+
local formatted_user_content = ""
61+
if string.find(user_prompt or "Please analyze: ", "{highlight}") then
62+
formatted_user_content = formatted_user_prompt
63+
else
64+
formatted_user_content = formatted_user_prompt .. highlightedText
65+
end
66+
67+
return formatted_user_content
68+
end
69+
5370
local function createContextMessage(ui, highlightedText)
5471
local book = getBookContext(ui)
5572
return {
@@ -66,7 +83,7 @@ local function handleFollowUpQuestion(message_history, new_question, ui, highlig
6683

6784
local question_message = {
6885
role = "user",
69-
content = new_question
86+
content = formatUserPrompt(new_question, highlightedText, ui)
7087
}
7188
table.insert(message_history, question_message)
7289

@@ -181,19 +198,7 @@ local function handlePredefinedPrompt(prompt_type, highlightedText, ui)
181198
return nil, "Prompt '" .. prompt_type .. "' not found"
182199
end
183200

184-
local book = getBookContext(ui)
185-
local formatted_user_prompt = (prompt.user_prompt or "Please analyze: ")
186-
:gsub("{title}", book.title)
187-
:gsub("{author}", book.author)
188-
:gsub("{highlight}", highlightedText)
189-
190-
local user_content = ""
191-
if string.find(prompt.user_prompt or "Please analyze: ", "{highlight}") then
192-
user_content = formatted_user_prompt
193-
else
194-
user_content = formatted_user_prompt .. highlightedText
195-
end
196-
201+
local user_content = formatUserPrompt(prompt.user_prompt, highlightedText, ui)
197202
local message_history = {
198203
{
199204
role = "system",

0 commit comments

Comments
 (0)