v64: рефакторинг — разбил монолит на css/ js/ build.sh dist/ (781→43 строки index.html)
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// ---------- Groq API: транскрипция и перевод ----------
|
||||
|
||||
async function transcribe(blob) {
|
||||
if (!GROQ_API_KEY) return { text: '', error: 'no_key' };
|
||||
const tStart = performance.now();
|
||||
|
||||
const form = new FormData();
|
||||
form.append('file', blob, 'audio.webm');
|
||||
form.append('model', 'whisper-large-v3');
|
||||
form.append('language', 'it');
|
||||
|
||||
console.log('[HTTP] blob ' + (blob.size/1024).toFixed(1) + 'KB → multipart POST');
|
||||
|
||||
try {
|
||||
const r = await fetch('https://proxy.kube5s.ru/openai/v1/audio/transcriptions', {
|
||||
method: 'POST',
|
||||
headers: { 'Authorization': 'Bearer ' + GROQ_API_KEY },
|
||||
body: form
|
||||
});
|
||||
const data = await r.json();
|
||||
console.log('[HTTP] ← ' + ((performance.now()-tStart)/1000).toFixed(2) + 's → ' + (data.text||'(empty)'));
|
||||
return data.error ? { text: '', error: data.error } : { text: data.text || '', error: null };
|
||||
} catch(e) {
|
||||
console.log('[HTTP] ERR', e);
|
||||
return { text: '', error: 'network' };
|
||||
}
|
||||
}
|
||||
|
||||
async function translateToRussian(text) {
|
||||
if (!GROQ_API_KEY) return;
|
||||
try {
|
||||
const res = await fetch('https://proxy.kube5s.ru/openai/v1/chat/completions', {
|
||||
method: 'POST',
|
||||
headers: { 'Authorization': `Bearer ${GROQ_API_KEY}`, 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
model: 'llama-3.3-70b-versatile',
|
||||
messages: [{ role: 'user', content: 'Переведи на русский одним словом или фразой: ' + text }],
|
||||
max_tokens: 50,
|
||||
temperature: 0
|
||||
})
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data.choices?.[0]?.message?.content) {
|
||||
document.getElementById('translation').textContent = '🇷🇺 ' + data.choices[0].message.content;
|
||||
}
|
||||
} catch(e) { /* тихо */ }
|
||||
}
|
||||
Reference in New Issue
Block a user