core.ts 652 B

12345678910111213141516171819202122232425262728
  1. import { MaskConfig, ProviderConfig } from "../store";
  2. import { shareToShareGPT } from "./common/share";
  3. import { createOpenAiClient } from "./openai";
  4. import { ChatControllerPool } from "./common/controller";
  5. export const LLMClients = {
  6. openai: createOpenAiClient,
  7. };
  8. export function createLLMClient(
  9. config: ProviderConfig,
  10. maskConfig: MaskConfig,
  11. ) {
  12. return LLMClients[maskConfig.provider as any as keyof typeof LLMClients](
  13. config,
  14. maskConfig.modelConfig,
  15. );
  16. }
  17. export function createApi() {
  18. return {
  19. createLLMClient,
  20. shareToShareGPT,
  21. controllerManager: ChatControllerPool,
  22. };
  23. }
  24. export const api = createApi();