save avant prochaine modif
This commit is contained in:
38
lib/geminiService.ts
Normal file
38
lib/geminiService.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
// Client-side wrapper that calls the server-side /api/gemini route
|
||||
|
||||
export const generateBusinessDescription = async (
|
||||
name: string,
|
||||
category: string,
|
||||
keywords: string
|
||||
): Promise<string> => {
|
||||
try {
|
||||
const res = await fetch('/api/gemini', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ action: 'description', name, category, keywords }),
|
||||
})
|
||||
if (!res.ok) throw new Error('API error')
|
||||
const data = await res.json()
|
||||
return data.text || 'Impossible de générer une description pour le moment.'
|
||||
} catch (error) {
|
||||
console.error('Gemini API Error:', error)
|
||||
return 'Erreur lors de la génération. Veuillez rédiger votre description manuellement.'
|
||||
}
|
||||
}
|
||||
|
||||
export const generateBusinessIdeas = async (
|
||||
category: string
|
||||
): Promise<string[]> => {
|
||||
try {
|
||||
const res = await fetch('/api/gemini', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ action: 'slogans', category }),
|
||||
})
|
||||
if (!res.ok) throw new Error('API error')
|
||||
const data = await res.json()
|
||||
return data.slogans || ["L'excellence au service de l'Afrique"]
|
||||
} catch {
|
||||
return ['Votre slogan ici']
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user