@xuda.io/account_module 1.2.1528 → 1.2.1530
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 +57 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -509,7 +509,7 @@ export const get_account_data = async function (req) {
|
|
|
509
509
|
ai_workspace_plan: acc_obj.ai_workspace_plan,
|
|
510
510
|
storage_plan_changed: acc_obj.storage_plan_changed,
|
|
511
511
|
account_project_id: acc_obj.account_project_id,
|
|
512
|
-
is_boarded: acc_obj.isBoarded,
|
|
512
|
+
is_boarded: acc_obj.isBoarded,
|
|
513
513
|
|
|
514
514
|
prices_info: acc_obj.prices_info,
|
|
515
515
|
activity_usage: acc_obj.activity_usage,
|
|
@@ -3013,3 +3013,59 @@ export const save_cache_hit = async function (_id) {
|
|
|
3013
3013
|
await db_module.save_couch_doc('xuda_cache', doc_ret.data);
|
|
3014
3014
|
}
|
|
3015
3015
|
};
|
|
3016
|
+
|
|
3017
|
+
export const record_ai_usage = async function (uid, input_tokens, output_tokens, source, prompt, model, metadata = {}, account_profile_info) {
|
|
3018
|
+
try {
|
|
3019
|
+
if (!account_profile_info) throw new Error('missing account_profile_info');
|
|
3020
|
+
|
|
3021
|
+
const cost = _conf?.ai_models?.[model] || {
|
|
3022
|
+
input: 1.0,
|
|
3023
|
+
output: 1.0,
|
|
3024
|
+
};
|
|
3025
|
+
|
|
3026
|
+
const t = Date.now();
|
|
3027
|
+
let usage_doc = {
|
|
3028
|
+
_id: await _common.xuda_get_uuid('ai_usage'),
|
|
3029
|
+
docType: 'ai_usage',
|
|
3030
|
+
prompt: typeof prompt === 'string' ? prompt.substr(0, 40) : '',
|
|
3031
|
+
date_created_ts: t,
|
|
3032
|
+
uid,
|
|
3033
|
+
source,
|
|
3034
|
+
input_tokens,
|
|
3035
|
+
output_tokens,
|
|
3036
|
+
stat: 3,
|
|
3037
|
+
metadata,
|
|
3038
|
+
model,
|
|
3039
|
+
cost,
|
|
3040
|
+
account_profile_info,
|
|
3041
|
+
};
|
|
3042
|
+
const save_ret = await db_module.save_couch_doc('xuda_usage', usage_doc);
|
|
3043
|
+
// console.log(save_ret);
|
|
3044
|
+
} catch (err) {
|
|
3045
|
+
console.error(err);
|
|
3046
|
+
}
|
|
3047
|
+
};
|
|
3048
|
+
|
|
3049
|
+
export const record_ai_credit = async function (uid, credits, source, account_profile_info) {
|
|
3050
|
+
try {
|
|
3051
|
+
if (!account_profile_info) throw new Error('missing account_profile_info');
|
|
3052
|
+
|
|
3053
|
+
const t = Date.now();
|
|
3054
|
+
let usage_doc = {
|
|
3055
|
+
_id: await _common.xuda_get_uuid('ai_credit'),
|
|
3056
|
+
docType: 'ai_credit',
|
|
3057
|
+
credits,
|
|
3058
|
+
date_created_ts: t,
|
|
3059
|
+
uid,
|
|
3060
|
+
source,
|
|
3061
|
+
|
|
3062
|
+
stat: 3,
|
|
3063
|
+
|
|
3064
|
+
account_profile_info,
|
|
3065
|
+
};
|
|
3066
|
+
const save_ret = await db_module.save_couch_doc('xuda_usage', usage_doc);
|
|
3067
|
+
// console.log(save_ret);
|
|
3068
|
+
} catch (err) {
|
|
3069
|
+
console.error(err);
|
|
3070
|
+
}
|
|
3071
|
+
};
|