-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathimage.go
49 lines (40 loc) · 1.18 KB
/
image.go
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
package go_ernie
import (
"context"
"fmt"
"net/http"
)
const visualGLMURL = "/rpc/2.0/ai_custom/v1/wenxinworkshop/txt2img/"
const sdXLURl = "/rpc/2.0/ai_custom/v1/wenxinworkshop/text2image/"
type ImageRequest struct {
Prompt string `json:"prompt"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
Model string `json:"-"`
}
type ImageResponse struct {
Images []string `json:"images"`
APIError
}
func (c *Client) CreateImageVisualGLM(ctx context.Context, request ImageRequest) (response ImageResponse, err error) {
req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(fmt.Sprintf("%s%s", visualGLMURL, request.Model)), withBody(request))
if err != nil {
return
}
err = c.sendRequest(req, &response)
if response.ErrorCode != 0 {
err = &response.APIError
}
return
}
func (c *Client) CreateImageStableDiffusionXL(ctx context.Context, request ImageRequest) (response ImageResponse, err error) {
req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(fmt.Sprintf("%s%s", sdXLURl, request.Model)), withBody(request))
if err != nil {
return
}
err = c.sendRequest(req, &response)
if response.ErrorCode != 0 {
err = &response.APIError
}
return
}