@xuda.io/ai_module 1.1.4334 → 1.1.4336
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 +7 -7
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -6775,33 +6775,33 @@ const get_profile_image = async function (uid, account_type = 'business', name,
|
|
|
6775
6775
|
} // throw new Error('not valid url');
|
|
6776
6776
|
let file;
|
|
6777
6777
|
try {
|
|
6778
|
-
file = await
|
|
6778
|
+
file = await get_image_blob_from_downloaded_image(url);
|
|
6779
6779
|
} catch (err) {
|
|
6780
6780
|
if (!err.message.includes('Failed to fetch image URL')) return console.error(err);
|
|
6781
6781
|
|
|
6782
6782
|
try {
|
|
6783
6783
|
url = await get_url();
|
|
6784
|
-
file = await
|
|
6784
|
+
file = await get_image_blob_from_downloaded_image(url);
|
|
6785
6785
|
} catch (err) {
|
|
6786
6786
|
// create factual image
|
|
6787
6787
|
|
|
6788
6788
|
return console.error(err);
|
|
6789
6789
|
}
|
|
6790
6790
|
}
|
|
6791
|
-
// const file = await
|
|
6791
|
+
// const file = await get_image_blob_from_downloaded_image(url);
|
|
6792
6792
|
// const imageBase64 = Buffer.from(await file.image_blob.arrayBuffer()).toString('base64');
|
|
6793
6793
|
const model = 'chatgpt-image-latest';
|
|
6794
6794
|
const prompt = `
|
|
6795
6795
|
extract the logo from the image
|
|
6796
6796
|
`;
|
|
6797
|
-
const
|
|
6797
|
+
const image_response = await client.images.edit({
|
|
6798
6798
|
model,
|
|
6799
6799
|
image: file.image_blob, //logo
|
|
6800
6800
|
prompt,
|
|
6801
6801
|
background: 'transparent',
|
|
6802
6802
|
});
|
|
6803
6803
|
|
|
6804
|
-
let imageBase64 = await normalizeBase64To1024(
|
|
6804
|
+
let imageBase64 = await normalizeBase64To1024(image_response.data[0].b64_json);
|
|
6805
6805
|
|
|
6806
6806
|
const outputBuffer = Buffer.from(imageBase64, 'base64');
|
|
6807
6807
|
const outputPath = file.tempOutputPath;
|
|
@@ -6819,7 +6819,7 @@ const get_profile_image = async function (uid, account_type = 'business', name,
|
|
|
6819
6819
|
|
|
6820
6820
|
const drive_ret = await drive_module.upload_drive_file_user({ uid, path: '/Profile Images' }, job_id, headers, file_obj);
|
|
6821
6821
|
|
|
6822
|
-
record_chat_usage(uid,
|
|
6822
|
+
record_chat_usage(uid, image_response.usage.input_tokens, image_response.usage.output_tokens, 'business logo', prompt, model, { url }, account_profile_info);
|
|
6823
6823
|
|
|
6824
6824
|
return drive_ret;
|
|
6825
6825
|
} catch (err) {
|
|
@@ -6846,7 +6846,7 @@ async function normalizeBase64To1024(base64Image) {
|
|
|
6846
6846
|
return normalizedBuffer.toString('base64'); // Return normalized base64 string
|
|
6847
6847
|
}
|
|
6848
6848
|
|
|
6849
|
-
const
|
|
6849
|
+
const get_image_blob_from_downloaded_image = async function (url) {
|
|
6850
6850
|
async function hasTransparentBackground(filePath) {
|
|
6851
6851
|
const image = sharp(filePath);
|
|
6852
6852
|
const metadata = await image.metadata();
|