-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_txt2img_result.go
55 lines (45 loc) · 1.53 KB
/
request_txt2img_result.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
50
51
52
53
54
55
package ernieapi
import (
"context"
"github.com/google/go-querystring/query"
"net/http"
"strings"
)
type Txt2ImgResultRequest struct {
TaskId int `json:"taskId" url:"taskId"`
}
type Txt2ImgResultResponse struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data Txt2ImgResultData `json:"data"`
}
type Txt2ImgResultData struct {
Img string `json:"img"`
Waiting string `json:"waiting"`
ImgUrls []Txt2ImgResultDataImages `json:"imgUrls"`
CreateTime string `json:"createTime"`
RequestID string `json:"requestId"`
Style string `json:"style"`
Text string `json:"text"`
Resolution string `json:"resolution"`
TaskID int `json:"taskId"`
Status int `json:"status"`
}
type Txt2ImgResultDataImages struct {
Image string `json:"image"`
Score interface{} `json:"score"`
}
func (c *Client) GetTxt2ImgResult(ctx context.Context, request *Txt2ImgResultRequest) (response *Txt2ImgResultResponse, err error) {
urlSuffix := "/rest/1.0/ernievilg/v1/getImg"
requestParams, err := query.Values(*request)
if err != nil {
return response, ErrV3CustomizeRequest
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.fullURL(urlSuffix), strings.NewReader(requestParams.Encode()))
if err != nil {
return
}
errResponse := &ResponseError{}
err = c.sendRequest(req, &response, errResponse)
return
}