A Go SDK for TypeSafe's Jev API.
go get github.com/kyledickey/jev-goThe package name is jev.
The client reads your key from TYPESAFE_API_KEY by default.
client, err := jev.NewClient()
if err != nil {
log.Fatal(err)
}
resp, err := client.SystemOne(ctx, jev.SystemOneRequest{
State: "I bought this product 10 days ago and I want a full refund.",
Questions: map[string]jev.Question{
"eligible": jev.NoulQuestion{
Instructions: "Is the customer eligible for a refund?",
Criteria: &jev.NoulCriteria{
True: "Full refunds are allowed within 30 days of purchase.",
},
},
},
})
if err != nil {
log.Fatal(err)
}
if a, ok := resp.Answers["eligible"].(*jev.NoulAnswer); ok {
fmt.Printf("eligible: %.2f\n", a.Noul)
}There are three question types, each with a matching answer type:
| Question | Answer |
|---|---|
NoulQuestion |
*NoulAnswer |
ChoiceQuestion |
*ChoiceAnswer |
ScoreQuestion |
*ScoreAnswer |
See the Jev docs for how each one works, and examples/basic for a full program.
client, err := jev.NewClient(
jev.WithAPIKey("..."),
jev.WithHTTPClient(&http.Client{Timeout: 10 * time.Second}),
jev.WithBaseURL("https://api.typesafe.ai/v1"),
)Non-2xx responses come back as *jev.APIError, which has the status code, headers, and raw body.
var apiErr *jev.APIError
if errors.As(err, &apiErr) {
log.Printf("status %d: %s", apiErr.StatusCode, apiErr.Body)
}Requests aren't retried, so wrap calls yourself if you need that.
Issues and PRs are welcome. For anything bigger than a small fix, it's worth opening an issue first so we can talk it through.
Before sending a PR, make sure these pass (CI runs the same checks):
gofmt -l .
go vet ./...
go test -race ./...