randydev's picture
Update lib/@randydev/together/cohere.js
be39d49 verified
raw
history blame
518 Bytes
import { CohereClient } from "cohere-ai";
const cohere = new CohereClient({
token: process.env["COHERE_API_KEY"],
});
function CohereAI(message) {
const stream = await cohere.chatStream({
model: "command-r-08-2024",
message: `${message}`,
temperature: 0.3,
chatHistory: [],
promptTruncation: "AUTO"
});
let answer = "";
for await (const chat of stream) {
if (chat.eventType === "text-generation") {
answer += chat.text;
}
}
return answer
}
export { CohereAI };