model.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. export * as Model from "./model"
  2. import { Schema } from "effect"
  3. import { Provider } from "./provider"
  4. import { withStatics } from "./schema"
  5. export const ID = Schema.String.pipe(Schema.brand("ModelV2.ID"))
  6. export type ID = typeof ID.Type
  7. export const VariantID = Schema.String.pipe(Schema.brand("VariantID"))
  8. export type VariantID = typeof VariantID.Type
  9. export const Ref = Schema.Struct({
  10. id: ID,
  11. providerID: Provider.ID,
  12. variant: VariantID.pipe(Schema.optional),
  13. })
  14. export type Ref = typeof Ref.Type
  15. export const Family = Schema.String.pipe(Schema.brand("Family"))
  16. export type Family = typeof Family.Type
  17. export interface Capabilities extends Schema.Schema.Type<typeof Capabilities> {}
  18. export const Capabilities = Schema.Struct({
  19. tools: Schema.Boolean,
  20. input: Schema.String.pipe(Schema.Array, Schema.mutable),
  21. output: Schema.String.pipe(Schema.Array, Schema.mutable),
  22. })
  23. export interface Cost extends Schema.Schema.Type<typeof Cost> {}
  24. export const Cost = Schema.Struct({
  25. tier: Schema.Struct({
  26. type: Schema.Literal("context"),
  27. size: Schema.Int,
  28. }).pipe(Schema.optional),
  29. input: Schema.Finite,
  30. output: Schema.Finite,
  31. cache: Schema.Struct({
  32. read: Schema.Finite,
  33. write: Schema.Finite,
  34. }),
  35. })
  36. export const Api = Schema.Union([
  37. Schema.Struct({
  38. id: ID,
  39. ...Provider.AISDK.fields,
  40. }),
  41. Schema.Struct({
  42. id: ID,
  43. ...Provider.Native.fields,
  44. }),
  45. ]).pipe(Schema.toTaggedUnion("type"))
  46. export type Api = typeof Api.Type
  47. export interface Info extends Schema.Schema.Type<typeof Info> {}
  48. export const Info = Schema.Struct({
  49. id: ID,
  50. providerID: Provider.ID,
  51. family: Family.pipe(Schema.optional),
  52. name: Schema.String,
  53. api: Api,
  54. capabilities: Capabilities,
  55. request: Schema.Struct({
  56. ...Provider.Request.fields,
  57. variant: Schema.String.pipe(Schema.optional),
  58. }),
  59. variants: Schema.Struct({
  60. id: VariantID,
  61. ...Provider.Request.fields,
  62. }).pipe(Schema.Array, Schema.mutable),
  63. time: Schema.Struct({
  64. released: Schema.Finite,
  65. }),
  66. cost: Cost.pipe(Schema.Array, Schema.mutable),
  67. status: Schema.Literals(["alpha", "beta", "deprecated", "active"]),
  68. enabled: Schema.Boolean,
  69. limit: Schema.Struct({
  70. context: Schema.Int,
  71. input: Schema.Int.pipe(Schema.optional),
  72. output: Schema.Int,
  73. }),
  74. })
  75. .annotate({ identifier: "ModelV2.Info" })
  76. .pipe(
  77. withStatics((schema) => ({
  78. empty: (providerID: Provider.ID, modelID: ID) =>
  79. schema.make({
  80. id: modelID,
  81. providerID,
  82. name: modelID,
  83. api: { id: modelID, type: "native", settings: {} },
  84. capabilities: { tools: false, input: [], output: [] },
  85. request: { headers: {}, body: {} },
  86. variants: [],
  87. time: { released: 0 },
  88. cost: [],
  89. status: "active",
  90. enabled: true,
  91. limit: { context: 0, output: 0 },
  92. }),
  93. })),
  94. )