-
Notifications
You must be signed in to change notification settings - Fork 11
/
baidu_txt2img.go
39 lines (31 loc) · 775 Bytes
/
baidu_txt2img.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
package go_ernie
import (
"context"
"fmt"
"net/http"
)
const baiduTxt2ImgURL = "/rpc/2.0/ai_custom/v1/wenxinworkshop/txt2img/"
type BaiduTxt2ImgRequest struct {
Prompt string `json:"prompt"`
Width string `json:"width"`
Height string `json:"height"`
Model string `json:"-"`
}
type BaiduTxt2ImgResponse struct {
Images []string `json:"images"`
APIError
}
func (c *Client) CreateBaiduTxt2Img(
ctx context.Context,
request BaiduTxt2ImgRequest,
) (response BaiduTxt2ImgResponse, err error) {
req, err := c.newRequest(ctx, http.MethodPost, c.fullURL(fmt.Sprintf("%s%s", baiduTxt2ImgURL, request.Model)), withBody(request))
if err != nil {
return
}
err = c.sendRequest(req, &response)
if response.ErrorCode != 0 {
err = &response.APIError
}
return
}