gpt4free-ts/model/index.ts

37 行
968 B
TypeScript

import {Chat, ChatOptions} from "./base";
import {You} from "./you";
import {Mcbbs} from "./mcbbs";
import {ChatDemo} from "./chatdemo";
import {Phind} from "./phind";
export enum Site {
// define new model here
You = 'you',
Phind = 'phind',
Mcbbs = 'mcbbs',
ChatDemo = 'chatdemo',
}
export class ChatModelFactory {
private modelMap: Map<Site, Chat>;
private readonly options: ChatOptions | undefined;
constructor(options?: ChatOptions) {
this.modelMap = new Map();
this.options = options;
this.init();
}
init() {
// register new model here
this.modelMap.set(Site.You, new You(this.options))
this.modelMap.set(Site.Phind, new Phind(this.options))
this.modelMap.set(Site.Mcbbs, new Mcbbs(this.options))
this.modelMap.set(Site.ChatDemo, new ChatDemo(this.options))
}
get(model: Site): Chat | undefined {
return this.modelMap.get(model);
}
}