forked from QuantumNous/new-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_image_generation_openapi.js
More file actions
90 lines (82 loc) · 2.34 KB
/
Copy pathpatch_image_generation_openapi.js
File metadata and controls
90 lines (82 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const fs = require('fs');
if (process.argv.length < 3) {
console.error('Usage: node patch_image_generation_openapi.js <openapi3.json>');
process.exit(1);
}
const file = process.argv[2];
const doc = JSON.parse(fs.readFileSync(file, 'utf8'));
const imageGenerationExamples = {
openai: {
summary: "OpenAI DALL-E 中文提示词示例",
value: {
model: "dall-e-3",
prompt: "可爱的中国小女孩在花园里玩耍",
response_format: "url",
size: "1024x1024",
quality: "standard",
n: 1
}
},
gemini: {
summary: "Gemini 中文提示词示例",
value: {
model: "nano-banana",
prompt: "一只猫在钢琴上跳舞",
response_format: "url",
size: "1024x1024",
n: 1
}
},
jimeng: {
summary: "即梦生图中文提示词示例",
value: {
model: "doubao-seedream-4-0-250828",
prompt: "可爱的中国小女孩在花园里玩耍",
image: ["https://ark-project.tos-cn-beijing.volces.com/doc_image/seedream4_imagesToimages_1.png"],
watermark: false,
extra_fields: {
width: 768,
height: 512,
seed: -1,
use_pre_llm: true,
use_sr: true,
logo_info: {
add_logo: true,
position: 1,
opacity: 0.4
}
}
}
}
};
// 可能的图像生成路径
const imagePaths = [
"/api/v1/images/generations",
"/v1/images/generations",
];
let patchedPaths = [];
imagePaths.forEach(path => {
try {
if (doc.paths && doc.paths[path] && doc.paths[path].post) {
if (doc.paths[path].post.requestBody &&
doc.paths[path].post.requestBody.content &&
doc.paths[path].post.requestBody.content["application/json"]) {
doc.paths[path].post.requestBody.content["application/json"].examples = imageGenerationExamples;
patchedPaths.push(path);
}
}
} catch (e) {
console.warn(`Failed to patch ${path}:`, e.message);
}
});
if (patchedPaths.length > 0) {
fs.writeFileSync(file, JSON.stringify(doc, null, 2));
console.log(`Patched openapi3.json with image generation examples for paths: ${patchedPaths.join(', ')}`);
} else {
console.log("No image generation paths found in openapi3.json. Available paths:");
if (doc.paths) {
Object.keys(doc.paths).forEach(path => {
console.log(` - ${path}`);
});
}
}