| 1 | /** |
| 2 | * Codecs for text and JSON decisions from Cloudflare Clef models. |
| 3 | * |
| 4 | * @stability unstable |
| 5 | * @since 4.0.0 |
| 6 | */ |
| 7 | import * as Schema from "effect/Schema" |
| 8 | |
| 9 | /** |
| 10 | * A classification question. |
| 11 | * |
| 12 | * @stability unstable |
| 13 | * @category schemas |
| 14 | * @since 4.0.0 |
| 15 | */ |
| 16 | export const ChoiceQuestion = Schema.Struct({ |
| 17 | type: Schema.Literal("choice"), |
| 18 | instructions: Schema.String, |
| 19 | criteria: Schema.Record(Schema.String, Schema.String) |
| 20 | }) |
| 21 | |
| 22 | /** |
| 23 | * An ordered rating question. |
| 24 | * |
| 25 | * @stability unstable |
| 26 | * @category schemas |
| 27 | * @since 4.0.0 |
| 28 | */ |
| 29 | export const ScoreQuestion = Schema.Struct({ |
| 30 | type: Schema.Literal("score"), |
| 31 | instructions: Schema.String, |
| 32 | criteria: Schema.Array(Schema.String) |
| 33 | }) |
| 34 | |
| 35 | /** |
| 36 | * A probability question. |
| 37 | * |
| 38 | * @stability unstable |
| 39 | * @category schemas |
| 40 | * @since 4.0.0 |
| 41 | */ |
| 42 | export const NoulQuestion = Schema.Struct({ |
| 43 | type: Schema.Literal("noul"), |
| 44 | instructions: Schema.String, |
| 45 | criteria: Schema.optional(Schema.Struct({ false: Schema.String, true: Schema.String })) |
| 46 | }) |
| 47 | |
| 48 | /** |
| 49 | * A Clef classification, rating, or probability question. |
| 50 | * |
| 51 | * @stability unstable |
| 52 | * @category schemas |
| 53 | * @since 4.0.0 |
| 54 | */ |
| 55 | export const Question = Schema.Union([ChoiceQuestion, ScoreQuestion, NoulQuestion]) |
| 56 | |
| 57 | /** |
| 58 | * A batch of questions about text or JSON state. |
| 59 | * |
| 60 | * @stability unstable |
| 61 | * @category schemas |
| 62 | * @since 4.0.0 |
| 63 | */ |
| 64 | export const DecisionsRequest = Schema.Struct({ |
| 65 | model: Schema.Union([Schema.Literals(["clef", "clef-flash"]), Schema.StringForLiteralAutocomplete]), |
| 66 | state: Schema.Json, |
| 67 | questions: Schema.Record(Schema.String, Question) |
| 68 | }) |
| 69 | |
| 70 | /** |
| 71 | * A classification distribution. |
| 72 | * |
| 73 | * @stability unstable |
| 74 | * @category schemas |
| 75 | * @since 4.0.0 |
| 76 | */ |
| 77 | export const ChoiceAnswer = Schema.Struct({ |
| 78 | type: Schema.Literal("choice"), |
| 79 | choice: Schema.String, |
| 80 | probabilities: Schema.Record(Schema.String, Schema.Number), |
| 81 | confidence: Schema.Number |
| 82 | }) |
| 83 | |
| 84 | /** |
| 85 | * A zero-based rating and index-keyed distribution. |
| 86 | * |
| 87 | * @stability unstable |
| 88 | * @category schemas |
| 89 | * @since 4.0.0 |
| 90 | */ |
| 91 | export const ScoreAnswer = Schema.Struct({ |
| 92 | type: Schema.Literal("score"), |
| 93 | score: Schema.Number, |
| 94 | probabilities: Schema.Record(Schema.String, Schema.Number), |
| 95 | confidence: Schema.Number, |
| 96 | legend: Schema.Record(Schema.String, Schema.String) |
| 97 | }) |
| 98 | |
| 99 | /** |
| 100 | * A Bernoulli probability. |
| 101 | * |
| 102 | * @stability unstable |
| 103 | * @category schemas |
| 104 | * @since 4.0.0 |
| 105 | */ |
| 106 | export const NoulAnswer = Schema.Struct({ type: Schema.Literal("noul"), noul: Schema.Number }) |
| 107 | |
| 108 | /** |
| 109 | * A Clef classification, rating, or probability answer. |
| 110 | * |
| 111 | * @stability unstable |
| 112 | * @category schemas |
| 113 | * @since 4.0.0 |
| 114 | */ |
| 115 | export const Answer = Schema.Union([ChoiceAnswer, ScoreAnswer, NoulAnswer]) |
| 116 | |
| 117 | /** |
| 118 | * Answers and token usage for a batch. |
| 119 | * |
| 120 | * @stability unstable |
| 121 | * @category schemas |
| 122 | * @since 4.0.0 |
| 123 | */ |
| 124 | export const DecisionsResponse = Schema.Struct({ |
| 125 | model: Schema.String, |
| 126 | answers: Schema.Record(Schema.String, Answer), |
| 127 | usage: Schema.Struct({ |
| 128 | input_tokens: Schema.Int, |
| 129 | output_tokens: Schema.Int |
| 130 | }) |
| 131 | }) |