@xuda.io/ai_module 1.1.4361 → 1.1.4363

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.
Files changed (2) hide show
  1. package/index.mjs +53 -33
  2. 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, business_name, country, mainCategory, subCategory, membership_plan } = metadata;
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
@@ -5908,14 +5908,30 @@ export const create_profile_avatar = async function (req, job_id, headers) {
5908
5908
  enterprise: `large modern hight rise multi-story office building located in ${country}`,
5909
5909
  };
5910
5910
  const model = 'chatgpt-image-latest';
5911
+ // const ai_avatar_response = await client.images.edit({
5912
+ // model,
5913
+ // image: image_blob_ret.image_blob, //logo
5914
+ // prompt: `
5915
+ // Create a transparent PNG profile image for a business account featuring building branded as ${business_name}.
5916
+ // Display the attached logo clearly as prominent exterior signage.
5917
+ // Show ${obj?.[membership_plan]?.employees || obj.free.employees} in front of the building/premises.
5918
+ // show ${obj?.[account_obj.membership_plan]?.building_size || obj.free.building_size}
5919
+ // The building’s architecture and overall atmosphere should reflect the nature of the business,
5920
+ // aligning with ${mainCategory} and ${subCategory}.
5921
+
5922
+ // Use the provided bio (${bio}) to understand the company’s focus and personality, and adapt the architectural style to match the ${country} country’s local design language. Select an appropriate building type for the specific business category, and present a contemporary, creative office environment with a strong, recognizable brand identity.
5923
+ // The background should be fully removed, remove trees,clouds,sky or any landscape objects`,
5924
+ // background: 'transparent',
5925
+ // });
5926
+
5911
5927
  const ai_avatar_response = await client.images.edit({
5912
5928
  model,
5913
5929
  image: image_blob_ret.image_blob, //logo
5914
5930
  prompt: `
5915
- Create a transparent PNG profile image for a business account featuring building branded as ${business_name}.
5931
+ Create a transparent PNG profile image for a business account featuring building branded as ${name}.
5916
5932
  Display the attached logo clearly as prominent exterior signage.
5917
- Show ${obj?.[membership_plan]?.employees || obj.free.employees} in front of the building/premises.
5918
- show ${obj?.[account_obj.membership_plan]?.building_size || obj.free.building_size}
5933
+
5934
+ show ${obj?.[business_size] || 'office building'}
5919
5935
  The building’s architecture and overall atmosphere should reflect the nature of the business,
5920
5936
  aligning with ${mainCategory} and ${subCategory}.
5921
5937
 
@@ -5929,7 +5945,7 @@ export const create_profile_avatar = async function (req, job_id, headers) {
5929
5945
  } else {
5930
5946
  /// PERSONAL
5931
5947
  const create_avatar_from_pic = async function () {
5932
- 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;
5933
5949
  const model = 'chatgpt-image-latest';
5934
5950
  const ai_avatar_response = await client.images.edit({
5935
5951
  model,
@@ -5937,7 +5953,7 @@ export const create_profile_avatar = async function (req, job_id, headers) {
5937
5953
 
5938
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.
5939
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.
5940
- Context: ${JSON.stringify({ first_name, last_name, bio, country, mainCategory, subCategory })}`,
5956
+ Context: ${JSON.stringify({ name, bio, country, mainCategory, subCategory })}`,
5941
5957
  background: 'transparent',
5942
5958
  });
5943
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);
@@ -5945,9 +5961,9 @@ export const create_profile_avatar = async function (req, job_id, headers) {
5945
5961
  avatar_source = 'ai profile';
5946
5962
  };
5947
5963
  const create_fictional_avatar = async function () {
5948
- const { first_name, last_name, bio, country, mainCategory, subCategory } = account_obj.account_info;
5964
+ // const { name, bio, country, mainCategory, subCategory } = account_obj.account_info;
5949
5965
 
5950
- const prompt = `analyze the the person info : ${JSON.stringify({ first_name, last_name, bio, country, mainCategory, subCategory })}
5966
+ const prompt = `analyze the the person info : ${JSON.stringify({ name, bio, country, mainCategory, subCategory })}
5951
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`;
5952
5968
 
5953
5969
  imageBase64 = await create_image(uid, prompt, undefined, undefined, 1, undefined, undefined, { url }, account_profile_info);
@@ -5988,35 +6004,39 @@ export const create_profile_avatar = async function (req, job_id, headers) {
5988
6004
  mimetype: `image/${ext}`,
5989
6005
  };
5990
6006
 
5991
- const drive_ret = await drive_module.upload_drive_file_user({ uid, path: '/Profile Images' }, job_id, headers, file_obj);
5992
-
5993
- if (drive_ret.code > 0) {
5994
- if (!is_profile_avatar) {
5995
- let db_doc = await db_module.get_couch_doc_native('xuda_accounts', account_obj._id);
5996
- db_doc.account_info.profile_avatar = drive_ret.data.file_url;
5997
- db_doc.account_info.profile_avatar_obj == drive_ret.data;
5998
- db_doc.account_info.avatar_source = avatar_source;
5999
- db_doc.image_request_ts = Date.now();
6000
- const save_ret = await db_module.save_couch_doc_native('xuda_accounts', db_doc);
6001
- console.log(save_ret);
6002
- await update_profile_avatar_status(uid, 3);
6003
- return save_ret;
6004
- } else {
6005
- return drive_ret;
6006
- }
6007
-
6008
- // account_module.update_contacts_with_account_changes(db_doc._id, ['profile_avatar']);
6009
- } else {
6010
- throw new Error(drive_ret.data);
6011
- }
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
6009
+
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
+ // }
6012
6031
  } catch (error) {
6013
- if (!is_profile_avatar) {
6014
- await update_profile_avatar_status(uid, 1);
6015
- }
6032
+ // if (!is_profile_avatar) {
6033
+ // await update_profile_avatar_status(uid, 1);
6034
+ // }
6016
6035
  console.error('Error:', error.message);
6017
6036
  if (error.response?.data) {
6018
6037
  console.error('OpenAI API response:', error.response.data);
6019
6038
  }
6039
+ return {code:-56:data:error.message}
6020
6040
  }
6021
6041
  };
6022
6042
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4361",
3
+ "version": "1.1.4363",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",