@xuda.io/ai_module 1.1.4313 → 1.1.4314

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