From 3e509f6663e181ff92bd0cc5d248f90ac24e3153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=9D=89=28Shan=20Wu=29?= Date: Wed, 22 Mar 2023 12:31:04 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BD=93=E7=94=A8gpt-4=E7=9A=84API=20?= =?UTF-8?q?=E6=97=B6=E5=A2=9E=E5=8A=A0=E5=8F=AF=E7=94=A8=E7=9A=84=20Max=20?= =?UTF-8?q?Tokens=20(#729)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 用GPT-4 API时增加max token * style: eslint fix --------- Co-authored-by: Redon <790348264@qq.com> --- service/src/chatgpt/index.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/service/src/chatgpt/index.ts b/service/src/chatgpt/index.ts index 3ade78d..fc25bd2 100644 --- a/service/src/chatgpt/index.ts +++ b/service/src/chatgpt/index.ts @@ -45,6 +45,19 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI debug: true, } + // increase max token limit if use gpt-4 + if (model.toLowerCase().includes('gpt-4')) { + // if use 32k model + if (model.toLowerCase().includes('32k')) { + options.maxModelTokens = 32768 + options.maxResponseTokens = 8192 + } + else { + options.maxModelTokens = 8192 + options.maxResponseTokens = 2048 + } + } + if (isNotEmptyString(OPENAI_API_BASE_URL)) options.apiBaseUrl = `${OPENAI_API_BASE_URL}/v1`