@saltcorn/large-language-model 0.9.10 → 0.9.12
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 +45 -2
- package/index.js +0 -2
- package/package.json +4 -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,10 @@ 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");
|
|
27
|
+
const { ElevenLabsClient } = require("@elevenlabs/elevenlabs-js");
|
|
28
|
+
|
|
25
29
|
let ollamaMod;
|
|
26
30
|
if (features.esm_plugins) ollamaMod = require("ollama");
|
|
27
31
|
|
|
@@ -119,7 +123,46 @@ const getAudioTranscription = async (
|
|
|
119
123
|
{ backend, apiKey, api_key, provider, ai_sdk_provider },
|
|
120
124
|
opts
|
|
121
125
|
) => {
|
|
122
|
-
switch (backend) {
|
|
126
|
+
switch (opts.backend || backend) {
|
|
127
|
+
case "ElevenLabs":
|
|
128
|
+
const transcription = await new ElevenLabsClient({
|
|
129
|
+
apiKey: opts?.api_key || api_key || apiKey,
|
|
130
|
+
}).speechToText.convert({
|
|
131
|
+
file: await (await File.findOne(opts.file)).get_contents(),
|
|
132
|
+
modelId: opts.model || "scribe_v2", // Model to use
|
|
133
|
+
tagAudioEvents: true, // Tag audio events like laughter, applause, etc.
|
|
134
|
+
languageCode: opts.languageCode || "eng", // Language of the audio file. If set to null, the model will detect the language automatically.
|
|
135
|
+
numSpeakers: opts.numSpeakers || null, // Language of the audio file. If set to null, the model will detect the language automatically.
|
|
136
|
+
diarize: !!opts.diarize, // Whether to annotate who is speaking
|
|
137
|
+
diarizationThreshold: opts.diarizationThreshold || null
|
|
138
|
+
});
|
|
139
|
+
return transcription;
|
|
140
|
+
case "OpenAI":
|
|
141
|
+
const client = new OpenAI({
|
|
142
|
+
apiKey: opts?.api_key || api_key || apiKey,
|
|
143
|
+
});
|
|
144
|
+
const fp = opts.file.location
|
|
145
|
+
? opts.file.location
|
|
146
|
+
: typeof opts.file === "string"
|
|
147
|
+
? await (
|
|
148
|
+
await File.findOne(opts.file)
|
|
149
|
+
).location
|
|
150
|
+
: null;
|
|
151
|
+
const model = opts?.model || "whisper-1";
|
|
152
|
+
const diarize = model === "gpt-4o-transcribe-diarize";
|
|
153
|
+
const transcript1 = await client.audio.transcriptions.create({
|
|
154
|
+
file: Buffer.isBuffer(opts.file) ? opts.file : fs.createReadStream(fp),
|
|
155
|
+
|
|
156
|
+
model,
|
|
157
|
+
...(diarize
|
|
158
|
+
? {
|
|
159
|
+
response_format: "diarized_json",
|
|
160
|
+
chunking_strategy: "auto",
|
|
161
|
+
}
|
|
162
|
+
: {}),
|
|
163
|
+
});
|
|
164
|
+
return transcript1;
|
|
165
|
+
|
|
123
166
|
case "AI SDK":
|
|
124
167
|
const api_Key = opts?.api_key || api_key || apiKey;
|
|
125
168
|
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.12",
|
|
4
4
|
"description": "Large language models and functionality for Saltcorn",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
|
@@ -12,7 +12,9 @@
|
|
|
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",
|
|
17
|
+
"@elevenlabs/elevenlabs-js": "2.31.0"
|
|
16
18
|
},
|
|
17
19
|
"author": "Tom Nielsen",
|
|
18
20
|
"license": "MIT",
|