diff --git a/service/src/chatgpt/index.ts b/service/src/chatgpt/index.ts index 1986540..6efa6e6 100644 --- a/service/src/chatgpt/index.ts +++ b/service/src/chatgpt/index.ts @@ -27,6 +27,7 @@ const timeoutMs: number = !isNaN(+process.env.TIMEOUT_MS) ? +process.env.TIMEOUT const disableDebug: boolean = process.env.OPENAI_API_DISABLE_DEBUG === 'true' let apiModel: ApiModel +let model = 'gpt-3.5-turbo' if (!isNotEmptyString(process.env.OPENAI_API_KEY) && !isNotEmptyString(process.env.OPENAI_ACCESS_TOKEN)) throw new Error('Missing OPENAI_API_KEY or OPENAI_ACCESS_TOKEN environment variable') @@ -39,7 +40,7 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI if (isNotEmptyString(process.env.OPENAI_API_KEY)) { const OPENAI_API_BASE_URL = process.env.OPENAI_API_BASE_URL const OPENAI_API_MODEL = process.env.OPENAI_API_MODEL - const model = isNotEmptyString(OPENAI_API_MODEL) ? OPENAI_API_MODEL : 'gpt-3.5-turbo' + model = isNotEmptyString(OPENAI_API_MODEL) ? OPENAI_API_MODEL : 'gpt-3.5-turbo' const options: ChatGPTAPIOptions = { apiKey: process.env.OPENAI_API_KEY, @@ -90,13 +91,14 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI })() async function chatReplyProcess(options: RequestOptions) { - const { message, lastContext, process, systemMessage } = options + const { message, lastContext, process, systemMessage, temperature, top_p } = options try { let options: SendMessageOptions = { timeoutMs } if (apiModel === 'ChatGPTAPI') { if (isNotEmptyString(systemMessage)) options.systemMessage = systemMessage + options.completionParams = { model, temperature, top_p } } if (lastContext != null) { diff --git a/service/src/chatgpt/types.ts b/service/src/chatgpt/types.ts index 420f465..4931abf 100644 --- a/service/src/chatgpt/types.ts +++ b/service/src/chatgpt/types.ts @@ -5,6 +5,8 @@ export interface RequestOptions { lastContext?: { conversationId?: string; parentMessageId?: string } process?: (chat: ChatMessage) => void systemMessage?: string + temperature?: number + top_p?: number } export interface BalanceResponse { diff --git a/service/src/index.ts b/service/src/index.ts index 28041d1..7068446 100644 --- a/service/src/index.ts +++ b/service/src/index.ts @@ -23,7 +23,7 @@ router.post('/chat-process', [auth, limiter], async (req, res) => { res.setHeader('Content-type', 'application/octet-stream') try { - const { prompt, options = {}, systemMessage } = req.body as RequestProps + const { prompt, options = {}, systemMessage, temperature, top_p } = req.body as RequestProps let firstChunk = true await chatReplyProcess({ message: prompt, @@ -33,6 +33,8 @@ router.post('/chat-process', [auth, limiter], async (req, res) => { firstChunk = false }, systemMessage, + temperature, + top_p, }) } catch (error) { diff --git a/service/src/types.ts b/service/src/types.ts index fdbf68c..99f9dd9 100644 --- a/service/src/types.ts +++ b/service/src/types.ts @@ -4,6 +4,8 @@ export interface RequestProps { prompt: string options?: ChatContext systemMessage: string + temperature?: number + top_p?: number } export interface ChatContext { diff --git a/src/api/index.ts b/src/api/index.ts index 9f61fc5..0ca33fd 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,6 +1,6 @@ import type { AxiosProgressEvent, GenericAbortSignal } from 'axios' import { post } from '@/utils/request' -import { useSettingStore } from '@/store' +import { useAuthStore, useSettingStore } from '@/store' export function fetchChatAPI( prompt: string, @@ -28,10 +28,25 @@ export function fetchChatAPIProcess( onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void }, ) { const settingStore = useSettingStore() + const authStore = useAuthStore() + + let data: Record = { + prompt: params.prompt, + options: params.options, + } + + if (authStore.isChatGPTAPI) { + data = { + ...data, + systemMessage: settingStore.systemMessage, + temperature: settingStore.temperature, + top_p: settingStore.top_p, + } + } return post({ url: '/chat-process', - data: { prompt: params.prompt, options: params.options, systemMessage: settingStore.systemMessage }, + data, signal: params.signal, onDownloadProgress: params.onDownloadProgress, }) diff --git a/src/components/common/Setting/Advanced.vue b/src/components/common/Setting/Advanced.vue index 9f255ff..0744677 100644 --- a/src/components/common/Setting/Advanced.vue +++ b/src/components/common/Setting/Advanced.vue @@ -1,6 +1,6 @@