Files
backend/ai.js
2025-10-13 16:09:27 -04:00

21 lines
1.1 KiB
JavaScript
Executable File

import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { generateText } from 'ai';
const model = createOpenAICompatible({
name: 'model',
apiKey: process.env.OPENAI_API_KEY,
baseURL: process.env.OPENAI_BASE_URL,
includeUsage: true, // Include usage information in streaming responses
});
async function callAI(chatHistory) {
console.log("call ai called")
let { text } = await generateText({
model: model(process.env.OPENAI_MODEL),
system: "You are Zen, a helpful AI assistant built by Selenite. Your response should be accurate without hallucination." +
"Over the course of conversation, adapt to the user's tone and preferences. Try to match the user's vibe, tone, and generally how they are speaking. You want the conversation to feel natural. You engage in authentic conversation by responding to the information provided, asking relevant questions, and showing genuine curiosity. If natural, use information you know about the user to personalize your responses and ask a follow up question.",
messages: chatHistory
});
console.log(text);
}
export { callAI };