Skip to content

Commit a2e0a51

Browse files
Merge pull request #24 from modzy/http-status-marshal
Http status marshal
2 parents 12ba988 + fbb1b96 commit a2e0a51

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
lines changed

internal/testing/main.go

+32-3
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ func main() {
2626
client := modzy.NewClient(baseURL).WithAPIKey(apiKey)
2727

2828
if os.Getenv("MODZY_DEBUG") == "1" {
29-
client = client.WithOptions(modzy.WithHTTPDebugging(false, false))
29+
client = client.WithOptions(modzy.WithHTTPDebugging(true, true))
3030
}
3131

32-
// listJobsHistory(client)
32+
listJobsHistory(client)
3333
// errorChecking()
3434
// submitExampleText(client, false)
35+
// submitExampleTextWithFailures(client, false)
3536
// submitExampleEmbedded(client, true)
3637
// submitExampleChunked(client, false)
37-
submitExampleS3(client, false)
38+
// submitExampleS3(client, false)
3839
// submitExampleJDBC(client, false)
3940
// describeJob(client, "86b76e20-c506-485d-af4e-2072c41ca35b")
4041
// describeModel(client, "ed542963de")
@@ -125,6 +126,30 @@ func submitExampleText(client modzy.Client, cancel bool) {
125126
afterSubmit(client, cancel, submittedJob)
126127
}
127128

129+
func submitExampleTextWithFailures(client modzy.Client, cancel bool) {
130+
logrus.Info("Will submit example text job")
131+
submittedJob, err := client.Jobs().SubmitJobText(ctx, &modzy.SubmitJobTextInput{
132+
ModelIdentifier: "ed542963de",
133+
ModelVersion: "0.0.27",
134+
Timeout: time.Minute * 5,
135+
Inputs: map[string]modzy.TextInputItem{
136+
"happy-text": {
137+
"not-input.txt": "I love AI! :)",
138+
},
139+
"angry-text": {
140+
"input.txt": "I hate AI! abysmal. adverse. alarming. angry. annoy. anxious :(",
141+
},
142+
},
143+
})
144+
if err != nil {
145+
logrus.WithError(err).Fatalf("Failed to submit text job")
146+
return
147+
}
148+
149+
logrus.WithField("jobIdentifier", submittedJob.Response.JobIdentifier).Info("text job submitted")
150+
afterSubmit(client, cancel, submittedJob)
151+
}
152+
128153
//go:embed smiling_face.encoded
129154
var SmilingFace string
130155

@@ -240,6 +265,10 @@ func afterSubmit(client modzy.Client, cancel bool, job modzy.JobActions) {
240265
return
241266
}
242267
logrus.Infof("Job results: %s -> %d results", jobResults.Results.JobIdentifier, jobResults.Results.Total)
268+
269+
if len(jobResults.Results.Failures) > 0 {
270+
logrus.Warnf("Job had failures: %+v", jobResults.Results.Failures)
271+
}
243272
}
244273
}
245274

model/jobresult.go

+25-7
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,36 @@ import (
77
)
88

99
type JobResults struct {
10-
JobIdentifier string `json:"jobIdentifier"`
11-
Total int `json:"total"`
12-
Completed int `json:"completed"`
13-
Failed int `json:"failed"`
14-
Finished bool `json:"finished"`
15-
SubmittedBy string `json:"submittedByKey"`
16-
Results map[string]JobResult `json:"results"`
10+
JobIdentifier string `json:"jobIdentifier"`
11+
Total int `json:"total"`
12+
Completed int `json:"completed"`
13+
Failed int `json:"failed"`
14+
Finished bool `json:"finished"`
15+
SubmittedBy string `json:"submittedByKey"`
16+
Explained bool `json:"explained"`
17+
SubmittedAt ModzyTime `json:"submittedAt"`
18+
19+
JobQueueTime int `json:"jobQueueTime"`
20+
JobProcessedTime int `json:"jobProcessedTime"`
21+
JobElapsedTime int `json:"jobElapsedTime"`
22+
23+
// next api version:
24+
// InitialQueueTime int `json:"initialQueueTime"`
25+
// TotalQueueTime int `json:"totalQueueTime"`
26+
// AverageModelLatency float64 `json:"averageModelLatency"`
27+
// TotalModelLatency float64 `json:"totalModelLatency"`
28+
// ElapsedTime float64 `json:"elapsedTime"`
29+
// StartingResultSummarizing ModzyTime `json:"startingResultSummarizing"`
30+
// ResultSummarizing int `json:"resultSummarizing"`
31+
32+
Results map[string]JobResult `json:"results"`
33+
Failures map[string]JobResult `json:"failures"`
1734
}
1835

1936
type JobResult struct {
2037
Status string `json:"status"`
2138
Engine string `json:"engine"`
39+
Error string `json:"error"`
2240
StartTime ModzyTime `json:"startTime"`
2341
UpdateTime ModzyTime `json:"updateTime"`
2442
EndTime ModzyTime `json:"endTime"`

requestor.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ func (r *requestor) execute(
107107
// non OK response
108108
apiError := &ModzyHTTPError{}
109109
if err := json.NewDecoder(toDecode).Decode(apiError); err != nil {
110-
return resp, errors.WithMessagef(err, "failed parsing non 200 response of %d from %s:%s", resp.StatusCode, method, path)
110+
logrus.WithError(err).Warnf("failed parsing non 200 response of %d from %s:%s", resp.StatusCode, method, path)
111+
return resp, fmt.Errorf("request to %s failed with response: %s", req.URL, resp.Status)
111112
}
112113
return resp, apiError
113114
}

0 commit comments

Comments
 (0)