Skip to content

Commit 494400a

Browse files
authored
Improve error handling and add new utility functions
Refactor error handling and add new functions for script generation and podcast audio.
1 parent a68c8da commit 494400a

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

services/geminiService.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
1-
const TUNNEL_URL = "https://clients-update-scientists-mouth.trycloudflare.com"; // Zkontroluj, zda je tato URL stále aktuální!
1+
const TUNNEL_URL = "https://clients-update-scientists-mouth.trycloudflare.com";
22

33
export const sendMessageToGemini = async (prompt: string) => {
44
try {
55
const response = await fetch(`${TUNNEL_URL}/api/generate`, {
66
method: 'POST',
7-
headers: {
8-
'Content-Type': 'application/json',
9-
},
7+
headers: { 'Content-Type': 'application/json' },
108
body: JSON.stringify({
119
model: 'gemma3:4b',
1210
prompt: prompt,
1311
stream: false
1412
})
1513
});
1614

17-
if (!response.ok) {
18-
const errorText = await response.text();
19-
console.error('Chyba z Raspberry:', errorText);
20-
throw new Error(`Raspberry Pi vrátilo chybu: ${response.status}`);
21-
}
15+
if (!response.ok) throw new Error(`Raspberry Pi vrátilo chybu: ${response.status}`);
2216

2317
const data = await response.json();
24-
console.log('Data z Ollamy:', data); // Toto uvidíš v konzoli F12
25-
26-
// Ollama vrací text v poli "response"
2718
return data.response || "AI vrátila prázdnou odpověď.";
28-
2919
} catch (error) {
3020
console.error('Chyba při volání AI:', error);
3121
throw error;
3222
}
3323
};
24+
25+
// TYTO FUNKCE NESMÍ CHYBĚT, JINAK BUILD SPADNE:
26+
export const generateScriptFromMaterial = async (material: any) => {
27+
const prompt = `Vytvoř studijní scénář z tohoto materiálu: ${JSON.stringify(material)}`;
28+
return await sendMessageToGemini(prompt);
29+
};
30+
31+
export const generatePodcastAudio = async (text: string) => {
32+
// Zatím jen simulace, aby aplikace běžela
33+
console.log("Generuji audio pro:", text);
34+
return "";
35+
};

0 commit comments

Comments
 (0)