← all modules

Std.Ai.Trace

Std.Ai.Trace

Types
  type alias Trace
  type Kind = Call | Training | Evaluation | Judge
  type alias Ledger
  type alias RowIn = { model : String , promptTokens : Int , completionTokens : Int , cost : Maybe Money , output : String , facts : Maybe Provider.CallFacts }
  type alias Row
  type alias Summary
  type alias Tally = { rows : Int , failures : Int , unpriced : Int , promptTokens : Int , completionTokens : Int , totals : List ( String, Decimal ) }
  type alias CostLine
  type alias Line = { kind : String , currency : String , total : Decimal , rows : Int }
  type alias TrainingStep

Values
  costs : Db -> Task Error (List CostLine)
      The whole lifecycle's cost across every run: what the app's calls, the
  forResponse : String -> String -> Provider.PriceBook -> Provider.ChatResponse -> Result Error Trace
      Build a trace row from a chat response and a price book: the token counts come
  ledger : String -> Ledger
      A model-call ledger for a run: no key, no price book.
  priced : Provider.PriceBook -> Ledger -> Ledger
      Price the ledger's rows with a price book.
  record : Db -> Trace -> Task Error ()
      Append a trace row (a priced model call).
  recordCall : Db -> Ledger -> Provider.Measured Provider.ChatResponse -> Task Error ()
      Record a measured chat call. A failed call is a row with its outcome and
  recordCost : Db -> Ledger -> String -> Money -> Task Error ()
      Record a cost that is not a model call: a training run's spend, for
  recordToolCall : Db -> Ledger -> Provider.Measured Provider.ToolResponse -> Task Error ()
      Record a measured native tool call (`Provider.measureTools`).
  recordTrainingStep : Db -> String -> TrainingStep -> Task Error ()
      Record a training step. A step already recorded for the run adds no row
  recordUnpriced : Db -> Ledger -> String -> Task Error ()
      Record a run that has no price (a training run on this machine): the row
  runRows : Db -> String -> Task Error (List Row)
      A run's rows, oldest first.
  runSummary : Db -> String -> Task Error Summary
      Sum a run's rows. Fails with `InvalidInput` when a stored cost is not a
  setup : Db -> Task Error ()
      Create the trace tables, or bring tables an earlier release made up to
  spanCount : Db -> String -> Task Error Int
      How many model calls a run recorded (the app's, the eval candidate's and
  totalCost : Db -> String -> Task Error String
      The total cost of a run, summed EXACTLY across its priced rows (model calls,
  tracedChat : Db -> Ledger -> Provider.Options -> Provider.Provider -> List Provider.Message -> Task Error Provider.ChatResponse
      Send a chat, measured, record it, and return its answer. A failed call is
  tracedChatStream : Db -> Ledger -> Provider.Options -> Provider.Provider -> List Provider.Message -> (String -> Task Error ()) -> Task Error Provider.ChatResponse
      `chat`, with each piece of the answer handed to `onPiece` as it is
  trainingSteps : Db -> String -> Task Error (List TrainingStep)
      A training run's recorded steps, in step order.