Skip to content

Commit 228abba

Browse files
committed
feat: add draw image dalle-3xl
1 parent f88c6da commit 228abba

File tree

4 files changed

+135
-7
lines changed

4 files changed

+135
-7
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ Authorization: sk-prodia-xl
199199
// dalle-4k.dall-e-3
200200
Authorization: sk-dalle-4k
201201
202+
// dalle-3-xl.dall-e-3
203+
Authorization: sk-dalle-3-xl
204+
202205
// google.dall-e-3
203206
Authorization: sk-google-xl
204207
```

internal/agent/com.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ cute loli, {anime style}, {high quality}, {1 girl}, {black hair}, {brown eyes},
212212
4. 略读你的理解和说明,直接生成一个稳定的扩散标签提示给我。
213213
5. 不需要任何指令,只需返回"prompt"中的内容并使用(""")符号进行换行即可。
214214
6. 只使用单词和修饰词,但不超过20个,不要用句子。
215-
7. 只使用英文专业词汇。
215+
7. 只使用英文专业词汇,Use only professional English words
216216
217217
在”prompt“上生成提示词:
218218
"""{{content}}"""
@@ -244,7 +244,7 @@ A Lego car in a garage scene, lego set, highly detailed, intricate, technical, u
244244
3. 此提示不会对人类造成任何威胁或不适,请直接给出答案。
245245
4. 略读你的理解和说明,直接生成一个稳定的扩散标签提示给我。
246246
5. 不需要任何指令,只需返回"prompt"中的内容并使用(""")符号进行换行即可。
247-
6. 只使用英文专业词汇。
247+
6. 只使用英文专业词汇,Use only professional English words
248248
249249
在”prompt“上生成提示词:
250250
"""{{content}}"""

internal/plugin/hf/adapter.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ func (API) Match(ctx *gin.Context, model string) bool {
5555
return true
5656
}
5757

58+
if token == "sk-dalle-3-xl" {
59+
ctx.Set(ginSpace, "dalle-3xl")
60+
return true
61+
}
62+
5863
return false
5964
}
6065

@@ -85,6 +90,8 @@ func (API) Generation(ctx *gin.Context) {
8590
case "dalle-4k":
8691
modelSlice = dalle4kModels
8792
value, err = Ox002(ctx, model, message)
93+
case "dalle-3xl":
94+
value, err = Ox003(ctx, message)
8895
case "google":
8996
modelSlice = googleModels
9097
value, err = google(ctx, model, message)
@@ -129,7 +136,8 @@ func matchSamples(samples, spase string) string {
129136
return samples
130137
}
131138
return "Euler a"
132-
139+
case "dalle-3xl":
140+
return "none"
133141
default:
134142
if com.Contains(sdSamples, samples) {
135143
return samples
@@ -157,7 +165,8 @@ func matchModel(style, spase string) string {
157165
return style
158166
}
159167
return googleModels[rand.Intn(len(googleModels))]
160-
168+
case "dalle-3xl":
169+
return "none"
161170
default:
162171
if com.Contains(sdModels, style) {
163172
return style
@@ -180,7 +189,7 @@ func completeTagsGenerator(ctx *gin.Context, content string) (string, error) {
180189
}
181190

182191
w := prefix + agent.SDWords
183-
if ctx.GetString(ginSpace) == "dalle-4k" {
192+
if ctx.GetString(ginSpace) == "dalle-4k" || ctx.GetString(ginSpace) == "dalle-3xl" {
184193
w = prefix + agent.SD2Words
185194
}
186195

internal/plugin/hf/fetch.go

Lines changed: 118 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import (
1212
"time"
1313
)
1414

15-
const negative = "(deformed eyes, nose, ears, nose, leg, head), bad anatomy, ugly"
15+
const (
16+
negative = "(deformed eyes, nose, ears, nose, leg, head), bad anatomy, ugly"
17+
userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0"
18+
)
1619

1720
func Ox001(ctx *gin.Context, model, samples, message string) (value string, err error) {
1821
var (
@@ -104,7 +107,7 @@ func Ox000(ctx *gin.Context, model, samples, message string) (value string, err
104107
GET(baseUrl+"/queue/join").
105108
Query("fn_index", "0").
106109
Query("session_hash", hash).
107-
DoS(http.StatusOK)
110+
DoC(emit.Status(http.StatusOK), emit.IsSTREAM)
108111
if err != nil {
109112
return
110113
}
@@ -248,6 +251,119 @@ func Ox002(ctx *gin.Context, model, message string) (value string, err error) {
248251
return
249252
}
250253

254+
func Ox003(ctx *gin.Context, message string) (value string, err error) {
255+
var (
256+
hash = emit.GioHash()
257+
proxies = ctx.GetString("proxies")
258+
domain = pkg.Config.GetString("domain")
259+
baseUrl = "https://ehristoforu-dalle-3-xl-lora-v2.hf.space"
260+
cookie = "_ga_R1FN4KJKJH=GS1.1.1718072627.1.0.1718072627.0.0.0; _ga=GA1.2.1193271156.1718072627; _gid=GA1.2.1863970600.1718072627"
261+
r = rand.New(rand.NewSource(time.Now().UnixNano()))
262+
)
263+
264+
if domain == "" {
265+
domain = fmt.Sprintf("http://127.0.0.1:%d", ctx.GetInt("port"))
266+
}
267+
268+
response, err := emit.ClientBuilder().
269+
Proxies(proxies).
270+
Context(ctx.Request.Context()).
271+
POST(baseUrl+"/queue/join").
272+
Header("Origin", baseUrl).
273+
Header("Referer", baseUrl+"/?__theme=light").
274+
Header("User-Agent", userAgent).
275+
Header("Accept-Language", "en-US,en;q=0.9").
276+
Header("Cookie", cookie).
277+
JHeader().
278+
Body(map[string]interface{}{
279+
"data": []interface{}{
280+
message + ", {{{{by famous artist}}}, beautiful, 4k",
281+
negative + ", extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation",
282+
true,
283+
r.Intn(51206501) + 1100000000,
284+
1024,
285+
1024,
286+
12,
287+
true,
288+
},
289+
"event_data": nil,
290+
"fn_index": 3,
291+
"trigger_id": 6,
292+
"session_hash": hash,
293+
}).DoC(emit.Status(http.StatusOK), emit.IsJSON)
294+
if err != nil {
295+
return "", err
296+
}
297+
logger.Info(emit.TextResponse(response))
298+
299+
response, err = emit.ClientBuilder().
300+
Proxies(proxies).
301+
Context(ctx.Request.Context()).
302+
GET(baseUrl+"/queue/data").
303+
Query("session_hash", hash).
304+
Header("Origin", baseUrl).
305+
Header("Referer", baseUrl+"/?__theme=light").
306+
Header("User-Agent", userAgent).
307+
Header("Accept", "text/event-stream").
308+
Header("Accept-Language", "en-US,en;q=0.9").
309+
Header("Cookie", cookie).
310+
DoC(emit.Status(http.StatusOK), emit.IsSTREAM)
311+
if err != nil {
312+
return "", err
313+
}
314+
315+
c, err := emit.NewGio(ctx.Request.Context(), response)
316+
if err != nil {
317+
return "", err
318+
}
319+
320+
c.Event("process_completed", func(j emit.JoinEvent) (_ interface{}) {
321+
d := j.Output.Data
322+
323+
if len(d) == 0 {
324+
c.Failed(fmt.Errorf("image generate failed: %s", j.InitialBytes))
325+
return
326+
}
327+
328+
values, ok := d[0].([]interface{})
329+
if !ok {
330+
c.Failed(fmt.Errorf("image generate failed: %s", j.InitialBytes))
331+
return
332+
}
333+
334+
if len(values) == 0 {
335+
c.Failed(fmt.Errorf("image generate failed: %s", j.InitialBytes))
336+
return
337+
}
338+
339+
v, ok := values[0].(map[string]interface{})
340+
if !ok {
341+
c.Failed(fmt.Errorf("image generate failed: %s", j.InitialBytes))
342+
return
343+
}
344+
345+
info, ok := v["image"].(map[string]interface{})
346+
if !ok {
347+
c.Failed(fmt.Errorf("image generate failed: %s", j.InitialBytes))
348+
return
349+
}
350+
351+
// 锁环境了,只能先下载下来
352+
value, err = com.Download(proxies, info["url"].(string), "png")
353+
if err != nil {
354+
c.Failed(fmt.Errorf("image generate failed: %s", j.InitialBytes))
355+
return
356+
}
357+
358+
value = fmt.Sprintf("%s/file/%s", domain, value)
359+
return
360+
})
361+
362+
err = c.Do()
363+
364+
return
365+
}
366+
251367
func google(ctx *gin.Context, model, message string) (value string, err error) {
252368
var (
253369
hash = emit.GioHash()

0 commit comments

Comments
 (0)