Skip to content

Commit ce68943

Browse files
authored
Refactor sendMessageToGemini function
Updated sendMessageToGemini to accept an optional useSearch parameter and modified return structure for better integration with Chatbot.tsx.
1 parent f06c674 commit ce68943

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

services/geminiService.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,46 @@
11
// services/geminiService.ts
22

3-
// VŽDY ZKONTROLUJ, ZDA TATO URL ODPOVÍDÁ TVÉMU TUNELU V TERMINÁLU!
3+
// VŽDY ZKONTROLUJ TU URL PODLE TERMINÁLU!
44
const TUNNEL_URL = "https://clients-update-scientists-mouth.trycloudflare.com";
55

6-
export const sendMessageToGemini = async (prompt: string) => {
6+
export const sendMessageToGemini = async (prompt: string, useSearch: boolean = false) => {
77
try {
88
const response = await fetch(`${TUNNEL_URL}/api/generate`, {
99
method: 'POST',
10-
headers: {
11-
'Content-Type': 'application/json',
12-
},
10+
headers: { 'Content-Type': 'application/json' },
1311
body: JSON.stringify({
1412
model: 'gemma3:4b',
1513
prompt: prompt,
1614
stream: false
1715
})
1816
});
1917

20-
if (!response.ok) {
21-
throw new Error(`Raspberry Pi vrátilo chybu: ${response.status}`);
22-
}
18+
if (!response.ok) throw new Error(`Chyba: ${response.status}`);
2319

2420
const data = await response.json();
25-
26-
// Logování pro tvou kontrolu v konzoli (F12)
2721
console.log('Data z Ollamy:', data);
28-
29-
// Klíčové pro zobrazení v chatu: vracíme přímo textový řetězec
30-
return data.response;
22+
23+
// Úprava pro tvůj Chatbot.tsx: vracíme objekt s klíčem "text"
24+
return {
25+
text: data.response || "AI vrátila prázdnou odpověď.",
26+
sources: [] // Ollama zatím zdroje nepodporuje, tak vracíme prázdné pole
27+
};
3128

3229
} catch (error) {
3330
console.error('Chyba při volání AI:', error);
34-
return "Omlouvám se, spojení s Raspberry Pi selhalo. Zkontroluj, zda běží tunel a Ollama.";
31+
return {
32+
text: "Omlouvám se, spojení s Raspberry Pi selhalo. Zkontroluj tunel a Ollamu.",
33+
sources: []
34+
};
3535
}
3636
};
3737

38-
/**
39-
* Funkce pro generování scénáře z materiálů
40-
* Nutné pro úspěšný build na GitHubu
41-
*/
38+
// Funkce pro build na GitHubu
4239
export const generateScriptFromMaterial = async (material: any) => {
43-
const prompt = `Jsi studijní asistent. Vytvoř strukturovaný studijní scénář z tohoto materiálu: ${JSON.stringify(material)}`;
40+
const prompt = `Vytvoř studijní scénář: ${JSON.stringify(material)}`;
4441
return await sendMessageToGemini(prompt);
4542
};
4643

47-
/**
48-
* Funkce pro simulaci generování audia
49-
* Nutné pro úspěšný build na GitHubu
50-
*/
5144
export const generatePodcastAudio = async (text: string) => {
52-
console.log("Generování audia pro:", text);
5345
return "";
5446
};

0 commit comments

Comments
 (0)