model.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { DateTime, Schema } from "effect"
  2. import { DateTimeUtcFromMillis } from "effect/Schema"
  3. import { ProviderV2 } from "./provider"
  4. export const ID = Schema.String.pipe(Schema.brand("ModelV2.ID"))
  5. export type ID = typeof ID.Type
  6. export const VariantID = Schema.String.pipe(Schema.brand("VariantID"))
  7. export type VariantID = typeof VariantID.Type
  8. // Grouping of models, eg claude opus, claude sonnet
  9. export const Family = Schema.String.pipe(Schema.brand("Family"))
  10. export type Family = typeof Family.Type
  11. export const Capabilities = Schema.Struct({
  12. tools: Schema.Boolean,
  13. // mime patterns, image, audio, video/*, text/*
  14. input: Schema.String.pipe(Schema.Array),
  15. output: Schema.String.pipe(Schema.Array),
  16. })
  17. export type Capabilities = typeof Capabilities.Type
  18. export const Cost = Schema.Struct({
  19. tier: Schema.Struct({
  20. type: Schema.Literal("context"),
  21. size: Schema.Int,
  22. }).pipe(Schema.optional),
  23. input: Schema.Finite,
  24. output: Schema.Finite,
  25. cache: Schema.Struct({
  26. read: Schema.Finite,
  27. write: Schema.Finite,
  28. }),
  29. })
  30. export const Ref = Schema.Struct({
  31. id: ID,
  32. providerID: ProviderV2.ID,
  33. variant: VariantID,
  34. })
  35. export type Ref = typeof Ref.Type
  36. export class Info extends Schema.Class<Info>("ModelV2.Info")({
  37. id: ID,
  38. apiID: ID,
  39. providerID: ProviderV2.ID,
  40. family: Family.pipe(Schema.optional),
  41. name: Schema.String,
  42. endpoint: ProviderV2.Endpoint,
  43. capabilities: Capabilities,
  44. options: Schema.Struct({
  45. ...ProviderV2.Options.fields,
  46. variant: Schema.String.pipe(Schema.optional),
  47. }),
  48. variants: Schema.Struct({
  49. id: VariantID,
  50. ...ProviderV2.Options.fields,
  51. }).pipe(Schema.Array),
  52. time: Schema.Struct({
  53. released: DateTimeUtcFromMillis,
  54. }),
  55. cost: Cost.pipe(Schema.Array),
  56. status: Schema.Literals(["alpha", "beta", "deprecated", "active"]),
  57. enabled: Schema.Boolean,
  58. limit: Schema.Struct({
  59. context: Schema.Int,
  60. input: Schema.Int.pipe(Schema.optional),
  61. output: Schema.Int,
  62. }),
  63. }) {
  64. static empty(providerID: ProviderV2.ID, modelID: ID) {
  65. return new Info({
  66. id: modelID,
  67. apiID: modelID,
  68. providerID,
  69. name: modelID,
  70. endpoint: {
  71. type: "unknown",
  72. },
  73. capabilities: {
  74. tools: false,
  75. input: [],
  76. output: [],
  77. },
  78. options: {
  79. headers: {},
  80. body: {},
  81. aisdk: {
  82. provider: {},
  83. request: {},
  84. },
  85. },
  86. variants: [],
  87. time: {
  88. released: DateTime.makeUnsafe(0),
  89. },
  90. cost: [],
  91. status: "active",
  92. enabled: true,
  93. limit: {
  94. context: 0,
  95. output: 0,
  96. },
  97. })
  98. }
  99. }
  100. export function parse(input: string): { providerID: ProviderV2.ID; modelID: ID } {
  101. const [providerID, ...modelID] = input.split("/")
  102. return {
  103. providerID: ProviderV2.ID.make(providerID),
  104. modelID: ID.make(modelID.join("/")),
  105. }
  106. }
  107. export * as ModelV2 from "./model"