@xuda.io/ai_module 1.1.4362 → 1.1.4364
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 +34 -30
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -5679,7 +5679,7 @@ export const create_profile_avatar = async function (req, job_id, headers) {
|
|
|
5679
5679
|
const uniqueId = Date.now() + '_' + Math.random().toString(36).substring(7);
|
|
5680
5680
|
const tempOutputPath = path.join(tempDir, `output_${uniqueId}.png`);
|
|
5681
5681
|
|
|
5682
|
-
const { url, uid, account_obj, prompt, is_profile_avatar, account_profile_info, docType = 'account', _id, metadata = {}, profile_picture, business_size = 'unknown' } = req;
|
|
5682
|
+
const { url, uid, account_obj, prompt, is_profile_avatar, account_profile_info, docType = 'account', _id, metadata = {}, profile_picture, business_size = 'unknown', name } = req;
|
|
5683
5683
|
|
|
5684
5684
|
// async function normalizeBase64To1024(base64Image) {
|
|
5685
5685
|
// const inputBuffer = Buffer.from(base64Image, 'base64');
|
|
@@ -5843,7 +5843,7 @@ export const create_profile_avatar = async function (req, job_id, headers) {
|
|
|
5843
5843
|
imageBase64 = Buffer.from(await image_blob_ret.image_blob.arrayBuffer()).toString('base64');
|
|
5844
5844
|
if (account_obj.account_info.account_type === 'business') {
|
|
5845
5845
|
// create avatar from logo - BUSINESS
|
|
5846
|
-
const { bio,
|
|
5846
|
+
const { bio, country, mainCategory, subCategory } = metadata;
|
|
5847
5847
|
// const ai_avatar_response = await client.images.edit({
|
|
5848
5848
|
// model: 'chatgpt-image-latest',
|
|
5849
5849
|
// image: image_blob_ret.image_blob, // only one image allowed
|
|
@@ -5928,7 +5928,7 @@ export const create_profile_avatar = async function (req, job_id, headers) {
|
|
|
5928
5928
|
model,
|
|
5929
5929
|
image: image_blob_ret.image_blob, //logo
|
|
5930
5930
|
prompt: `
|
|
5931
|
-
Create a transparent PNG profile image for a business account featuring building branded as ${
|
|
5931
|
+
Create a transparent PNG profile image for a business account featuring building branded as ${name}.
|
|
5932
5932
|
Display the attached logo clearly as prominent exterior signage.
|
|
5933
5933
|
|
|
5934
5934
|
show ${obj?.[business_size] || 'office building'}
|
|
@@ -5945,7 +5945,7 @@ export const create_profile_avatar = async function (req, job_id, headers) {
|
|
|
5945
5945
|
} else {
|
|
5946
5946
|
/// PERSONAL
|
|
5947
5947
|
const create_avatar_from_pic = async function () {
|
|
5948
|
-
const { first_name, last_name, bio, country, mainCategory, subCategory } = account_obj.account_info;
|
|
5948
|
+
// const { first_name, last_name, bio, country, mainCategory, subCategory } = account_obj.account_info;
|
|
5949
5949
|
const model = 'chatgpt-image-latest';
|
|
5950
5950
|
const ai_avatar_response = await client.images.edit({
|
|
5951
5951
|
model,
|
|
@@ -5953,7 +5953,7 @@ export const create_profile_avatar = async function (req, job_id, headers) {
|
|
|
5953
5953
|
|
|
5954
5954
|
prompt: `Completely remove the background, enhance and color-correct the subject, and return only a centered head-and-shoulders portrait facing the camera. Add extra top margin, include no labels or text, and export the result as a clean transparent PNG.
|
|
5955
5955
|
Ensure the subject is large enough to fill most of the frame. Use the supplied name, country, and context to guide the character’s appearance.
|
|
5956
|
-
Context: ${JSON.stringify({
|
|
5956
|
+
Context: ${JSON.stringify({ name, bio, country, mainCategory, subCategory })}`,
|
|
5957
5957
|
background: 'transparent',
|
|
5958
5958
|
});
|
|
5959
5959
|
record_chat_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { url }, account_profile_info);
|
|
@@ -5961,9 +5961,9 @@ export const create_profile_avatar = async function (req, job_id, headers) {
|
|
|
5961
5961
|
avatar_source = 'ai profile';
|
|
5962
5962
|
};
|
|
5963
5963
|
const create_fictional_avatar = async function () {
|
|
5964
|
-
const {
|
|
5964
|
+
// const { name, bio, country, mainCategory, subCategory } = account_obj.account_info;
|
|
5965
5965
|
|
|
5966
|
-
const prompt = `analyze the the person info : ${JSON.stringify({
|
|
5966
|
+
const prompt = `analyze the the person info : ${JSON.stringify({ name, bio, country, mainCategory, subCategory })}
|
|
5967
5967
|
and create realistic fictional profile picture transparent background ,person in the center of the picture return only a centered head-and-shoulders portrait facing the camera. include no labels or text add top margin the person should cover the whole picture`;
|
|
5968
5968
|
|
|
5969
5969
|
imageBase64 = await create_image(uid, prompt, undefined, undefined, 1, undefined, undefined, { url }, account_profile_info);
|
|
@@ -6004,35 +6004,39 @@ export const create_profile_avatar = async function (req, job_id, headers) {
|
|
|
6004
6004
|
mimetype: `image/${ext}`,
|
|
6005
6005
|
};
|
|
6006
6006
|
|
|
6007
|
-
|
|
6007
|
+
let drive_ret = await drive_module.upload_drive_file_user({ uid, path: '/Profile Images' }, job_id, headers, file_obj);
|
|
6008
|
+
drive_ret.avatar_source = avatar_source;
|
|
6008
6009
|
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
}
|
|
6010
|
+
return drive_ret;
|
|
6011
|
+
// if (drive_ret.code > 0) {
|
|
6012
|
+
// // if (!is_profile_avatar) {
|
|
6013
|
+
// // let db_doc = await db_module.get_couch_doc_native('xuda_accounts', account_obj._id);
|
|
6014
|
+
// // db_doc.account_info.profile_avatar = drive_ret.data.file_url;
|
|
6015
|
+
// // db_doc.account_info.profile_avatar_obj == drive_ret.data;
|
|
6016
|
+
// // db_doc.account_info.avatar_source = avatar_source;
|
|
6017
|
+
// // db_doc.image_request_ts = Date.now();
|
|
6018
|
+
// // const save_ret = await db_module.save_couch_doc_native('xuda_accounts', db_doc);
|
|
6019
|
+
// // console.log(save_ret);
|
|
6020
|
+
// // await update_profile_avatar_status(uid, 3);
|
|
6021
|
+
// // return save_ret;
|
|
6022
|
+
// // } else {
|
|
6023
|
+
// // return drive_ret;
|
|
6024
|
+
// // }
|
|
6025
|
+
|
|
6026
|
+
// // account_module.update_contacts_with_account_changes(db_doc._id, ['profile_avatar']);
|
|
6027
|
+
// return drive_ret;
|
|
6028
|
+
// } else {
|
|
6029
|
+
// throw new Error(drive_ret.data);
|
|
6030
|
+
// }
|
|
6028
6031
|
} catch (error) {
|
|
6029
|
-
if (!is_profile_avatar) {
|
|
6030
|
-
|
|
6031
|
-
}
|
|
6032
|
+
// if (!is_profile_avatar) {
|
|
6033
|
+
// await update_profile_avatar_status(uid, 1);
|
|
6034
|
+
// }
|
|
6032
6035
|
console.error('Error:', error.message);
|
|
6033
6036
|
if (error.response?.data) {
|
|
6034
6037
|
console.error('OpenAI API response:', error.response.data);
|
|
6035
6038
|
}
|
|
6039
|
+
return { code: -56, data: error.message };
|
|
6036
6040
|
}
|
|
6037
6041
|
};
|
|
6038
6042
|
|