3d / server /src /services /gemini.ts
hologramicon's picture
Update server/src/services/gemini.ts
6a45e69 verified
raw
history blame contribute delete
527 Bytes
import fetch from 'node-fetch'
export async function proxyGemini(prompt: string) {
const url =
'https://generativelanguage.googleapis.com/v1/models/gemini-pro:generateContent?key=' +
process.env.GEMINI_API_KEY
const r = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
contents: [{ parts: [{ text: prompt }] }]
})
})
const j: any = await r.json()
const text = j.candidates?.[0]?.content?.parts?.[0]?.text || ''
return text
}