xujfcn commited on
Commit
0de5f43
·
1 Parent(s): 70dd289

AI图像生成指南 - DALL-E 3/Flux + 提示词技巧 + ComfyUI集成

Browse files
Files changed (1) hide show
  1. README.md +298 -3
README.md CHANGED
@@ -1,3 +1,298 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - tutorial
5
+ - crazyrouter
6
+ - dall-e
7
+ - flux
8
+ - image-generation
9
+ - ai-art
10
+ - stable-diffusion
11
+ - midjourney
12
+ - llm
13
+ language:
14
+ - en
15
+ - zh
16
+ ---
17
+
18
+ # 🎨 Crazyrouter AI 图像生成指南
19
+
20
+ > 通过 Crazyrouter API 调用 DALL-E 3、Flux 等图像生成模型
21
+
22
+ [Crazyrouter](https://crazyrouter.com) 不仅支持文本模型,还支持图像生成模型。一个 API Key 即可调用多种 AI 绘画模型。
23
+
24
+ ---
25
+
26
+ ## 支持的图像模型
27
+
28
+ | 模型 | 提供商 | 特点 |
29
+ |------|--------|------|
30
+ | `dall-e-3` | OpenAI | 高质量、理解复杂提示词 |
31
+ | `dall-e-2` | OpenAI | 快速、便宜 |
32
+ | `flux-schnell` | Black Forest Labs | 开源、速度快 |
33
+ | `flux-dev` | Black Forest Labs | 高质量开源模型 |
34
+
35
+ ---
36
+
37
+ ## 快速开始
38
+
39
+ ### Python
40
+
41
+ ```python
42
+ from openai import OpenAI
43
+
44
+ client = OpenAI(
45
+ base_url="https://crazyrouter.com/v1",
46
+ api_key="sk-your-crazyrouter-key"
47
+ )
48
+
49
+ response = client.images.generate(
50
+ model="dall-e-3",
51
+ prompt="A cute robot serving coffee in a futuristic cafe, digital art style",
52
+ size="1024x1024",
53
+ quality="standard",
54
+ n=1,
55
+ )
56
+
57
+ image_url = response.data[0].url
58
+ print(f"Image URL: {image_url}")
59
+ ```
60
+
61
+ ### cURL
62
+
63
+ ```bash
64
+ curl https://crazyrouter.com/v1/images/generations \
65
+ -H "Content-Type: application/json" \
66
+ -H "Authorization: Bearer sk-your-crazyrouter-key" \
67
+ -d '{
68
+ "model": "dall-e-3",
69
+ "prompt": "A serene Japanese garden with cherry blossoms, watercolor painting",
70
+ "size": "1024x1024",
71
+ "n": 1
72
+ }'
73
+ ```
74
+
75
+ ### Node.js
76
+
77
+ ```javascript
78
+ import OpenAI from "openai";
79
+
80
+ const client = new OpenAI({
81
+ baseURL: "https://crazyrouter.com/v1",
82
+ apiKey: "sk-your-crazyrouter-key",
83
+ });
84
+
85
+ const response = await client.images.generate({
86
+ model: "dall-e-3",
87
+ prompt: "A cyberpunk cityscape at night with neon lights, 4K detailed",
88
+ size: "1024x1024",
89
+ n: 1,
90
+ });
91
+
92
+ console.log(response.data[0].url);
93
+ ```
94
+
95
+ ---
96
+
97
+ ## DALL-E 3 详细用法
98
+
99
+ ### 尺寸选项
100
+
101
+ | 尺寸 | 用途 |
102
+ |------|------|
103
+ | `1024x1024` | 正方形(默认) |
104
+ | `1024x1792` | 竖版(手机壁纸、海报) |
105
+ | `1792x1024` | 横版(桌面壁纸、Banner) |
106
+
107
+ ### 质量选项
108
+
109
+ | 质量 | 说明 |
110
+ |------|------|
111
+ | `standard` | 标准质量(默认,更快) |
112
+ | `hd` | 高清质量(更细腻,更慢) |
113
+
114
+ ### 风格选项
115
+
116
+ | 风格 | 说明 |
117
+ |------|------|
118
+ | `vivid` | 鲜艳风格(默认) |
119
+ | `natural` | 自然风格 |
120
+
121
+ ### 完整示例
122
+
123
+ ```python
124
+ response = client.images.generate(
125
+ model="dall-e-3",
126
+ prompt="A majestic dragon flying over a medieval castle at sunset",
127
+ size="1792x1024", # 横版
128
+ quality="hd", # 高清
129
+ style="vivid", # 鲜艳
130
+ n=1,
131
+ )
132
+ ```
133
+
134
+ ---
135
+
136
+ ## 批量生成
137
+
138
+ ```python
139
+ prompts = [
140
+ "A minimalist logo for a tech startup, blue and white",
141
+ "A cozy reading nook with warm lighting, illustration style",
142
+ "An astronaut playing guitar on the moon, digital art",
143
+ "A steampunk mechanical butterfly, detailed 3D render",
144
+ ]
145
+
146
+ for i, prompt in enumerate(prompts):
147
+ response = client.images.generate(
148
+ model="dall-e-3",
149
+ prompt=prompt,
150
+ size="1024x1024",
151
+ n=1,
152
+ )
153
+ print(f"Image {i+1}: {response.data[0].url}")
154
+ ```
155
+
156
+ ---
157
+
158
+ ## 下载图片
159
+
160
+ ```python
161
+ import requests
162
+
163
+ response = client.images.generate(
164
+ model="dall-e-3",
165
+ prompt="A beautiful sunset over the ocean",
166
+ size="1024x1024",
167
+ n=1,
168
+ )
169
+
170
+ image_url = response.data[0].url
171
+
172
+ # 下载保存
173
+ img_data = requests.get(image_url).content
174
+ with open("sunset.png", "wb") as f:
175
+ f.write(img_data)
176
+ print("Image saved as sunset.png")
177
+ ```
178
+
179
+ ---
180
+
181
+ ## 在客户端中使用
182
+
183
+ ### Cherry Studio
184
+
185
+ Cherry Studio 内置 AI 绘画功能,配置 Crazyrouter 后可以直接在客户端中生成图片。
186
+
187
+ ### ChatBox
188
+
189
+ ChatBox 支持图片生成,在对话中输入绘画提示词即可。
190
+
191
+ ### NextChat / LobeChat
192
+
193
+ 这些客户端支持 DALL-E 插件,配置 Crazyrouter API 后可以在对话中生成图片。
194
+
195
+ ---
196
+
197
+ ## 提示词技巧
198
+
199
+ ### 基础结构
200
+
201
+ ```
202
+ [主体] + [风格] + [细节] + [氛围]
203
+ ```
204
+
205
+ ### 示例
206
+
207
+ | 提示词 | 效果 |
208
+ |--------|------|
209
+ | `A cat wearing a space suit, digital art, highly detailed` | 太空猫,数字艺术风格 |
210
+ | `Minimalist mountain landscape, Japanese ink wash painting` | 极简山水,水墨画风格 |
211
+ | `Product photo of a sleek smartphone, studio lighting, white background` | 产品摄影风格 |
212
+ | `Isometric view of a tiny coffee shop, pixel art, warm colors` | 等距像素风咖啡店 |
213
+
214
+ ### 风格关键词
215
+
216
+ - **写实**: `photorealistic, 8K, detailed, professional photography`
217
+ - **插画**: `illustration, digital art, concept art, artstation`
218
+ - **水彩**: `watercolor painting, soft colors, artistic`
219
+ - **像素**: `pixel art, retro, 16-bit, game style`
220
+ - **3D**: `3D render, octane render, blender, cinema 4D`
221
+ - **动漫**: `anime style, manga, studio ghibli`
222
+ - **极简**: `minimalist, clean, simple, flat design`
223
+
224
+ ---
225
+
226
+ ## 与文本模型结合
227
+
228
+ 让 AI 先生成提示词,再用来绘画:
229
+
230
+ ```python
231
+ # Step 1: 用文本模型生成优化的提示词
232
+ chat_response = client.chat.completions.create(
233
+ model="gpt-4o-mini",
234
+ messages=[{
235
+ "role": "user",
236
+ "content": "Generate a detailed DALL-E prompt for: a cozy winter cabin. Include style, lighting, and mood details. Output only the prompt."
237
+ }]
238
+ )
239
+ optimized_prompt = chat_response.choices[0].message.content
240
+
241
+ # Step 2: 用优化后的提示词生成图片
242
+ image_response = client.images.generate(
243
+ model="dall-e-3",
244
+ prompt=optimized_prompt,
245
+ size="1792x1024",
246
+ quality="hd",
247
+ n=1,
248
+ )
249
+ print(f"Prompt: {optimized_prompt}")
250
+ print(f"Image: {image_response.data[0].url}")
251
+ ```
252
+
253
+ ---
254
+
255
+ ## ComfyUI 集成
256
+
257
+ 如果你使用 ComfyUI 进行更高级的图像生成工作流,可以通过 Crazyrouter API 获取文本提示词优化:
258
+
259
+ ```python
260
+ # 用 Crazyrouter 的文本模型优化 ComfyUI 的提示词
261
+ response = client.chat.completions.create(
262
+ model="gpt-4o-mini",
263
+ messages=[{
264
+ "role": "system",
265
+ "content": "You are a Stable Diffusion prompt expert. Convert user descriptions into optimized SD prompts with positive and negative prompts."
266
+ }, {
267
+ "role": "user",
268
+ "content": "A beautiful girl in a flower garden"
269
+ }]
270
+ )
271
+ print(response.choices[0].message.content)
272
+ # Output: positive prompt + negative prompt for ComfyUI/SD
273
+ ```
274
+
275
+ ---
276
+
277
+ ## 价格参考
278
+
279
+ | 模型 | 尺寸 | 质量 | 价格/张 |
280
+ |------|------|------|---------|
281
+ | DALL-E 3 | 1024x1024 | standard | ~$0.04 |
282
+ | DALL-E 3 | 1024x1024 | hd | ~$0.08 |
283
+ | DALL-E 3 | 1792x1024 | standard | ~$0.08 |
284
+ | DALL-E 3 | 1792x1024 | hd | ~$0.12 |
285
+ | DALL-E 2 | 1024x1024 | - | ~$0.02 |
286
+
287
+ *通过 Crazyrouter 调用,价格可能更优惠。*
288
+
289
+ ---
290
+
291
+ ## 链接
292
+
293
+ - 🌐 [Crazyrouter](https://crazyrouter.com) — 获取 API Key
294
+ - 🤖 [在线 Demo](https://huggingface.co/spaces/xujfcn/Crazyrouter-Demo)
295
+ - 📖 [快速入门](https://huggingface.co/xujfcn/Crazyrouter-Getting-Started)
296
+ - 💻 [编程工具配置](https://huggingface.co/xujfcn/Crazyrouter-AI-Coding-Tools)
297
+ - 💬 [Telegram 社区](https://t.me/crazyrouter)
298
+ - 🐦 [Twitter @metaviiii](https://twitter.com/metaviiii)