@xuda.io/ai_module 1.1.4775 → 1.1.4777
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 +50 -36
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -7036,54 +7036,68 @@ export const get_profile_picture = async function (uid, account_type = 'business
|
|
|
7036
7036
|
// debugger;
|
|
7037
7037
|
try {
|
|
7038
7038
|
url = await getUserPhotoByEmail(email);
|
|
7039
|
-
|
|
7040
|
-
|
|
7041
|
-
if (account_type === 'business') {
|
|
7042
|
-
url = await get_url();
|
|
7039
|
+
if (url) {
|
|
7040
|
+
profile_picture_source = 'google';
|
|
7043
7041
|
|
|
7044
|
-
|
|
7042
|
+
try {
|
|
7043
|
+
image_blob_ret = await get_image_blob_from_downloaded_image(url);
|
|
7044
|
+
} catch (err) {
|
|
7045
|
+
if (!err.message.includes('Failed to fetch image URL')) {
|
|
7046
|
+
console.error(err);
|
|
7047
|
+
return '';
|
|
7048
|
+
}
|
|
7045
7049
|
profile_picture_source = 'factual';
|
|
7046
|
-
|
|
7050
|
+
factual_image_mode = true;
|
|
7051
|
+
}
|
|
7052
|
+
} else {
|
|
7053
|
+
// first attempt
|
|
7054
|
+
if (account_type === 'business') {
|
|
7047
7055
|
url = await get_url();
|
|
7056
|
+
|
|
7048
7057
|
if (url.substr(0, 8) !== 'https://') {
|
|
7049
|
-
factual_image_mode = true;
|
|
7050
7058
|
profile_picture_source = 'factual';
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
7057
|
-
}
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
|
|
7059
|
+
// second attempt
|
|
7060
|
+
url = await get_url();
|
|
7061
|
+
if (url.substr(0, 8) !== 'https://') {
|
|
7062
|
+
factual_image_mode = true;
|
|
7063
|
+
profile_picture_source = 'factual';
|
|
7064
|
+
}
|
|
7065
|
+
} else {
|
|
7066
|
+
// success
|
|
7067
|
+
profile_picture_source = 'internet search';
|
|
7068
|
+
try {
|
|
7069
|
+
image_blob_ret = await get_image_blob_from_downloaded_image(url);
|
|
7070
|
+
} catch (err) {
|
|
7071
|
+
if (!err.message.includes('Failed to fetch image URL')) {
|
|
7072
|
+
console.error(err);
|
|
7073
|
+
return '';
|
|
7074
|
+
}
|
|
7075
|
+
profile_picture_source = 'factual';
|
|
7076
|
+
factual_image_mode = true;
|
|
7061
7077
|
}
|
|
7062
|
-
profile_picture_source = 'factual';
|
|
7063
|
-
factual_image_mode = true;
|
|
7064
7078
|
}
|
|
7079
|
+
} else {
|
|
7080
|
+
factual_image_mode = true;
|
|
7081
|
+
profile_picture_source = 'factual';
|
|
7065
7082
|
}
|
|
7066
|
-
} else {
|
|
7067
|
-
factual_image_mode = true;
|
|
7068
|
-
profile_picture_source = 'factual';
|
|
7069
|
-
}
|
|
7070
7083
|
|
|
7071
|
-
|
|
7072
|
-
|
|
7073
|
-
|
|
7074
|
-
|
|
7075
|
-
|
|
7084
|
+
if (factual_image_mode) {
|
|
7085
|
+
imageBase64 = await create_image(uid, factual_prompt, undefined, undefined, 1, undefined, undefined, {}, account_profile_info);
|
|
7086
|
+
} else {
|
|
7087
|
+
const model = 'gpt-image-1-mini'; // 'chatgpt-image-latest';
|
|
7088
|
+
const prompt = `
|
|
7076
7089
|
extract the logo from the image
|
|
7077
7090
|
`;
|
|
7078
|
-
|
|
7079
|
-
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
|
|
7091
|
+
const image_response = await client.images.edit({
|
|
7092
|
+
model,
|
|
7093
|
+
image: image_blob_ret.image_blob,
|
|
7094
|
+
prompt,
|
|
7095
|
+
background: 'transparent',
|
|
7096
|
+
});
|
|
7084
7097
|
|
|
7085
|
-
|
|
7086
|
-
|
|
7098
|
+
imageBase64 = await normalizeBase64To1024(image_response.data[0].b64_json, resize);
|
|
7099
|
+
account_module.record_ai_usage(uid, image_response.usage.input_tokens, image_response.usage.output_tokens, 'profile image', prompt, model, { url }, account_profile_info);
|
|
7100
|
+
}
|
|
7087
7101
|
}
|
|
7088
7102
|
const outputBuffer = Buffer.from(imageBase64, 'base64');
|
|
7089
7103
|
const outputPath = tempOutputPath;
|