randydev commited on
Commit
8e6f2c8
·
verified ·
1 Parent(s): ba0cefc

Create openai.js

Browse files
Files changed (1) hide show
  1. lib/@randydev/openai.js +27 -0
lib/@randydev/openai.js ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ app.post("/run/:model", async (req, res) => {
3
+ const { model } = req.params;
4
+ const url = req.query.url;
5
+
6
+ const path = await audioContent(
7
+ "https://pub-dbcf9f0bd3af47ca9d40971179ee62de.r2.dev/02f6edc0-1f7b-4272-bd17-f05335104725/audio.mp3"
8
+ );
9
+ if (!path) {
10
+ return res.status(500).json({ error: "Failed to download audio file" });
11
+ }
12
+ try {
13
+ const audioBytes = fs.readFileSync(path);
14
+ const audioBase64 = Buffer.from(audioBytes).toString("base64");
15
+ const inputData = { audio: audioBase64 };
16
+ const response = await axios.post(`${API_BASE_URL}${model}`, inputData, { headers });
17
+ return res.json(response.data);
18
+ } catch (error) {
19
+ console.error("Error making API request:", error.message);
20
+ return res.status(500).json({ error: error.message });
21
+ } finally {
22
+ if (fs.existsSync(path)) {
23
+ fs.unlinkSync(path);
24
+ }
25
+ }
26
+ });
27
+ */