Files
claude-voice-experiment/lib/local-query-complete.mjs
mikael-lovqvists-claude-agent db8889aeed Initial commit — voice pipeline experiment
STT (Silero VAD + Whisper via sherpa-onnx), Chatterbox TTS HTTP server,
query completeness classifier (Ollama), multi-voice demo scripts, and
planning docs. Kept as reference; clean rewrite planned in separate repos.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 04:48:54 +00:00

44 lines
1.3 KiB
JavaScript

export async function is_query_complete(query, model = 'qwen2.5:3b') {
const payload = {
model,
messages: [
{
role: 'system',
content: `
You are a voice query completeness classifier. Determine if the input is complete enough to act on.
Respond only with JSON: {"complete": true} or {"complete": false}
Default to {"complete": true}. Only respond with {"complete": false} if the input is clearly mid-sentence, trails off, or is a single ambiguous word with no clear intent.
Complete examples: "What time is it", "Turn off the lights", "How do I juggle", "Make a note", "Check the weather"
Incomplete examples: "How do I", "The thing is", "Can you"
`.replace(/^[\t ]+/gm, ''),
},
{ role: 'user', content: query },
],
stream: false,
format: 'json',
options: { num_predict: 10, num_ctx: 2048 },
}
const response = await fetch('http://192.168.2.99:11434/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
})
if (response.ok) {
try {
const data = await response.json()
const parsed = JSON.parse(data.message.content)
return parsed.complete === true
} catch {
return true
}
} else {
// Fail open — if classifier errors, let the query through
return true
}
}