typesafe-ai-core
Types, JSON codecs and typed questions for the TypeSafe AI API
typesafe-ai-core
Transport-agnostic bindings to TypeSafe AI's System One API: typed Noul, Choice and Score questions whose answers decode to your own Haskell types, a one-to-one mirror of the OpenAPI schemas with JSON codecs, and API calls as plain values.
This package does no networking. Use it with servant or any other HTTP
stack. For a ready-to-use client, depend on
typesafe-ai instead; it
re-exports everything here.
data Department = Billing | Technical | Sales
deriving stock (Show, Eq, Generic)
deriving anyclass (ChoiceOption)
routing :: Questions (Choice Department, Noul)
routing =
(,) <$> ask "department" (choice "Which team should handle this?")
<*> ask "is_urgent" (noul "Does this convey urgency?")
-- The request, for any HTTP client:
request :: Either RequestError Wire.SystemOneRequest
request = systemOneRequest jevLatest "Help! My payouts have been failing." routing
-- And the typed answers, from its response:
answers :: Wire.SystemOneResponse -> Either (NonEmpty AnswerError) (Evaluation (Choice Department, Noul))
answers = decodeEvaluation routing Nothing
Start with the documentation of TypeSafe.Core and TypeSafe.Question. The
repository has more examples.
The bindings are checked against version 0.2.0 of the TypeSafe OpenAPI
specification (apiSpecVersion), which is included in the package
(spec/openapi.json).
This is a community SDK, not affiliated with or endorsed by TypeSafe AI.
- aeson >=2.1 && <2.4
- base >=4.18 && <4.23
- bytestring >=0.11.3 && <0.13
- containers >=0.6.7 && <0.9
- deepseq >=1.4.8 && <1.6
- http-types >=0.12.3 && <0.13
- text >=2.0 && <2.2
- time >=1.12 && <1.17
- vector >=0.13 && <0.14
- 0.1.0.0