@xuda.io/ai_module 1.1.3953 → 1.1.3956
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/index.mjs +8 -2
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -3450,7 +3450,7 @@ const get_drive_file_stream = async function (drive_type, app_id, uid, file_path
|
|
|
3450
3450
|
}
|
|
3451
3451
|
};
|
|
3452
3452
|
|
|
3453
|
-
const transcribe = async function (stream) {
|
|
3453
|
+
const transcribe = async function (uid, stream, metadata) {
|
|
3454
3454
|
try {
|
|
3455
3455
|
const resp = await client.audio.transcriptions.create({
|
|
3456
3456
|
model: 'whisper-1', // or "gpt-4o-transcribe", "whisper-1"
|
|
@@ -3460,7 +3460,7 @@ const transcribe = async function (stream) {
|
|
|
3460
3460
|
language: 'en', // hint language (ISO 639-1), e.g. "he" for Hebrew
|
|
3461
3461
|
// temperature: 0 // lower = more literal
|
|
3462
3462
|
});
|
|
3463
|
-
|
|
3463
|
+
record_chat_usage(uid, 0, resp.length || 0, 'transcribe', prompt, model, metadata);
|
|
3464
3464
|
console.log(resp); // or resp for JSON formats
|
|
3465
3465
|
return resp;
|
|
3466
3466
|
} catch (error) {
|
|
@@ -6370,6 +6370,11 @@ const record_chat_usage = async function (uid, input_tokens, output_tokens, sour
|
|
|
6370
6370
|
try {
|
|
6371
6371
|
const app_id = await account_module.get_account_default_project_id(uid);
|
|
6372
6372
|
|
|
6373
|
+
const cost = _conf?.ai_models?.[model] || {
|
|
6374
|
+
input: 1.0,
|
|
6375
|
+
output: 1.0,
|
|
6376
|
+
};
|
|
6377
|
+
|
|
6373
6378
|
const t = Date.now();
|
|
6374
6379
|
let usage_doc = {
|
|
6375
6380
|
_id: await _common.xuda_get_uuid('chat_usage'),
|
|
@@ -6383,6 +6388,7 @@ const record_chat_usage = async function (uid, input_tokens, output_tokens, sour
|
|
|
6383
6388
|
stat: 3,
|
|
6384
6389
|
metadata,
|
|
6385
6390
|
model,
|
|
6391
|
+
cost,
|
|
6386
6392
|
};
|
|
6387
6393
|
const save_ret = await db_module.save_app_couch_doc(app_id, usage_doc);
|
|
6388
6394
|
// console.log(save_ret);
|