core.ts 741 B

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