forked from xiangsx/gpt4free-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
77 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {Stream} from "stream"; | ||
|
||
export interface ChatOptions { | ||
proxy?: string; | ||
} | ||
|
||
export interface Response { | ||
text: string | null; | ||
other: any; | ||
} | ||
|
||
export interface ResponseStream { | ||
text: Stream; | ||
other: any; | ||
} | ||
|
||
export interface Request { | ||
prompt: string; | ||
history?: HistoryItem[]; | ||
options?: any; | ||
} | ||
|
||
export interface HistoryItem { | ||
question?: string; | ||
answer?: string; | ||
} | ||
|
||
|
||
export abstract class Chat { | ||
protected proxy: string | undefined; | ||
|
||
constructor(options?: ChatOptions) { | ||
this.proxy = options?.proxy; | ||
} | ||
|
||
public abstract ask(req: Request): Promise<Response> | ||
|
||
public abstract askStream(req: Request): Promise<ResponseStream> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,27 @@ | ||
import {Stream} from "stream"; | ||
import {Chat, ChatOptions} from "./base"; | ||
import {You} from "./you"; | ||
|
||
export interface ChatOptions { | ||
proxy?: string; | ||
export enum Model { | ||
// define new model here | ||
You = 'you', | ||
} | ||
|
||
export interface Response { | ||
text: string | null; | ||
other: any; | ||
} | ||
|
||
export interface ResponseStream { | ||
text: Stream; | ||
other: any; | ||
} | ||
|
||
export interface Request { | ||
prompt: string; | ||
history?: HistoryItem[]; | ||
options?: any; | ||
} | ||
|
||
export interface HistoryItem { | ||
question?: string; | ||
answer?: string; | ||
} | ||
|
||
|
||
export abstract class Chat { | ||
protected proxy: string | undefined; | ||
export class ChatModelFactory { | ||
private modelMap: Map<Model, Chat>; | ||
private readonly options: ChatOptions | undefined; | ||
|
||
constructor(options?: ChatOptions) { | ||
this.proxy = options?.proxy; | ||
this.modelMap = new Map(); | ||
this.options = options; | ||
this.init(); | ||
} | ||
|
||
public abstract ask(req: Request): Promise<Response> | ||
init() { | ||
// register new model here | ||
this.modelMap.set(Model.You, new You(this.options)) | ||
} | ||
|
||
public abstract askStream(req: Request): Promise<ResponseStream> | ||
get(model: Model): Chat | undefined { | ||
return this.modelMap.get(model); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters