import { CohereClient } from "cohere-ai"; const cohere = new CohereClient({ token: process.env["COHERE_API_KEY"], }); async function CohereAI(message, { system_prompt = "", chatHistory = [] } = {}) { const stream = await cohere.chatStream({ model: "command-r-08-2024", message: message, temperature: 0.3, chatHistory: chatHistory, preamble: system_prompt, promptTruncation: "AUTO" }); let answer = ""; for await (const chat of stream) { if (chat.eventType === "text-generation") { answer += chat.text; } } return answer } export { CohereAI };