typesafe-ai
Client for the TypeSafe AI System One API
typesafe-ai
A Haskell client for TypeSafe AI's System One API. Send text or JSON state with typed questions, and get back answers that decode to your own Haskell types.
{-# LANGUAGE DeriveAnyClass, DeriveGeneric, DerivingStrategies, OverloadedStrings #-}
import GHC.Generics (Generic)
import TypeSafe
data Department = Billing | Technical | Sales
deriving stock (Show, Eq, Generic)
deriving anyclass (ChoiceOption)
main :: IO ()
main = do
client <- newClientFromEnv -- reads TYPESAFE_API_KEY
result <-
send client $
systemOne "Help! My payouts have been failing for 3 days." $
(,) <$> ask "department" (choice "Which team should handle this?")
<*> ask "is_urgent" (noul "Does this convey urgency?")
let (department, urgent) = evaluationAnswers result
print (choiceSelected department :: Department, choiceConfidence department)
print (noulProbability urgent)
- Choice options and Score levels are your own types; the answer can only be one of them.
- Questions combine with
Applicative, and many questions fit in one request. - Built on
http-client, with a shared TLS connection pool, per-attempt timeouts, and retries with exponential backoff that honourRetry-After. - Errors are values that separate local validation, error responses, connection failures and unexpected responses.
Read TypeSafe.Tutorial for a guided tour. The types, codecs and calls live
in typesafe-ai-core,
which has no HTTP dependency. The
repository has runnable examples.
This is a community SDK, not affiliated with or endorsed by TypeSafe AI.
- base >=4.18 && <4.23
- bytestring >=0.11.3 && <0.13
- http-client >=0.7.13 && <0.8
- http-client-tls >=0.3.6.2 && <0.5
- http-types >=0.12.3 && <0.13
- random >=1.2 && <1.4
- text >=2.0 && <2.2
- time >=1.12 && <1.17
- typesafe-ai-core >=0.1.0.0 && <0.1.1
- 0.1.0.0