provider.types.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { Provider } from "../src/provider"
  2. import { ProviderID, type ModelRef } from "../src/schema"
  3. declare const model: (id: string) => ModelRef
  4. declare const requiredModel: (id: string, options: { readonly baseURL: string }) => ModelRef
  5. declare const chat: (id: string, options: { readonly apiKey: string }) => ModelRef
  6. Provider.make({
  7. id: ProviderID.make("example"),
  8. model,
  9. })
  10. Provider.make({
  11. id: ProviderID.make("bad"),
  12. model,
  13. // @ts-expect-error provider definitions should not grow accidental top-level fields.
  14. routes: [],
  15. })
  16. const requiredProvider = Provider.make({
  17. id: ProviderID.make("required"),
  18. model: requiredModel,
  19. })
  20. requiredProvider.model("custom", { baseURL: "https://example.com/v1" })
  21. // @ts-expect-error Provider.make preserves required model options.
  22. requiredProvider.model("custom")
  23. const multiApiProvider = Provider.make({
  24. id: ProviderID.make("multi-api"),
  25. model,
  26. apis: { chat },
  27. })
  28. multiApiProvider.apis.chat("chat-model", { apiKey: "key" })
  29. // @ts-expect-error Provider.make preserves API-specific option types.
  30. multiApiProvider.apis.chat("chat-model")