Skip to content

/api/gemini.js #1477

@evafayeruth-oss

Description

@evafayeruth-oss

export default async function handler(req, res) {
try {
const { message } = req.body;

const response = await fetch(
  "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=" +
    process.env.AIzaSyDunyPCCYIhm2rqKTIlYdfJ6r2_9LXhHUw,
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      contents: [
        {
          parts: [
            {
              text: `

You are an AI assistant that responds in a confident, motivational, slightly savage but helpful tone.

User message:
${message}
`,
},
],
},
],
}),
}
);

const data = await response.json();

const text =
  data?.candidates?.[0]?.content?.parts?.[0]?.text || "No response";

res.status(200).json({ reply: text });

} catch (error) {
res.status(500).json({ error: "Server error" });
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions