provider.types.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Provider } from "../src/provider"
  2. import { ProviderID, type LanguageModel } from "../src/schema"
  3. declare const model: (id: string) => LanguageModel
  4. declare const requiredModel: (id: string, options: { readonly baseURL: string }) => LanguageModel
  5. declare const chat: (id: string, options: { readonly apiKey: string }) => LanguageModel
  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. // Provider.make is advanced structural typing coverage; built-in providers use
  21. // configure(...).model(id) facades instead of second-argument selectors.
  22. requiredProvider.model("custom", { baseURL: "https://example.com/v1" })
  23. // @ts-expect-error Provider.make preserves required model options.
  24. requiredProvider.model("custom")
  25. const multiApiProvider = Provider.make({
  26. id: ProviderID.make("multi-api"),
  27. model,
  28. apis: { chat },
  29. })
  30. multiApiProvider.apis.chat("chat-model", { apiKey: "key" })
  31. // @ts-expect-error Provider.make preserves API-specific option types.
  32. multiApiProvider.apis.chat("chat-model")