mirror of
https://github.com/kyledickey/jev-go.git
synced 2026-10-31 10:05:29 +00:00
TypeSafe.ai Jev Go SDK
https://docs.typesafe.ai
- Go 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| .github | ||
| examples/basic | ||
| .gitignore | ||
| answers.go | ||
| answers_test.go | ||
| client.go | ||
| client_test.go | ||
| doc.go | ||
| errors.go | ||
| errors_test.go | ||
| go.mod | ||
| LICENSE | ||
| questions.go | ||
| questions_test.go | ||
| README.md | ||
| systemone.go | ||
| systemone_test.go | ||
jev-go
A Go SDK for TypeSafe's Jev API.
Install
go get github.com/kyledickey/jev-go
The package name is jev.
Usage
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.
Options
client, err := jev.NewClient(
jev.WithAPIKey("..."),
jev.WithHTTPClient(&http.Client{Timeout: 10 * time.Second}),
jev.WithBaseURL("https://api.typesafe.ai/v1"),
)
Errors
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.
Contributing
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 ./...