Many-in-one AI client.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738
  1. import * as OpenAi from './platforms/openai';
  2. import * as ElevenLabs from './platforms/elevenlabs';
  3. const SUPPORTED_PLATFORMS = [
  4. OpenAi,
  5. ElevenLabs,
  6. ] as const;
  7. export * as OpenAi from './platforms/openai';
  8. export * as ElevenLabs from './platforms/elevenlabs';
  9. export type PlatformConfig = (
  10. OpenAi.PlatformConfig
  11. | ElevenLabs.PlatformConfig
  12. );
  13. export type PlatformEventEmitter = (
  14. OpenAi.PlatformEventEmitter
  15. | ElevenLabs.PlatformEventEmitter
  16. );
  17. export const createAiClient = <T extends PlatformEventEmitter = PlatformEventEmitter>(
  18. configParams: PlatformConfig,
  19. ): T => {
  20. const {
  21. platform,
  22. platformConfiguration,
  23. } = configParams;
  24. const platformModule = SUPPORTED_PLATFORMS.find((p) => p.PLATFORM_ID === platform);
  25. if (!platformModule) {
  26. const supportedPlatforms = SUPPORTED_PLATFORMS.map((p) => p.PLATFORM_ID).join(', ');
  27. throw new Error(`Unsupported platform: ${platform}. Supported platforms are: ${supportedPlatforms}`);
  28. }
  29. return new platformModule.PlatformEventEmitterImpl(platformConfiguration) as T;
  30. };