@xuda.io/ai_module 1.1.4313 → 1.1.4315

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 +45 -37
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -6735,52 +6735,60 @@ const get_business_logo = async function (uid, name, account_profile_info) {
6735
6735
  tools: [{ type: 'web_search_preview' }],
6736
6736
  });
6737
6737
  console.log('=============', ret);
6738
+
6738
6739
  return ret.data;
6739
6740
  };
6740
-
6741
- let url = await get_url();
6742
- let file;
6743
6741
  try {
6744
- file = await return_image_blob_from_downloaded_image(url);
6745
- } catch (err) {
6746
- if (!err.message.includes('Failed to fetch image URL')) return console.error(err);
6747
-
6748
- try {
6742
+ let url = await get_url();
6743
+ if (!url.includes('https://')) {
6749
6744
  url = await get_url();
6745
+ } // throw new Error('not valid url');
6746
+ let file;
6747
+ try {
6750
6748
  file = await return_image_blob_from_downloaded_image(url);
6751
6749
  } catch (err) {
6752
- return console.error(err);
6750
+ if (!err.message.includes('Failed to fetch image URL')) return console.error(err);
6751
+
6752
+ try {
6753
+ url = await get_url();
6754
+ file = await return_image_blob_from_downloaded_image(url);
6755
+ } catch (err) {
6756
+ return console.error(err);
6757
+ }
6753
6758
  }
6754
- }
6755
- // const file = await return_image_blob_from_downloaded_image(url);
6756
- // const imageBase64 = Buffer.from(await file.image_blob.arrayBuffer()).toString('base64');
6757
- const model = 'chatgpt-image-latest';
6758
- const prompt = `
6759
+ // const file = await return_image_blob_from_downloaded_image(url);
6760
+ // const imageBase64 = Buffer.from(await file.image_blob.arrayBuffer()).toString('base64');
6761
+ const model = 'chatgpt-image-latest';
6762
+ const prompt = `
6759
6763
  extract the logo from the image
6760
6764
  `;
6761
- const logo_response = await client.images.edit({
6762
- model,
6763
- image: file.image_blob, //logo
6764
- prompt,
6765
- background: 'transparent',
6766
- });
6767
- record_chat_usage(uid, logo_response.usage.input_tokens, logo_response.usage.output_tokens, 'business logo', prompt, model, { url }, account_profile_info);
6768
- imageBase64 = await normalizeBase64To1024(logo_response.data[0].b64_json);
6769
-
6770
- const outputBuffer = Buffer.from(imageBase64, 'base64');
6771
- const outputPath = file.tempOutputPath;
6772
- await fs.promises.writeFile(outputPath, outputBuffer);
6773
-
6774
- console.log('Success! Saved →', outputPath);
6775
-
6776
- console.log(file);
6777
- // prompt: `find "${name}" logo base on the following facts "${facts}", Return only png,jpg img tag , nothing else`,
6778
- // try {
6779
- // if (ret.code > -1) {
6780
- // const data = JSON.parse(ret.data);
6781
- // return data.is_business;
6782
- // }
6783
- // } catch (error) {}
6765
+ const logo_response = await client.images.edit({
6766
+ model,
6767
+ image: file.image_blob, //logo
6768
+ prompt,
6769
+ background: 'transparent',
6770
+ });
6771
+ debugger;
6772
+ imageBase64 = await normalizeBase64To1024(logo_response.data[0].b64_json);
6773
+
6774
+ const outputBuffer = Buffer.from(imageBase64, 'base64');
6775
+ const outputPath = file.tempOutputPath;
6776
+ await fs.promises.writeFile(outputPath, outputBuffer);
6777
+
6778
+ console.log('Success! Saved →', outputPath);
6779
+
6780
+ console.log(file);
6781
+ record_chat_usage(uid, logo_response.usage.input_tokens, logo_response.usage.output_tokens, 'business logo', prompt, model, { url }, account_profile_info);
6782
+ // prompt: `find "${name}" logo base on the following facts "${facts}", Return only png,jpg img tag , nothing else`,
6783
+ // try {
6784
+ // if (ret.code > -1) {
6785
+ // const data = JSON.parse(ret.data);
6786
+ // return data.is_business;
6787
+ // }
6788
+ // } catch (error) {}
6789
+ } catch (err) {
6790
+ return console.error(err);
6791
+ }
6784
6792
  };
6785
6793
 
6786
6794
  async function normalizeBase64To1024(base64Image) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4313",
3
+ "version": "1.1.4315",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",