utilitas 1999.1.31 → 1999.1.33
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/dist/utilitas.lite.mjs +1 -1
- package/dist/utilitas.lite.mjs.map +1 -1
- package/lib/alan.mjs +12 -4
- package/lib/manifest.mjs +1 -1
- package/lib/speech.mjs +10 -10
- package/lib/web.mjs +9 -3
- package/package.json +1 -1
package/lib/alan.mjs
CHANGED
|
@@ -747,12 +747,20 @@ const packResp = async (resp, options) => {
|
|
|
747
747
|
).join('\n');
|
|
748
748
|
}
|
|
749
749
|
txt = txt.split('\n');
|
|
750
|
-
const
|
|
750
|
+
const [reJinaStr, reJinaEnd]
|
|
751
|
+
= [`^\s*(${THINK_STR})`, `(${THINK_END})\s*$`].map(x => new RegExp(x));
|
|
751
752
|
const fixJina = [];
|
|
752
753
|
for (let l of txt) {
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
754
|
+
let catched = false;
|
|
755
|
+
if (reJinaStr.test(l)) {
|
|
756
|
+
fixJina.push(THINK_STR);
|
|
757
|
+
l = l.replace(reJinaStr, '');
|
|
758
|
+
}
|
|
759
|
+
if (reJinaEnd.test(l)) {
|
|
760
|
+
l = l.replace(reJinaEnd, '');
|
|
761
|
+
catched = true;
|
|
762
|
+
}
|
|
763
|
+
fixJina.push(l, ...catched ? [THINK_END, ''] : []);
|
|
756
764
|
}
|
|
757
765
|
txt = fixJina;
|
|
758
766
|
for (let i in txt) {
|
package/lib/manifest.mjs
CHANGED
package/lib/speech.mjs
CHANGED
|
@@ -26,11 +26,10 @@ const WHISPER_DEFAULT_MODEL = 'base';
|
|
|
26
26
|
const errorMessage = 'Invalid audio data.';
|
|
27
27
|
const [BUFFER, STREAM, BASE64, FILE, clients, languageCode, audioEncoding, suffix, SPEAKER, cleanup]
|
|
28
28
|
= ['BUFFER', 'STREAM', 'BASE64', 'FILE', {}, 'en-US', 'OGG_OPUS', 'ogg', 'SPEAKER', true];
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const [
|
|
32
|
-
|
|
33
|
-
const defaultOpenAITtsModel = TTS_1;
|
|
29
|
+
const [GPT_4O_MIMI_TTS, GPT_4O_TRANSCRIBE, OPENAI_TTS_MAX_LENGTH]
|
|
30
|
+
= ['gpt-4o-mini-tts', 'gpt-4o-transcribe', 4096];
|
|
31
|
+
const [defaultOpenAITtsModel, defaultOpenAISttModel]
|
|
32
|
+
= [GPT_4O_MIMI_TTS, GPT_4O_TRANSCRIBE];
|
|
34
33
|
|
|
35
34
|
const WHISPER_MODELS = [
|
|
36
35
|
// npx whisper-node download tiny.en
|
|
@@ -147,12 +146,13 @@ const checkWhisper = async (options) => {
|
|
|
147
146
|
};
|
|
148
147
|
|
|
149
148
|
const ttsOpenAI = async (input, options) => {
|
|
150
|
-
assert(clients.tts, '
|
|
149
|
+
assert(clients.tts, 'OpenAI TTS API has not been initialized.', 500);
|
|
151
150
|
assert(input, 'Text is required.', 400);
|
|
152
151
|
assert(input.length <= OPENAI_TTS_MAX_LENGTH, 'Text is too long.', 400);
|
|
153
152
|
// https://platform.openai.com/docs/api-reference/audio/createSpeech
|
|
154
153
|
const content = await clients.tts.create({
|
|
155
154
|
model: defaultOpenAITtsModel, voice: DEFAULT_MODELS[OPENAI_VOICE],
|
|
155
|
+
instructions: 'Speak in a friendly and sweet tone.',
|
|
156
156
|
response_format: 'opus', input, ...options?.params || {},
|
|
157
157
|
});
|
|
158
158
|
const buffer = Buffer.from(await content.arrayBuffer());
|
|
@@ -160,7 +160,7 @@ const ttsOpenAI = async (input, options) => {
|
|
|
160
160
|
};
|
|
161
161
|
|
|
162
162
|
const ttsGoogle = async (text, options) => {
|
|
163
|
-
assert(clients.tts, '
|
|
163
|
+
assert(clients.tts, 'Google TTS API has not been initialized.', 500);
|
|
164
164
|
assert(text, 'Text is required.', 400);
|
|
165
165
|
const [response] = await clients.tts.synthesizeSpeech({
|
|
166
166
|
input: { text, ...options?.input || {} },
|
|
@@ -197,7 +197,7 @@ const ttsBrowser = async (text) => {
|
|
|
197
197
|
};
|
|
198
198
|
|
|
199
199
|
const sttOpenAI = async (audio, options) => {
|
|
200
|
-
assert(clients.stt, '
|
|
200
|
+
assert(clients.stt, 'OpenAI STT API has not been initialized.', 500);
|
|
201
201
|
const input = ensureString(options?.input, { case: 'UP' });
|
|
202
202
|
const { content, cleanup } = await convert(audio, {
|
|
203
203
|
input: options?.input, ...options || {}, expected: STREAM, errorMessage,
|
|
@@ -205,7 +205,7 @@ const sttOpenAI = async (audio, options) => {
|
|
|
205
205
|
withCleanupFunc: true,
|
|
206
206
|
});
|
|
207
207
|
const result = await clients.stt.create({
|
|
208
|
-
file: await clients.toFile(content), model:
|
|
208
|
+
file: await clients.toFile(content), model: defaultOpenAISttModel,
|
|
209
209
|
response_format: 'text', ...options?.params || {},
|
|
210
210
|
});
|
|
211
211
|
await cleanup();
|
|
@@ -213,7 +213,7 @@ const sttOpenAI = async (audio, options) => {
|
|
|
213
213
|
};
|
|
214
214
|
|
|
215
215
|
const sttGoogle = async (audio, options) => {
|
|
216
|
-
assert(clients.stt, '
|
|
216
|
+
assert(clients.stt, 'Google STT API has not been initialized.', 500);
|
|
217
217
|
const content = await convert(audio, {
|
|
218
218
|
input: options?.input, expected: BASE64, errorMessage,
|
|
219
219
|
});
|
package/lib/web.mjs
CHANGED
|
@@ -222,7 +222,7 @@ const search = async (query, options = {}) => {
|
|
|
222
222
|
headers: {
|
|
223
223
|
'Authorization': `Bearer ${key}`,
|
|
224
224
|
'Accept': options?.aiFriendly ? MIME_TEXT : MIME_JSON,
|
|
225
|
-
'X-Respond-With': 'no-content',
|
|
225
|
+
...options?.fetch ? {} : { 'X-Respond-With': 'no-content' },
|
|
226
226
|
...options?.aiFriendly ? {} : { 'X-With-Favicons': true },
|
|
227
227
|
}
|
|
228
228
|
}, ...options || {},
|
|
@@ -329,8 +329,14 @@ const distill = async (url, options = {}) => {
|
|
|
329
329
|
const key = options.apiKey || jinaApiKey;
|
|
330
330
|
if (key) {
|
|
331
331
|
const resp = await get(`https://r.jina.ai/${encodeURIComponent(url)}`, {
|
|
332
|
-
fetch: {
|
|
333
|
-
|
|
332
|
+
fetch: {
|
|
333
|
+
headers: {
|
|
334
|
+
'Authorization': `Bearer ${key}`,
|
|
335
|
+
// 'X-Engine': 'cf-browser-rendering',
|
|
336
|
+
// 'X-Respond-With': 'readerlm-v2',
|
|
337
|
+
'X-Base': 'final',
|
|
338
|
+
}
|
|
339
|
+
}, ...options || {},
|
|
334
340
|
});
|
|
335
341
|
return { content: null, summary: resp?.content };
|
|
336
342
|
}
|