feat: Ollama LLM backend + 5 utility packs (daily briefing, pomodoro, currency convert, stocks, habits, translate clipboard)
Local-LLM support so J.A.R.V.I.S. works offline without GROQ_TOKEN.
LLM multi-backend (crates/jarvis-core/src/llm/client.rs)
- LlmBackend enum {Groq, Ollama}. Both use OpenAI-compatible /v1/chat/completions
(Ollama exposes one natively at :11434/v1).
- LlmClient::from_env() now dispatches on JARVIS_LLM=groq|ollama. Auto-detect:
Groq if GROQ_TOKEN set, else Ollama.
- New helpers: LlmClient::groq() (was: from_env), LlmClient::ollama().
- Reqwest client now has a 60s timeout (was: unbounded — Groq freezes could hang).
- api_key skipped when empty (Ollama doesn't need auth).
- Defaults: OLLAMA_BASE_URL=http://localhost:11434/v1, OLLAMA_MODEL=qwen2.5:3b.
Override via OLLAMA_BASE_URL / OLLAMA_MODEL env.
- llm_fallback + llm_router log the active backend on init.
- Tests: 32/32 pass. Renamed `from_env_fails` → `groq_fails_when_token_missing`,
added `ollama_works_without_token`.
Daily briefing pack (resources/commands/daily_briefing/, 3 commands)
- setup.lua: "настрой утренний брифинг на 9:00" → adds a daily scheduled task
that runs now.lua via the scheduler's Lua-action support.
- now.lua: greeting + time + active profile + scheduled task count + memory recap
+ LLM motivational nudge. Voice-triggered ("утренний брифинг") works the same.
- off.lua: removes the scheduled task.
Pomodoro pack (resources/commands/pomodoro/, 2 commands)
- start.lua / stop.lua + tick.lua (re-scheduled by itself). State stored in
jarvis.state — phase alternates work (25 min) / break (5 min) until stop.
Currency conversion (resources/commands/currency/convert.lua)
- "сколько будет 1000 долларов в рублях" — fetches CBR daily rates from
cbr-xml-daily.ru, normalises by Nominal, prints both directions.
- Recognises USD/EUR/CNY/GBP/JPY/RUB by substring. Pluralises russian units.
Stocks pack (resources/commands/stocks/, 1 command)
- "сколько Сбер" → MOEX ISS /iss/engines/stock/markets/shares/securities/<TKR>.
- Mapping of 22 popular Russian tickers to common names (Сбер→SBER, Газпром→GAZP,
Лукойл→LKOH, Яндекс→YDEX, Т-банк→T, etc).
- Picks TQBR (main board) row, reports LAST + LASTTOPREVPRICE%.
Habit nudges (resources/commands/habit_nudge/, 4 commands)
- "напоминай мне пить воду" → every 2 hours
- "напоминай мне размяться" → every 50 minutes
- "напоминай отдыхать глазам" → every 20 minutes (20-20-20 rule)
- "отключи все привычки" → stops all three by id.
Translate clipboard (resources/commands/translate/clipboard.lua)
- "переведи буфер на английский" → grabs clipboard, sends to LLM, speaks first
sentence, replaces clipboard with full translation, fires notification.
Build: cargo build --release -p jarvis-app -p jarvis-gui both green. 32/32 tests.
To use Ollama:
1. Install + run Ollama (https://ollama.com).
2. `ollama pull qwen2.5:3b` (or any chat model).
3. Optional: `set JARVIS_LLM=ollama` (auto-picked if GROQ_TOKEN unset).
This commit is contained in:
parent
12b1ed4ccb
commit
45243c3e3c
22 changed files with 895 additions and 16 deletions
54
resources/commands/daily_briefing/command.toml
Normal file
54
resources/commands/daily_briefing/command.toml
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# Daily briefing — chains time + weather + memory + scheduler at a fixed time.
|
||||
|
||||
[[commands]]
|
||||
id = "daily_briefing.setup"
|
||||
type = "lua"
|
||||
script = "setup.lua"
|
||||
sandbox = "standard"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"настрой утренний брифинг",
|
||||
"включи утренний брифинг",
|
||||
"начни утренний брифинг каждый день",
|
||||
"сделай утренний брифинг",
|
||||
]
|
||||
en = ["set up morning briefing", "enable morning briefing", "daily briefing"]
|
||||
ua = ["налаштуй ранковий брифінг", "увімкни ранковий брифінг"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "daily_briefing.now"
|
||||
type = "lua"
|
||||
script = "now.lua"
|
||||
sandbox = "standard"
|
||||
timeout = 15000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"утренний брифинг",
|
||||
"сделай брифинг",
|
||||
"брифинг сейчас",
|
||||
"что нового",
|
||||
"сводка дня",
|
||||
]
|
||||
en = ["morning briefing", "give me a briefing", "what's new today"]
|
||||
ua = ["ранковий брифінг", "брифінг зараз"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "daily_briefing.off"
|
||||
type = "lua"
|
||||
script = "off.lua"
|
||||
sandbox = "minimal"
|
||||
timeout = 2000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"отключи утренний брифинг",
|
||||
"выключи утренний брифинг",
|
||||
"отмени брифинг",
|
||||
]
|
||||
en = ["disable morning briefing", "cancel morning briefing"]
|
||||
ua = ["вимкни ранковий брифінг"]
|
||||
64
resources/commands/daily_briefing/now.lua
Normal file
64
resources/commands/daily_briefing/now.lua
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
-- The actual briefing body. Called either directly ("утренний брифинг") OR
|
||||
-- by the scheduler at the configured daily time.
|
||||
local t = jarvis.context.time
|
||||
local lang = jarvis.context.language or "ru"
|
||||
|
||||
-- 1) Greeting + time
|
||||
local hour = t.hour
|
||||
local greeting
|
||||
if hour >= 5 and hour < 12 then greeting = "Доброе утро."
|
||||
elseif hour >= 12 and hour < 18 then greeting = "Добрый день."
|
||||
elseif hour >= 18 and hour < 23 then greeting = "Добрый вечер."
|
||||
else greeting = "Сэр." end
|
||||
|
||||
jarvis.speak(greeting .. string.format(" Сейчас %d:%02d.", hour, t.minute))
|
||||
jarvis.sleep(300)
|
||||
|
||||
-- 2) Profile-aware tone
|
||||
local prof = jarvis.profile.active()
|
||||
if prof and prof.name and prof.name ~= "default" then
|
||||
jarvis.speak("Активный режим: " .. prof.name .. ".")
|
||||
jarvis.sleep(200)
|
||||
end
|
||||
|
||||
-- 3) Scheduled tasks ahead today
|
||||
local tasks = jarvis.scheduler.list()
|
||||
if tasks and #tasks > 0 then
|
||||
local count = 0
|
||||
for _, task in ipairs(tasks) do
|
||||
if task.action and task.action.type == "speak" then
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
if count > 0 then
|
||||
jarvis.speak(string.format("Запланировано задач: %d.", count))
|
||||
jarvis.sleep(200)
|
||||
end
|
||||
end
|
||||
|
||||
-- 4) Memory recap (most recently used 3)
|
||||
local memos = jarvis.memory.all()
|
||||
if memos and #memos > 0 then
|
||||
local sample = math.min(2, #memos)
|
||||
local line = "Из памяти: "
|
||||
for i = 1, sample do
|
||||
line = line .. memos[i].key .. " — " .. memos[i].value
|
||||
if i < sample then line = line .. "; " end
|
||||
end
|
||||
line = line .. "."
|
||||
jarvis.speak(line)
|
||||
jarvis.sleep(200)
|
||||
end
|
||||
|
||||
-- 5) Closing nudge from LLM if available
|
||||
local nudge = jarvis.llm({
|
||||
{ role = "system", content = "Ты — Джарвис. Одна короткая фраза-мотиватор на день. По-русски. 5-10 слов." },
|
||||
{ role = "user", content = string.format("Сейчас %d часов %02d минут, режим: %s.", hour, t.minute, prof and prof.name or "default") }
|
||||
}, { max_tokens = 60, temperature = 0.8 })
|
||||
|
||||
if nudge and nudge ~= "" then
|
||||
jarvis.speak(nudge)
|
||||
end
|
||||
|
||||
jarvis.audio.play_ok()
|
||||
return { chain = false }
|
||||
9
resources/commands/daily_briefing/off.lua
Normal file
9
resources/commands/daily_briefing/off.lua
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
local removed = jarvis.scheduler.remove("daily_briefing_main")
|
||||
if removed then
|
||||
jarvis.speak("Утренний брифинг отключен.")
|
||||
jarvis.audio.play_ok()
|
||||
else
|
||||
jarvis.speak("Брифинг и так не был настроен.")
|
||||
jarvis.audio.play_not_found()
|
||||
end
|
||||
return { chain = false }
|
||||
38
resources/commands/daily_briefing/setup.lua
Normal file
38
resources/commands/daily_briefing/setup.lua
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
-- "Настрой утренний брифинг на 9:00" → adds a daily scheduled task that runs now.lua
|
||||
local phrase = (jarvis.context.phrase or ""):lower()
|
||||
|
||||
-- try to extract HH:MM, default 9:00
|
||||
local h, m = phrase:match("(%d%d?)[:%s%-](%d%d)")
|
||||
if not h then
|
||||
h = phrase:match("(%d%d?)")
|
||||
end
|
||||
local hh = tonumber(h) or 9
|
||||
local mm = tonumber(m) or 0
|
||||
if hh < 0 or hh > 23 or mm < 0 or mm > 59 then hh = 9; mm = 0 end
|
||||
|
||||
local script_path = jarvis.context.command_path .. "/now.lua"
|
||||
script_path = script_path:gsub("/", "\\")
|
||||
|
||||
local id = "daily_briefing_main"
|
||||
|
||||
local ok, err = pcall(function()
|
||||
-- replace any prior briefing
|
||||
jarvis.scheduler.remove(id)
|
||||
jarvis.scheduler.add({
|
||||
id = id,
|
||||
name = "Daily briefing",
|
||||
schedule = string.format("daily %02d:%02d", hh, mm),
|
||||
action = { type = "lua", script_path = script_path },
|
||||
})
|
||||
end)
|
||||
|
||||
if not ok then
|
||||
jarvis.log("warn", "daily_briefing.setup: " .. tostring(err))
|
||||
jarvis.speak("Не получилось настроить брифинг.")
|
||||
jarvis.audio.play_error()
|
||||
return { chain = false }
|
||||
end
|
||||
|
||||
jarvis.speak(string.format("Утренний брифинг настроен на %02d:%02d.", hh, mm))
|
||||
jarvis.audio.play_ok()
|
||||
return { chain = false }
|
||||
Loading…
Add table
Add a link
Reference in a new issue