Update plugins/gptold.js
Browse files- plugins/gptold.js +53 -0
plugins/gptold.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import express from 'express';
|
2 |
import { OpenaiRes } from '../lib/scrapper.js';
|
|
|
3 |
import { NvidiaTogether } from '../lib/@randydev/together/llama.js';
|
4 |
import { CohereAI } from '../lib/@randydev/together/cohere.js';
|
5 |
import {
|
@@ -10,6 +11,58 @@ import { DeepSeekR1 } from '../lib/@randydev/together/blackbox.js';
|
|
10 |
import { authenticateApiKey, authenticateApiKeyPremium, apiLimiter } from '../middleware/midware.js';
|
11 |
const GptRoutes = express.Router();
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
/**
|
15 |
* @swagger
|
|
|
1 |
import express from 'express';
|
2 |
import { OpenaiRes } from '../lib/scrapper.js';
|
3 |
+
import { audioContent } from '../lib/all.js';
|
4 |
import { NvidiaTogether } from '../lib/@randydev/together/llama.js';
|
5 |
import { CohereAI } from '../lib/@randydev/together/cohere.js';
|
6 |
import {
|
|
|
11 |
import { authenticateApiKey, authenticateApiKeyPremium, apiLimiter } from '../middleware/midware.js';
|
12 |
const GptRoutes = express.Router();
|
13 |
|
14 |
+
import fs from "fs";
|
15 |
+
import { Buffer } from "Buffer";
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @swagger
|
19 |
+
* /api/v1/ai/openai/whisper-large-v3-turbo:
|
20 |
+
* get:
|
21 |
+
* summary: Openai Whisper large turbo
|
22 |
+
* tags: [AI]
|
23 |
+
* parameters:
|
24 |
+
* - in: query
|
25 |
+
* name: url
|
26 |
+
* required: true
|
27 |
+
* description: url mp3
|
28 |
+
* schema:
|
29 |
+
* type: string
|
30 |
+
* - in: header
|
31 |
+
* name: x-api-key
|
32 |
+
* required: true
|
33 |
+
* description: API key for authentication
|
34 |
+
* schema:
|
35 |
+
* type: string
|
36 |
+
* responses:
|
37 |
+
* 200:
|
38 |
+
* description: Success
|
39 |
+
*/
|
40 |
+
GptRoutes.get("/api/v1/ai/openai/whisper-large-v3-turbo", authenticateApiKey, apiLimiter, async (req, res) => {
|
41 |
+
API_BASE_URL = `https://api.cloudflare.com/client/v4/accounts/${process.env['ACCOUNT_ID']}/ai/run/@cf/openai/whisper-large-v3-turbo`
|
42 |
+
headers = {'Authorization': `Bearer ${process.env['CLOUDFLARE_API_KEY']}`}
|
43 |
+
const url = req.query.url;
|
44 |
+
|
45 |
+
const path = await audioContent(url);
|
46 |
+
);
|
47 |
+
if (!path) {
|
48 |
+
return res.status(500).json({ error: "Failed to download audio file" });
|
49 |
+
}
|
50 |
+
try {
|
51 |
+
const audioBytes = fs.readFileSync(path);
|
52 |
+
const audioBase64 = Buffer.from(audioBytes).toString("base64");
|
53 |
+
const inputData = { audio: audioBase64 };
|
54 |
+
const response = await axios.post(`${API_BASE_URL}`, inputData, { headers });
|
55 |
+
return res.json(response.data);
|
56 |
+
} catch (error) {
|
57 |
+
console.error("Error making API request:", error.message);
|
58 |
+
return res.status(500).json({ error: null });
|
59 |
+
} finally {
|
60 |
+
if (fs.existsSync(path)) {
|
61 |
+
fs.unlinkSync(path);
|
62 |
+
}
|
63 |
+
}
|
64 |
+
});
|
65 |
+
|
66 |
|
67 |
/**
|
68 |
* @swagger
|