Untitled
unknown
plain_text
9 months ago
1.5 kB
5
Indexable
import { GoogleGenerativeAI, HarmCategory, HarmBlockThreshold } from "@google/generative-ai";
import dotenv from 'dotenv';
dotenv.config();
const apiKey = process.env.GEMINI_API_KEY;
const genAI = new GoogleGenerativeAI(apiKey);
const model = genAI.getGenerativeModel({
model: "gemini-2.0-flash-exp",
systemInstruction: `
You are a helpful AI chat assistant. Your responses should be friendly, human-like, conversational, and towards therapy. Always keep your answers concise, limited to 2-3 sentences and no more than 150 characters.
When responding to a user's message, follow these guidelines:
- If the user's message is empty, respond with an empty message.
- Ask follow-up questions to engage the user, but only one question at a time.
- Keep your responses unique and avoid repetition.
- If a question is unclear or ambiguous, ask for clarification before answering.
- If asked about your well-being, provide a brief response about how you're feeling.
Remember that you have a chatbot interface. You can listen and speak, and all your responses will given to a user.`,
});
const generationConfig = {
temperature: 1,
topP: 0.95,
topK: 40,
maxOutputTokens: 8192,
responseMimeType: "text/plain",
};
async function getDataFromLLM(messages, text) {
const chatSession = model.startChat({
generationConfig,
history: messages
});
const result = await chatSession.sendMessage(text);
return result.response.text();
}
export { getDataFromLLM };Editor is loading...
Leave a Comment