mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
Update language and demo links in plugin
documentation
This commit is contained in:
1 parent
69197312cc
commit
b6a62f8dc5
9 files changed
+15
-2526
No files matched your search
+7
-17
@@ -3,11 +3,8 @@ import cpy from 'cpy';
|
||||
import path from 'path';
|
||||
import axios from 'axios';
|
||||
import { glob } from 'glob';
|
||||
import dotenv from 'dotenv';
|
||||
import { removeDir } from './utils.js';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
function splitMarkdown(text, maxChars) {
|
||||
const parts = [];
|
||||
let currentPart = '';
|
||||
@@ -44,23 +41,21 @@ function splitMarkdown(text, maxChars) {
|
||||
return parts;
|
||||
}
|
||||
|
||||
const translateContent = async (content, targetLanguage, openAIKey) => {
|
||||
const translateContent = async (content, targetLanguage) => {
|
||||
try {
|
||||
const response = await axios.post(
|
||||
'https://api.openai.com/v1/engines/gpt-4-1106-preview/completions',
|
||||
'https://api.aimu.app/openai/chat',
|
||||
{
|
||||
prompt: `Translate the following text to ${targetLanguage}:\n\n${content}`,
|
||||
max_tokens: 2048,
|
||||
content: `Translate the following text to ${targetLanguage}:\n\n${content}`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${openAIKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
timeout: 60000,
|
||||
},
|
||||
);
|
||||
|
||||
return response.data.choices[0].text;
|
||||
return response.data.data;
|
||||
} catch (error) {
|
||||
console.error('Error during translation:', error);
|
||||
return '';
|
||||
@@ -94,11 +89,6 @@ const translateMarkdownFiles = async (filePaths, targetLanguage, openAIKey, maxC
|
||||
await cpy(path.resolve(basePath, dir), path.resolve(enPath, dir), { flat: true });
|
||||
}
|
||||
const mdsPaths = glob.sync(path.resolve(enPath, '**/*.md'));
|
||||
const openAIKey = process.env.OPENAI_KEY;
|
||||
const maxCharsPerRequest = 2000;
|
||||
if (openAIKey) {
|
||||
await translateMarkdownFiles(mdsPaths, 'English', openAIKey, maxCharsPerRequest);
|
||||
} else {
|
||||
console.log('OPENAI_KEY is not set');
|
||||
}
|
||||
const maxCharsPerRequest = 1024;
|
||||
await translateMarkdownFiles(mdsPaths, 'English', maxCharsPerRequest);
|
||||
})();
|
||||
Reference in new issue
Block a user