@saltcorn/large-language-model 0.9.10 → 0.9.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/generate.js +29 -1
- package/index.js +0 -2
- package/package.json +3 -2
package/generate.js
CHANGED
|
@@ -11,6 +11,7 @@ const { google } = require("googleapis");
|
|
|
11
11
|
const Plugin = require("@saltcorn/data/models/plugin");
|
|
12
12
|
const File = require("@saltcorn/data/models/file");
|
|
13
13
|
const path = require("path");
|
|
14
|
+
const fs = require("fs");
|
|
14
15
|
const { features, getState } = require("@saltcorn/data/db/state");
|
|
15
16
|
const {
|
|
16
17
|
generateText,
|
|
@@ -21,7 +22,8 @@ const {
|
|
|
21
22
|
embedMany,
|
|
22
23
|
experimental_transcribe,
|
|
23
24
|
} = require("ai");
|
|
24
|
-
const {
|
|
25
|
+
const { createOpenAI } = require("@ai-sdk/openai");
|
|
26
|
+
const OpenAI = require("openai");
|
|
25
27
|
let ollamaMod;
|
|
26
28
|
if (features.esm_plugins) ollamaMod = require("ollama");
|
|
27
29
|
|
|
@@ -120,6 +122,32 @@ const getAudioTranscription = async (
|
|
|
120
122
|
opts
|
|
121
123
|
) => {
|
|
122
124
|
switch (backend) {
|
|
125
|
+
case "OpenAI":
|
|
126
|
+
const client = new OpenAI({
|
|
127
|
+
apiKey: opts?.api_key || api_key || apiKey,
|
|
128
|
+
});
|
|
129
|
+
const fp = opts.file.location
|
|
130
|
+
? opts.file.location
|
|
131
|
+
: typeof opts.file === "string"
|
|
132
|
+
? await (
|
|
133
|
+
await File.findOne(opts.file)
|
|
134
|
+
).location
|
|
135
|
+
: null;
|
|
136
|
+
const model = opts?.model || "whisper-1";
|
|
137
|
+
const diarize = model === "gpt-4o-transcribe-diarize";
|
|
138
|
+
const transcript1 = await client.audio.transcriptions.create({
|
|
139
|
+
file: Buffer.isBuffer(opts.file) ? opts.file : fs.createReadStream(fp),
|
|
140
|
+
|
|
141
|
+
model,
|
|
142
|
+
...(diarize
|
|
143
|
+
? {
|
|
144
|
+
response_format: "diarized_json",
|
|
145
|
+
chunking_strategy: "auto",
|
|
146
|
+
}
|
|
147
|
+
: {}),
|
|
148
|
+
});
|
|
149
|
+
return transcript1;
|
|
150
|
+
|
|
123
151
|
case "AI SDK":
|
|
124
152
|
const api_Key = opts?.api_key || api_key || apiKey;
|
|
125
153
|
const prov_obj = createOpenAI({ apiKey: api_Key });
|
package/index.js
CHANGED
|
@@ -687,7 +687,6 @@ module.exports = {
|
|
|
687
687
|
name: "model",
|
|
688
688
|
label: "The model name, for example <code>whisper-1</code>",
|
|
689
689
|
type: "String",
|
|
690
|
-
required: true,
|
|
691
690
|
},
|
|
692
691
|
{
|
|
693
692
|
name: "prompt_template",
|
|
@@ -729,7 +728,6 @@ module.exports = {
|
|
|
729
728
|
name: "model",
|
|
730
729
|
label: "The model name, for example <code>whisper-1</code>",
|
|
731
730
|
type: "String",
|
|
732
|
-
required: true,
|
|
733
731
|
},
|
|
734
732
|
{
|
|
735
733
|
name: "prompt_template",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saltcorn/large-language-model",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.11",
|
|
4
4
|
"description": "Large language models and functionality for Saltcorn",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"@google-cloud/aiplatform": "^3.34.0",
|
|
13
13
|
"googleapis": "^144.0.0",
|
|
14
14
|
"ai": "5.0.44",
|
|
15
|
-
"@ai-sdk/openai": "2.0.30"
|
|
15
|
+
"@ai-sdk/openai": "2.0.30",
|
|
16
|
+
"openai": "6.16.0"
|
|
16
17
|
},
|
|
17
18
|
"author": "Tom Nielsen",
|
|
18
19
|
"license": "MIT",
|