Create cloudflare-ai.js
Browse files
lib/@randydev/together/cloudflare-ai.js
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import got from 'got';
|
2 |
+
|
3 |
+
async function CloudFlareMistralTogether(message, { system_prompt = "" } = {}) {
|
4 |
+
const run = await got.post(`https://api.cloudflare.com/client/v4/accounts/${process.env['ACCOUNT_ID']}/ai/run/@cf/mistral/mistral-7b-instruct-v0.1`, {
|
5 |
+
headers: {
|
6 |
+
'Authorization': `Bearer ${process.env['CLOUDFLARE_API_KEY']}`,
|
7 |
+
'Content-Type': 'application/json'
|
8 |
+
},
|
9 |
+
json: {
|
10 |
+
'messages': [
|
11 |
+
{"role": "system", "content": system_prompt},
|
12 |
+
{"role": "user", "content": message}
|
13 |
+
],
|
14 |
+
'max_tokens': 200,
|
15 |
+
'stream': false
|
16 |
+
}
|
17 |
+
}).json();
|
18 |
+
return run.result.response;
|
19 |
+
}
|
20 |
+
export { CloudFlareMistralTogether };
|