|
|
@@ -1,30 +1,6 @@
|
|
|
const models = require('../../models');
|
|
|
const fetch = require('node-fetch');
|
|
|
|
|
|
-/**
|
|
|
- *
|
|
|
-curl --location 'https://ark.cn-beijing.volces.com/api/v3/chat/completions' \
|
|
|
---header 'Authorization: Bearer fb8942c2-fe94-4092-80fc-233e252f7090' \
|
|
|
---header 'Content-Type: application/json' \
|
|
|
---data '{
|
|
|
- "model": "ep-20250206115552-7qg5c",
|
|
|
- "messages": [
|
|
|
- {"role": "user", "content": [
|
|
|
- {
|
|
|
- "type":"text",
|
|
|
- "text": "根据图片生成标题(title, 60个字符以内)、简要描述(description, 用于网站SEO的meta description,160个字符以内,尽量包含Coloring Page关键字)、文案描述(copy, 200字左右,尽量包含Coloring Page 关键字)。 以json格式输出,支持语言中文(zh)、英语(en)、西班牙语(es)、葡萄牙语(pt)、日语(ja),形如: { title: {zh:'', en:'', es: '', pt: '', ja: ''}, description: {zh:'', en:'', es: '', pt: '', ja: ''}, copy:{zh:'', en:'', es: '', pt: '', ja: ''} }"
|
|
|
- },
|
|
|
- {
|
|
|
- "type": "image_url",
|
|
|
- "image_url": {
|
|
|
- "url": "https://color.jccytech.cn/thumbs/v2/work/320/67a241674f9d65537938e36d.png"
|
|
|
- }
|
|
|
- }
|
|
|
- ]}
|
|
|
- ]
|
|
|
-}'
|
|
|
-*/
|
|
|
-
|
|
|
let apiKey = require('process').env.ARK_API_KEY;
|
|
|
const url = "https://ark.cn-beijing.volces.com/api/v3/chat/completions";
|
|
|
let headers = {
|
|
|
@@ -33,10 +9,11 @@ let headers = {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 豆包视觉API
|
|
|
* 从豆包获取图片的标题和文案描述
|
|
|
* @param {*} imageUrl
|
|
|
*/
|
|
|
-async function fetchMetaFromDoubao(imageUrl) {
|
|
|
+async function fetchMetaByImageFromDoubao(imageUrl) {
|
|
|
let data = {
|
|
|
"model": "ep-20250206115552-7qg5c", // Doubao-1.5...ion-pro-32k 当前最新,贵,响应慢,效果好
|
|
|
// "model": "ep-20250204231910-4phb8", // Doubao-vision-lite-32k 便宜点,相应速度快
|
|
|
@@ -58,6 +35,8 @@ async function fetchMetaFromDoubao(imageUrl) {
|
|
|
]
|
|
|
}
|
|
|
|
|
|
+ console.log(data);
|
|
|
+
|
|
|
const jsonData = JSON.stringify(data);
|
|
|
|
|
|
const response = await fetch(url, { method: 'POST', headers, body: jsonData });
|
|
|
@@ -69,9 +48,89 @@ async function fetchMetaFromDoubao(imageUrl) {
|
|
|
return responseJson.choices[0].message.content;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 豆包对话API
|
|
|
+ * @param {*} text
|
|
|
+ */
|
|
|
+async function fetchMetaByTxtFromDoubao(text) {
|
|
|
+ let data = {
|
|
|
+ "model": "ep-20250206115552-7qg5c", // Doubao-1.5...ion-pro-32k 当前最新,贵,响应慢,效果好
|
|
|
+ // "model": "ep-20250204231910-4phb8", // Doubao-vision-lite-32k 便宜点,相应速度快
|
|
|
+ "messages": [
|
|
|
+ { "role": "user", "content": text }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(data);
|
|
|
|
|
|
-async function run() {
|
|
|
+ const jsonData = JSON.stringify(data);
|
|
|
+
|
|
|
+ const response = await fetch(url, { method: 'POST', headers, body: jsonData });
|
|
|
|
|
|
+ let responseJson = await response.json();
|
|
|
+
|
|
|
+ console.log(responseJson);
|
|
|
+
|
|
|
+ return responseJson.choices[0].message.content;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+async function runAlbumMeta() {
|
|
|
+ let done = 0;
|
|
|
+ let duration = 0;
|
|
|
+ let hour, minute, second;
|
|
|
+ let start = Date.now();
|
|
|
+
|
|
|
+ // 筛选出所有album
|
|
|
+ let query = { pid: 'art', enabled: true, $or: [{ seoTitle: { $exists: false } }, { seoTitle: null }] }
|
|
|
+ let docs = await models.ArtAlbum
|
|
|
+ .find(query)
|
|
|
+ .sort({ order: 'asc' })
|
|
|
+ .populate('title')
|
|
|
+ .select('tag title slogon');
|
|
|
+
|
|
|
+
|
|
|
+ let total = docs.length;
|
|
|
+ console.log('total:', total);
|
|
|
+ if (total <= 0) return;
|
|
|
+
|
|
|
+ for (let doc of docs) {
|
|
|
+ console.log(`process album ${doc._id}`);
|
|
|
+
|
|
|
+ console.time(doc._id);
|
|
|
+
|
|
|
+ try {
|
|
|
+ let text = `帮我生成填色页专辑《${doc.title.zh}》的SEO title(60个字符以内) 和 description(160个字符以内), 以json格式输出,支持语言中文(zh)、英语(en)、西班牙语(es)、葡萄牙语(pt)、日语(ja),形如: { title: {zh:'', en:'', es: '', pt: '', ja: ''}, description: {zh:'', en:'', es: '', pt: '', ja: ''}`;
|
|
|
+ let metaInfo = await fetchMetaByTxtFromDoubao(text);
|
|
|
+ console.log(metaInfo);
|
|
|
+ let metaInfoJson = JSON.parse(metaInfo);
|
|
|
+ let titleJson = metaInfoJson.title;
|
|
|
+ let descJson = metaInfoJson.description;
|
|
|
+ let title = JSON.stringify(titleJson);
|
|
|
+ let desc = JSON.stringify(descJson);
|
|
|
+
|
|
|
+ doc.seoTitle = title;
|
|
|
+ doc.seoDescription = desc;
|
|
|
+ await doc.save();
|
|
|
+
|
|
|
+ } catch (e) {
|
|
|
+ console.error(e.message);
|
|
|
+ }
|
|
|
+
|
|
|
+ console.timeEnd(doc._id);
|
|
|
+
|
|
|
+ done++;
|
|
|
+ duration = (Date.now() - start) / 1000;
|
|
|
+ hour = (Math.floor(duration / 60 / 60)).toString().padStart(2, '0');
|
|
|
+ minute = (Math.floor(duration / 60) % 60).toString().padStart(2, '0');
|
|
|
+ second = (Math.floor(duration) % 60).toString().padStart(2, '0');
|
|
|
+
|
|
|
+ console.log('progress: ' + Math.floor((100 * done / total)) + '% used time: ' + hour + ':' + minute + ':' + second);
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+async function runArtMeta() {
|
|
|
let done = 0;
|
|
|
let duration = 0;
|
|
|
let hour, minute, second;
|
|
|
@@ -98,7 +157,7 @@ async function run() {
|
|
|
console.time(doc._id);
|
|
|
|
|
|
try {
|
|
|
- let metaInfo = await fetchMetaFromDoubao(thumbUrl);
|
|
|
+ let metaInfo = await fetchMetaByImageFromDoubao(thumbUrl);
|
|
|
console.log(metaInfo);
|
|
|
let metaInfoJson = JSON.parse(metaInfo);
|
|
|
let titleJson = metaInfoJson.title;
|
|
|
@@ -129,14 +188,18 @@ async function run() {
|
|
|
|
|
|
}
|
|
|
|
|
|
- run();
|
|
|
+ runArtMeta();
|
|
|
|
|
|
}
|
|
|
|
|
|
+async function run() {
|
|
|
+ await runAlbumMeta();
|
|
|
+ await runArtMeta();
|
|
|
+}
|
|
|
|
|
|
|
|
|
async function test() {
|
|
|
- let metaInfo = await fetchMetaFromDoubao("https://color.jccytech.cn/thumbs/v2/work/640/67a254ec4f9d65537938e5c5.png");
|
|
|
+ let metaInfo = await fetchMetaByImageFromDoubao("https://color.jccytech.cn/thumbs/v2/work/640/67a254ec4f9d65537938e5c5.png");
|
|
|
console.log(metaInfo);
|
|
|
let metaInfoJson = JSON.parse(metaInfo);
|
|
|
let titleJson = metaInfoJson.title;
|