File size: 586 Bytes
be39d49 772a227 be39d49 9d6ddb4 be39d49 9d6ddb4 be39d49 772a227 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import { CohereClient } from "cohere-ai";
const cohere = new CohereClient({
token: process.env["COHERE_API_KEY"],
});
async function CohereAI(message, { system_prompt = ""} = {}) {
const stream = await cohere.chatStream({
model: "command-r-08-2024",
message: `${message}`,
temperature: 0.3,
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 }; |