|
|
|
@@ -41,7 +41,7 @@ func (c VolcesClient) runImage(ctx context.Context, request Request, apiKey stri
|
|
|
|
|
req.Header.Set("Content-Type", "application/json")
|
|
|
|
|
req.Header.Set("Authorization", "Bearer "+apiKey)
|
|
|
|
|
|
|
|
|
|
resp, err := httpClient(c.HTTPClient).Do(req)
|
|
|
|
|
resp, err := httpClient(request.HTTPClient, c.HTTPClient).Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return Response{}, &ClientError{Code: "network", Message: err.Error(), Retryable: true}
|
|
|
|
|
}
|
|
|
|
@@ -69,7 +69,7 @@ func (c VolcesClient) runImage(ctx context.Context, request Request, apiKey stri
|
|
|
|
|
func (c VolcesClient) runVideo(ctx context.Context, request Request, apiKey string) (Response, error) {
|
|
|
|
|
body := volcesVideoBody(request)
|
|
|
|
|
submitStartedAt := time.Now()
|
|
|
|
|
submitResult, submitRequestID, err := c.postJSON(ctx, request.Candidate.BaseURL, "/contents/generations/tasks", apiKey, body)
|
|
|
|
|
submitResult, submitRequestID, err := c.postJSON(ctx, request, request.Candidate.BaseURL, "/contents/generations/tasks", apiKey, body)
|
|
|
|
|
submitFinishedAt := time.Now()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return Response{}, annotateResponseError(err, submitRequestID, submitStartedAt, submitFinishedAt)
|
|
|
|
@@ -96,7 +96,7 @@ func (c VolcesClient) runVideo(ctx context.Context, request Request, apiKey stri
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pollStartedAt := time.Now()
|
|
|
|
|
pollResult, pollRequestID, err := c.getJSON(ctx, request.Candidate.BaseURL, "/contents/generations/tasks/"+upstreamTaskID, apiKey)
|
|
|
|
|
pollResult, pollRequestID, err := c.getJSON(ctx, request, request.Candidate.BaseURL, "/contents/generations/tasks/"+upstreamTaskID, apiKey)
|
|
|
|
|
pollFinishedAt := time.Now()
|
|
|
|
|
requestID := firstNonEmpty(pollRequestID, submitRequestID, upstreamTaskID)
|
|
|
|
|
if err != nil {
|
|
|
|
@@ -143,7 +143,7 @@ func (c VolcesClient) runVideo(ctx context.Context, request Request, apiKey stri
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c VolcesClient) postJSON(ctx context.Context, baseURL string, path string, apiKey string, body map[string]any) (map[string]any, string, error) {
|
|
|
|
|
func (c VolcesClient) postJSON(ctx context.Context, request Request, baseURL string, path string, apiKey string, body map[string]any) (map[string]any, string, error) {
|
|
|
|
|
raw, _ := json.Marshal(body)
|
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, joinURL(baseURL, path), bytes.NewReader(raw))
|
|
|
|
|
if err != nil {
|
|
|
|
@@ -151,7 +151,7 @@ func (c VolcesClient) postJSON(ctx context.Context, baseURL string, path string,
|
|
|
|
|
}
|
|
|
|
|
req.Header.Set("Content-Type", "application/json")
|
|
|
|
|
req.Header.Set("Authorization", "Bearer "+apiKey)
|
|
|
|
|
resp, err := httpClient(c.HTTPClient).Do(req)
|
|
|
|
|
resp, err := httpClient(request.HTTPClient, c.HTTPClient).Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, "", &ClientError{Code: "network", Message: err.Error(), Retryable: true}
|
|
|
|
|
}
|
|
|
|
@@ -160,13 +160,13 @@ func (c VolcesClient) postJSON(ctx context.Context, baseURL string, path string,
|
|
|
|
|
return result, requestID, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c VolcesClient) getJSON(ctx context.Context, baseURL string, path string, apiKey string) (map[string]any, string, error) {
|
|
|
|
|
func (c VolcesClient) getJSON(ctx context.Context, request Request, baseURL string, path string, apiKey string) (map[string]any, string, error) {
|
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, joinURL(baseURL, path), nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, "", err
|
|
|
|
|
}
|
|
|
|
|
req.Header.Set("Authorization", "Bearer "+apiKey)
|
|
|
|
|
resp, err := httpClient(c.HTTPClient).Do(req)
|
|
|
|
|
resp, err := httpClient(request.HTTPClient, c.HTTPClient).Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, "", &ClientError{Code: "network", Message: err.Error(), Retryable: true}
|
|
|
|
|
}
|
|
|
|
|