feat: persist LLM/TTS backend choice + reset/repeat context + quick-search + diagnostics
Closes the UX hole I created in 5c72450: voice-swap to Ollama used to vanish
after restart. Plus P0.3 (long-standing roadmap item) and two new packs.
Persistent backend choice (crates/jarvis-core/src/db/structs.rs)
- Settings struct gains llm_backend + tts_backend fields (both String,
"" / "auto" = follow env/auto-detect).
- set("llm_backend", "groq"|"ollama"|"auto") validates input.
- llm::init_global() reads DB first, then JARVIS_LLM env, then auto-detect.
- llm::swap_to() now persists the choice via db::save_settings.
- Voice swap "переключись на локальный" now survives restart.
Shared conversation history (P0.3, crates/jarvis-core/src/llm/mod.rs)
- HISTORY: Lazy<RwLock<Option<ConversationHistory>>> singleton.
- Helpers: init_history, history_push_user, history_push_assistant,
history_snapshot, history_clear, history_pop_last_user, history_last_assistant.
- llm_fallback migrated off its own Mutex<History> — now reads/writes shared.
- ConversationHistory gains last_assistant() method.
New Lua APIs
- jarvis.llm_reset() → clear conversation turns (keeps system prompt).
- jarvis.llm_last_reply() → string or nil (last assistant message text).
- jarvis.health() → debug table {tts_backend, llm_backend, llm_model,
active_profile, memory_facts, scheduled_tasks,
language, voice, microphone, vosk_model,
noise_suppression}. No secrets included.
New voice packs
- resources/commands/llm_context/ (P0.3)
* "сбрось контекст" / "забудь разговор" → llm.reset
* "повтори последнее" / "повтори ответ" → llm.repeat (uses last_assistant)
- resources/commands/quick_search/ (imba P1 item)
* "найди в гугле <X>" / "загугли <X>"
* Uses DuckDuckGo Instant Answer API (api.duckduckgo.com, no key required).
Pulls AbstractText or RelatedTopics into LLM prompt; falls back to pure
LLM knowledge if DDG returns nothing useful. Speaks 2-4 sentence answer.
- resources/commands/diagnostics/
* "диагностика" / "доложи о себе" / "статус"
* Reads jarvis.health() and speaks a one-line summary. Useful when
debugging — user can read out their current state for a bug report.
Build: cargo build --release -p jarvis-app -p jarvis-gui green.
Tests: 52/52 jarvis-core unit tests pass.
This commit is contained in:
parent
5c7245012e
commit
385bd5c8ce
15 changed files with 413 additions and 37 deletions
21
resources/commands/diagnostics/command.toml
Normal file
21
resources/commands/diagnostics/command.toml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Diagnostics — speak a summary of the active runtime state. Useful when
|
||||
# something is misbehaving and you want to know which backends are active.
|
||||
|
||||
[[commands]]
|
||||
id = "diagnostics.health"
|
||||
type = "lua"
|
||||
script = "health.lua"
|
||||
sandbox = "standard"
|
||||
timeout = 3000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"диагностика",
|
||||
"состояние системы",
|
||||
"статус",
|
||||
"что у тебя сейчас",
|
||||
"проверка системы",
|
||||
"доложи о себе",
|
||||
]
|
||||
en = ["diagnostics", "status report", "health check"]
|
||||
ua = ["діагностика", "стан системи"]
|
||||
11
resources/commands/diagnostics/health.lua
Normal file
11
resources/commands/diagnostics/health.lua
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
local h = jarvis.health()
|
||||
local line = string.format(
|
||||
"TTS: %s. LLM: %s. Профиль: %s. Памяти фактов: %d. Запланировано: %d. Язык: %s.",
|
||||
h.tts_backend or "—",
|
||||
h.llm_backend or "—",
|
||||
h.active_profile or "—",
|
||||
h.memory_facts or 0,
|
||||
h.scheduled_tasks or 0,
|
||||
h.language or "—"
|
||||
)
|
||||
return jarvis.cmd.ok(line)
|
||||
39
resources/commands/llm_context/command.toml
Normal file
39
resources/commands/llm_context/command.toml
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# P0.3: Conversation context controls — reset / repeat last reply.
|
||||
|
||||
[[commands]]
|
||||
id = "llm.reset"
|
||||
type = "lua"
|
||||
script = "reset.lua"
|
||||
sandbox = "standard"
|
||||
timeout = 2000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"сбрось контекст",
|
||||
"сбрось разговор",
|
||||
"забудь о чём мы говорили",
|
||||
"забудь разговор",
|
||||
"начни разговор заново",
|
||||
"очисти контекст",
|
||||
]
|
||||
en = ["reset context", "forget conversation", "start fresh"]
|
||||
ua = ["скинь контекст", "забудь розмову"]
|
||||
|
||||
|
||||
[[commands]]
|
||||
id = "llm.repeat"
|
||||
type = "lua"
|
||||
script = "repeat.lua"
|
||||
sandbox = "standard"
|
||||
timeout = 5000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"повтори последнее",
|
||||
"повтори что сказал",
|
||||
"повтори ответ",
|
||||
"что ты сказал",
|
||||
"повтори",
|
||||
]
|
||||
en = ["repeat", "say it again", "repeat the last answer"]
|
||||
ua = ["повтори", "повтори що сказав"]
|
||||
5
resources/commands/llm_context/repeat.lua
Normal file
5
resources/commands/llm_context/repeat.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
local last = jarvis.llm_last_reply()
|
||||
if not last or last == "" then
|
||||
return jarvis.cmd.not_found("Мне нечего повторить.")
|
||||
end
|
||||
return jarvis.cmd.ok(last)
|
||||
2
resources/commands/llm_context/reset.lua
Normal file
2
resources/commands/llm_context/reset.lua
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
jarvis.llm_reset()
|
||||
return jarvis.cmd.ok("Контекст сброшен.")
|
||||
31
resources/commands/quick_search/command.toml
Normal file
31
resources/commands/quick_search/command.toml
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# Quick-search-read — answer questions using DuckDuckGo Instant Answer API + LLM.
|
||||
# No API key required. Falls back to pure LLM if web search returns nothing.
|
||||
|
||||
[[commands]]
|
||||
id = "quick_search"
|
||||
type = "lua"
|
||||
script = "search.lua"
|
||||
sandbox = "full"
|
||||
timeout = 30000
|
||||
|
||||
[commands.phrases]
|
||||
ru = [
|
||||
"найди в гугле",
|
||||
"найди в интернете",
|
||||
"поищи в гугле",
|
||||
"найди и расскажи",
|
||||
"загугли",
|
||||
"посмотри в гугле",
|
||||
"поищи информацию",
|
||||
"найди информацию о",
|
||||
]
|
||||
en = [
|
||||
"google for",
|
||||
"search for",
|
||||
"find online",
|
||||
"look up",
|
||||
]
|
||||
ua = [
|
||||
"знайди в гуглі",
|
||||
"погугли",
|
||||
]
|
||||
83
resources/commands/quick_search/search.lua
Normal file
83
resources/commands/quick_search/search.lua
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
-- "Найди в гугле что такое квантовая запутанность"
|
||||
-- Uses DuckDuckGo's free Instant Answer API (api.duckduckgo.com). No key.
|
||||
-- The IA response often has a "Abstract" / "AbstractText" / "AbstractURL" set
|
||||
-- for well-known topics. We feed Abstract + RelatedTopics to the LLM for a
|
||||
-- spoken summary. Falls back to pure LLM knowledge if DDG returns nothing useful.
|
||||
|
||||
local phrase = (jarvis.context.phrase or "")
|
||||
|
||||
local query = jarvis.text.strip_trigger(phrase:lower(), {
|
||||
"найди и расскажи",
|
||||
"найди в гугле",
|
||||
"найди в интернете",
|
||||
"поищи в гугле",
|
||||
"посмотри в гугле",
|
||||
"загугли",
|
||||
"поищи информацию о",
|
||||
"поищи информацию",
|
||||
"найди информацию о",
|
||||
"google for",
|
||||
"search for",
|
||||
"find online",
|
||||
"look up",
|
||||
"знайди в гуглі",
|
||||
"погугли",
|
||||
})
|
||||
query = query:gsub("^[%s,:%.]+", ""):gsub("%s+$", "")
|
||||
|
||||
if query == "" then
|
||||
return jarvis.cmd.error("Что искать?")
|
||||
end
|
||||
|
||||
local function urlencode(s)
|
||||
return (s:gsub("[^A-Za-z0-9%-_%.~]", function(c)
|
||||
return string.format("%%%02X", string.byte(c))
|
||||
end))
|
||||
end
|
||||
|
||||
local url = "https://api.duckduckgo.com/?q=" .. urlencode(query)
|
||||
.. "&format=json&no_html=1&skip_disambig=1"
|
||||
|
||||
local data = jarvis.http.json(url)
|
||||
|
||||
local context = ""
|
||||
if data then
|
||||
if data.AbstractText and data.AbstractText ~= "" then
|
||||
context = data.AbstractText
|
||||
if data.AbstractURL and data.AbstractURL ~= "" then
|
||||
context = context .. "\nИсточник: " .. data.AbstractURL
|
||||
end
|
||||
elseif data.RelatedTopics and #data.RelatedTopics > 0 then
|
||||
local lines = {}
|
||||
for i = 1, math.min(4, #data.RelatedTopics) do
|
||||
local t = data.RelatedTopics[i]
|
||||
if t.Text then table.insert(lines, t.Text) end
|
||||
end
|
||||
context = table.concat(lines, "\n")
|
||||
end
|
||||
end
|
||||
|
||||
local user_prompt
|
||||
if context ~= "" then
|
||||
user_prompt = string.format(
|
||||
"Вопрос пользователя: %s\n\nДанные из веб-поиска:\n%s\n\nОтветь на вопрос по-русски, кратко (2-4 предложения), используя данные. Если данных мало — добавь из своих знаний.",
|
||||
query, context
|
||||
)
|
||||
else
|
||||
user_prompt = string.format(
|
||||
"Вопрос пользователя: %s\n\nВеб-поиск ничего полезного не дал. Ответь по-русски кратко (2-4 предложения), используя свои знания. Если не уверен — скажи об этом.",
|
||||
query
|
||||
)
|
||||
end
|
||||
|
||||
local answer = jarvis.llm({
|
||||
{ role = "system", content = "Ты — справочный помощник. Отвечай кратко и по делу, без вводных фраз." },
|
||||
{ role = "user", content = user_prompt }
|
||||
}, { max_tokens = 350, temperature = 0.3 })
|
||||
|
||||
if not answer or answer == "" then
|
||||
return jarvis.cmd.error("Не получилось получить ответ.")
|
||||
end
|
||||
|
||||
jarvis.system.notify("Поиск: " .. query, answer:sub(1, 200))
|
||||
return jarvis.cmd.ok(answer)
|
||||
Loading…
Add table
Add a link
Reference in a new issue