44 lines
1.9 KiB
Lua
44 lines
1.9 KiB
Lua
|
|
local lang = jarvis.context.language
|
||
|
|
|
||
|
|
local copy_ps = [[Add-Type -Name K -Namespace W -MemberDefinition '[DllImport("user32.dll")] public static extern void keybd_event(byte vk, byte sc, uint flags, System.UIntPtr extra);'; [W.K]::keybd_event(0x11,0,0,[UIntPtr]::Zero); [W.K]::keybd_event(0x43,0,0,[UIntPtr]::Zero); Start-Sleep -Milliseconds 40; [W.K]::keybd_event(0x43,0,2,[UIntPtr]::Zero); [W.K]::keybd_event(0x11,0,2,[UIntPtr]::Zero); Start-Sleep -Milliseconds 220]]
|
||
|
|
jarvis.system.exec(string.format('powershell -NoProfile -Command "%s"', copy_ps:gsub('"', '\\"')))
|
||
|
|
|
||
|
|
local raw = jarvis.system.clipboard.get() or ""
|
||
|
|
local text = raw:gsub("^%s+", ""):gsub("%s+$", "")
|
||
|
|
|
||
|
|
if #text < 20 then
|
||
|
|
jarvis.system.notify("Summarize",
|
||
|
|
lang == "ru" and "Сначала выдели текст и повтори" or "Select text first, then retry")
|
||
|
|
jarvis.audio.play_not_found()
|
||
|
|
return { chain = false }
|
||
|
|
end
|
||
|
|
|
||
|
|
if #text > 8000 then
|
||
|
|
text = text:sub(1, 8000) .. " ..."
|
||
|
|
end
|
||
|
|
|
||
|
|
local sys = lang == "ru"
|
||
|
|
and "Перескажи следующий текст одним абзацем (3-5 предложений). Сохрани ключевые факты и имена, без 'вот суммарно' и других вступлений."
|
||
|
|
or "Summarise the following text in 3-5 sentences. Keep key facts and names, no preamble."
|
||
|
|
|
||
|
|
local reply = jarvis.llm(
|
||
|
|
{ { role = "system", content = sys },
|
||
|
|
{ role = "user", content = text } },
|
||
|
|
{ max_tokens = 400, temperature = 0.3 }
|
||
|
|
)
|
||
|
|
|
||
|
|
if not reply or reply == "" then
|
||
|
|
jarvis.system.notify("Summarize", lang == "ru" and "LLM не ответила" or "LLM failed")
|
||
|
|
jarvis.audio.play_error()
|
||
|
|
return { chain = false }
|
||
|
|
end
|
||
|
|
|
||
|
|
jarvis.system.clipboard.set(reply)
|
||
|
|
jarvis.system.notify(
|
||
|
|
lang == "ru" and "Кратко" or "TL;DR",
|
||
|
|
reply:sub(1, 280)
|
||
|
|
)
|
||
|
|
jarvis.speak(reply, { lang = lang })
|
||
|
|
jarvis.audio.play_ok()
|
||
|
|
return { chain = false }
|