UNPKG

doomiaichat

Version:

Doomisoft OpenAI

30 lines (29 loc) 1.3 kB
// import { Configuration, OpenAIApi, ChatCompletionRequestMessage } from "azure-openai" import { OpenAIApiParameters } from "./declare"; import GptBase from "./gptbase" export default abstract class OpenAIBase<T> extends GptBase { protected readonly apiKey: string; protected readonly chatModel: string; protected readonly maxtoken: number; protected readonly top_p: number; protected readonly presence_penalty: number; protected readonly frequency_penalty: number; protected readonly temperature: number; protected readonly embeddingmodel: string; protected aiApi: T | undefined;//OpenAIApi | undefined; constructor(apiKey: string, apiOption: OpenAIApiParameters = {}) { super(); this.apiKey = apiKey; this.chatModel = apiOption.model || 'gpt-3.5-turbo'; this.maxtoken = apiOption.maxtoken || 2048; this.top_p = apiOption.top_p || 0.95; this.temperature = apiOption.temperature || 0.9; this.presence_penalty = apiOption.presence_penalty || 0; this.frequency_penalty = apiOption.frequency_penalty || 0; this.embeddingmodel = apiOption.embedding || 'text-embedding-ada-002'; } /** * 初始化OpenAI 的聊天对象Api */ abstract createOpenAI(apiKey: string): T ; }