@@ -11,7 +11,7 @@ import { textAuditServices } from '../utils/textAudit'
1111import { getCacheConfig , getOriginConfig } from '../storage/config'
1212import { sendResponse } from '../utils'
1313import { isNotEmptyString } from '../utils/is'
14- import type { ApiModel , ChatContext , ChatGPTUnofficialProxyAPIOptions , ModelConfig } from '../types'
14+ import type { ChatContext , ChatGPTUnofficialProxyAPIOptions , ModelConfig } from '../types'
1515import type { RequestOptions } from './types'
1616
1717const { HttpsProxyAgent } = httpsProxyAgent
@@ -27,7 +27,6 @@ const ErrorCodeMessage: Record<string, string> = {
2727 500 : '[OpenAI] 服务器繁忙,请稍后再试 | Internal Server Error' ,
2828}
2929
30- let apiModel : ApiModel
3130let api : ChatGPTAPI | ChatGPTUnofficialProxyAPI
3231let auditService : TextAuditService
3332
@@ -38,10 +37,9 @@ export async function initApi() {
3837 if ( ! config . apiKey && ! config . accessToken )
3938 throw new Error ( 'Missing OPENAI_API_KEY or OPENAI_ACCESS_TOKEN environment variable' )
4039
41- if ( isNotEmptyString ( config . apiKey ) ) {
40+ if ( config . apiModel === 'ChatGPTAPI' ) {
4241 const OPENAI_API_BASE_URL = config . apiBaseUrl
43- const OPENAI_API_MODEL = config . apiModel
44- const model = isNotEmptyString ( OPENAI_API_MODEL ) ? OPENAI_API_MODEL : 'gpt-3.5-turbo'
42+ const model = config . chatModel
4543
4644 const options : ChatGPTAPIOptions = {
4745 apiKey : config . apiKey ,
@@ -67,10 +65,9 @@ export async function initApi() {
6765 await setupProxy ( options )
6866
6967 api = new ChatGPTAPI ( { ...options } )
70- apiModel = 'ChatGPTAPI'
7168 }
7269 else {
73- const model = isNotEmptyString ( config . apiModel ) ? config . apiModel : 'gpt-3.5-turbo'
70+ const model = config . chatModel
7471 const options : ChatGPTUnofficialProxyAPIOptions = {
7572 accessToken : config . accessToken ,
7673 apiReverseProxyUrl : isNotEmptyString ( config . reverseProxy ) ? config . reverseProxy : 'https://ai.fakeopen.com/api/conversation' ,
@@ -81,27 +78,26 @@ export async function initApi() {
8178 await setupProxy ( options )
8279
8380 api = new ChatGPTUnofficialProxyAPI ( { ...options } )
84- apiModel = 'ChatGPTUnofficialProxyAPI'
8581 }
8682}
8783
8884async function chatReplyProcess ( options : RequestOptions ) {
8985 const config = await getCacheConfig ( )
90- const model = isNotEmptyString ( config . apiModel ) ? config . apiModel : 'gpt-3.5-turbo'
86+ const model = config . chatModel
9187 const { message, lastContext, process, systemMessage, temperature, top_p } = options
9288
9389 try {
9490 const timeoutMs = ( await getCacheConfig ( ) ) . timeoutMs
9591 let options : SendMessageOptions = { timeoutMs }
9692
97- if ( apiModel === 'ChatGPTAPI' ) {
93+ if ( config . apiModel === 'ChatGPTAPI' ) {
9894 if ( isNotEmptyString ( systemMessage ) )
9995 options . systemMessage = systemMessage
10096 options . completionParams = { model, temperature, top_p }
10197 }
10298
10399 if ( lastContext != null ) {
104- if ( apiModel === 'ChatGPTAPI' )
100+ if ( config . apiModel === 'ChatGPTAPI' )
105101 options . parentMessageId = lastContext . parentMessageId
106102 else
107103 options = { ...lastContext }
@@ -265,12 +261,8 @@ async function setupProxy(options: ChatGPTAPIOptions | ChatGPTUnofficialProxyAPI
265261 }
266262}
267263
268- function currentModel ( ) : ApiModel {
269- return apiModel
270- }
271-
272264initApi ( )
273265
274266export type { ChatContext , ChatMessage }
275267
276- export { chatReplyProcess , chatConfig , currentModel , containsSensitiveWords }
268+ export { chatReplyProcess , chatConfig , containsSensitiveWords }
0 commit comments