Update lib/@randydev/together/cohere.js
Browse files- lib/@randydev/together/cohere.js +20 -17
lib/@randydev/together/cohere.js
CHANGED
@@ -1,20 +1,23 @@
|
|
1 |
-
import
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
19 |
}
|
20 |
export { CohereAI };
|
|
|
1 |
+
import { CohereClient } from "cohere-ai";
|
2 |
|
3 |
+
const cohere = new CohereClient({
|
4 |
+
token: process.env["COHERE_API_KEY"],
|
5 |
+
});
|
6 |
+
|
7 |
+
function CohereAI(message) {
|
8 |
+
const stream = await cohere.chatStream({
|
9 |
+
model: "command-r-08-2024",
|
10 |
+
message: `${message}`,
|
11 |
+
temperature: 0.3,
|
12 |
+
chatHistory: [],
|
13 |
+
promptTruncation: "AUTO"
|
14 |
+
});
|
15 |
+
let answer = "";
|
16 |
+
for await (const chat of stream) {
|
17 |
+
if (chat.eventType === "text-generation") {
|
18 |
+
answer += chat.text;
|
19 |
+
}
|
20 |
+
}
|
21 |
+
return answer
|
22 |
}
|
23 |
export { CohereAI };
|